Code Duplication    Length = 27-28 lines in 2 locations

src/Models/MetadataTrait.php 2 locations

@@ 431-458 (lines=28) @@
428
429
        $fkMethodName = null;
430
        $rkMethodName = null;
431
        if ($condition) {
432
            if (array_key_exists(get_class($foo), static::$methodPrimary)) {
433
                $line = static::$methodPrimary[get_class($foo)];
434
                $fkMethodName = $line['fk'];
435
                $rkMethodName = $line['rk'];
436
            } else {
437
                $methodList = get_class_methods(get_class($foo));
438
                $fkMethodName = 'getQualifiedForeignPivotKeyName';
439
                foreach ($fkList as $option) {
440
                    if (in_array($option, $methodList)) {
441
                        $fkMethodName = $option;
442
                        break;
443
                    }
444
                }
445
                assert(in_array($fkMethodName, $methodList), "Selected method, ".$fkMethodName.", not in method list");
446
                $rkMethodName = 'getQualifiedRelatedPivotKeyName';
447
                foreach ($rkList as $option) {
448
                    if (in_array($option, $methodList)) {
449
                        $rkMethodName = $option;
450
                        break;
451
                    }
452
                }
453
                assert(in_array($rkMethodName, $methodList), "Selected method, ".$rkMethodName.", not in method list");
454
                $line = ['fk' => $fkMethodName, 'rk' => $rkMethodName];
455
                static::$methodPrimary[get_class($foo)] = $line;
456
            }
457
        }
458
        return array($fkMethodName, $rkMethodName);
459
    }
460
461
    private function polyglotKeyMethodBackupNames($foo, $condition = false)
@@ 468-494 (lines=27) @@
465
466
        $fkMethodName = null;
467
        $rkMethodName = null;
468
        if ($condition) {
469
            if (array_key_exists(get_class($foo), static::$methodAlternate)) {
470
                $line = static::$methodAlternate[get_class($foo)];
471
                $fkMethodName = $line['fk'];
472
                $rkMethodName = $line['rk'];
473
            } else {
474
                $methodList = get_class_methods(get_class($foo));
475
                $fkMethodName = 'getForeignKeyName';
476
                foreach ($fkList as $option) {
477
                    if (in_array($option, $methodList)) {
478
                        $fkMethodName = $option;
479
                        break;
480
                    }
481
                }
482
                assert(in_array($fkMethodName, $methodList), "Selected method, ".$fkMethodName.", not in method list");
483
                $rkMethodName = 'getQualifiedParentKeyName';
484
                foreach ($rkList as $option) {
485
                    if (in_array($option, $methodList)) {
486
                        $rkMethodName = $option;
487
                        break;
488
                    }
489
                }
490
                assert(in_array($rkMethodName, $methodList), "Selected method, ".$rkMethodName.", not in method list");
491
                $line = ['fk' => $fkMethodName, 'rk' => $rkMethodName];
492
                static::$methodAlternate[get_class($foo)] = $line;
493
            }
494
        }
495
        return array($fkMethodName, $rkMethodName);
496
    }
497