@@ -185,6 +185,7 @@ private function getElementsWithFixedName(array $tableData): array
185
185
* @param array $tableData
186
186
* @return array
187
187
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
188
+ * @SuppressWarnings(PHPMD.NPathComplexity)
188
189
*/
189
190
private function getElementsWithAutogeneratedName (Schema $ schema , string $ tableName , array $ tableData ) : array
190
191
{
@@ -194,7 +195,7 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
194
195
$ elementType = 'index ' ;
195
196
if (!empty ($ tableData [$ elementType ])) {
196
197
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
197
- if ($ table -> getIndexByName ($ tableElementData ['referenceId ' ])) {
198
+ if (isset ($ tableElementData ['column ' ])) {
198
199
$ indexName = $ this ->elementNameResolver ->getFullIndexName (
199
200
$ table ,
200
201
$ tableElementData ['column ' ],
@@ -209,24 +210,32 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
209
210
if (!empty ($ tableData [$ elementType ])) {
210
211
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
211
212
$ 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
+ }
230
239
}
231
240
}
232
241
if ($ constraintName ) {
0 commit comments