1717use Magento \Framework \Setup \Declaration \Schema \Declaration \TableElement \ElementNameResolver ;
1818use Magento \Framework \Setup \Declaration \Schema \Diff \Diff ;
1919use Magento \Framework \Setup \Declaration \Schema \Dto \Schema ;
20- use Magento \Framework \Setup \Declaration \Schema \Dto \Table ;
2120use Magento \Framework \Setup \Declaration \Schema \SchemaConfig ;
2221use Magento \Framework \Setup \JsonPersistor ;
2322
@@ -137,7 +136,9 @@ private function persistModule(Schema $schema, string $moduleName)
137136 . Diff::GENERATED_WHITELIST_FILE_NAME ;
138137
139138 //We need to load whitelist file and update it with new revision of code.
139+ // phpcs:disable Magento2.Functions.DiscouragedFunction
140140 if (file_exists ($ whiteListFileName )) {
141+ // phpcs:disable Magento2.Functions.DiscouragedFunction
141142 $ content = json_decode (file_get_contents ($ whiteListFileName ), true );
142143 }
143144
@@ -193,19 +194,16 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
193194 $ elementType = 'index ' ;
194195 if (!empty ($ tableData [$ elementType ])) {
195196 foreach ($ tableData [$ elementType ] as $ tableElementData ) {
196- if (!isset ($ tableElementData ['column ' ])) {
197- continue ;
198- }
199197 $ indexName = $ this ->elementNameResolver ->getFullIndexName (
200198 $ table ,
201- $ tableElementData ['column ' ],
199+ $ tableElementData ['column ' ] ?? [] ,
202200 $ tableElementData ['indexType ' ] ?? null
203201 );
204202 $ declaredStructure [$ elementType ][$ indexName ] = true ;
205203 }
206204 }
207205
208- $ constraintName = $ this ->getConstraintName ($ schema , $ table , $ tableData );
206+ $ constraintName = $ this ->getConstraintName ($ schema , $ tableName , $ tableData );
209207 if ($ constraintName ) {
210208 $ declaredStructure += $ constraintName ;
211209 }
@@ -214,22 +212,22 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
214212 }
215213
216214 /**
215+ * Provide autogenerated names of the table constraint.
216+ *
217217 * @param Schema $schema
218- * @param Table $table
218+ * @param string $tableName
219219 * @param array $tableData
220220 * @return array
221221 */
222- private function getConstraintName (Schema $ schema , Table $ table , array $ tableData ): array
222+ private function getConstraintName (Schema $ schema , string $ tableName , array $ tableData ): array
223223 {
224224 $ declaredStructure = [];
225+ $ table = $ schema ->getTableByName ($ tableName );
225226
226227 $ elementType = 'constraint ' ;
227228 if (!empty ($ tableData [$ elementType ])) {
228229 foreach ($ tableData [$ elementType ] as $ tableElementData ) {
229- if (!isset ($ tableElementData ['referenceTable ' ])) {
230- continue ;
231- }
232- if ($ tableElementData ['type ' ] === 'foreign ' ) {
230+ if ($ tableElementData ['type ' ] === 'foreign ' && isset ($ tableElementData ['referenceTable ' ])) {
233231 $ referenceTable = $ schema ->getTableByName ($ tableElementData ['referenceTable ' ]);
234232 $ column = $ table ->getColumnByName ($ tableElementData ['column ' ]);
235233 $ referenceColumn = $ referenceTable ->getColumnByName ($ tableElementData ['referenceColumn ' ]);
@@ -241,12 +239,9 @@ private function getConstraintName(Schema $schema, Table $table, array $tableDat
241239 $ referenceColumn
242240 ) : null ;
243241 } else {
244- if (!isset ($ tableElementData ['column ' ])) {
245- continue ;
246- }
247242 $ constraintName = $ this ->elementNameResolver ->getFullIndexName (
248243 $ table ,
249- $ tableElementData ['column ' ],
244+ $ tableElementData ['column ' ] ?? [] ,
250245 $ tableElementData ['type ' ]
251246 );
252247 }
0 commit comments