@@ -185,6 +185,7 @@ private function getElementsWithFixedName(array $tableData): array
185185 * @param array $tableData
186186 * @return array
187187 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
188+ * @SuppressWarnings(PHPMD.NPathComplexity)
188189 */
189190 private function getElementsWithAutogeneratedName (Schema $ schema , string $ tableName , array $ tableData ) : array
190191 {
@@ -194,7 +195,7 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
194195 $ elementType = 'index ' ;
195196 if (!empty ($ tableData [$ elementType ])) {
196197 foreach ($ tableData [$ elementType ] as $ tableElementData ) {
197- if ($ table -> getIndexByName ($ tableElementData ['referenceId ' ])) {
198+ if (isset ($ tableElementData ['column ' ])) {
198199 $ indexName = $ this ->elementNameResolver ->getFullIndexName (
199200 $ table ,
200201 $ tableElementData ['column ' ],
@@ -209,24 +210,32 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
209210 if (!empty ($ tableData [$ elementType ])) {
210211 foreach ($ tableData [$ elementType ] as $ tableElementData ) {
211212 $ constraintName = null ;
212- if ($ tableElementData ['type ' ] === 'foreign ' && $ table ->getConstraintByName ($ tableElementData ['referenceId ' ])) {
213- $ referenceTable = $ schema ->getTableByName ($ tableElementData ['referenceTable ' ]);
214- $ column = $ table ->getColumnByName ($ tableElementData ['column ' ]);
215- $ referenceColumn = $ referenceTable ->getColumnByName ($ tableElementData ['referenceColumn ' ]);
216- $ constraintName = ($ column !== false && $ referenceColumn !== false ) ?
217- $ this ->elementNameResolver ->getFullFKName (
218- $ table ,
219- $ column ,
220- $ referenceTable ,
221- $ referenceColumn
222- ) : null ;
223- } else {
224- if ($ table ->getIndexByName ($ tableElementData ['referenceId ' ])) {
225- $ constraintName = $ this ->elementNameResolver ->getFullIndexName (
226- $ table ,
227- $ tableElementData ['column ' ],
228- $ tableElementData ['type ' ]
229- );
213+ if (isset ($ tableElementData ['type ' ], $ tableElementData ['column ' ])) {
214+ if ($ tableElementData ['type ' ] === 'foreign ' ) {
215+ if (isset (
216+ $ tableElementData ['column ' ],
217+ $ tableElementData ['referenceTable ' ],
218+ $ tableElementData ['referenceColumn ' ]
219+ )) {
220+ $ referenceTable = $ schema ->getTableByName ($ tableElementData ['referenceTable ' ]);
221+ $ column = $ table ->getColumnByName ($ tableElementData ['column ' ]);
222+ $ referenceColumn = $ referenceTable ->getColumnByName ($ tableElementData ['referenceColumn ' ]);
223+ $ constraintName = ($ column !== false && $ referenceColumn !== false ) ?
224+ $ this ->elementNameResolver ->getFullFKName (
225+ $ table ,
226+ $ column ,
227+ $ referenceTable ,
228+ $ referenceColumn
229+ ) : null ;
230+ }
231+ } else {
232+ if (isset ($ tableElementData ['column ' ])) {
233+ $ constraintName = $ this ->elementNameResolver ->getFullIndexName (
234+ $ table ,
235+ $ tableElementData ['column ' ],
236+ $ tableElementData ['type ' ]
237+ );
238+ }
230239 }
231240 }
232241 if ($ constraintName ) {
0 commit comments