Code Duplication    Length = 27-28 lines in 2 locations

src/Models/MetadataTrait.php 2 locations

@@ 452-479 (lines=28) @@
449
450
        $fkMethodName = null;
451
        $rkMethodName = null;
452
        if ($condition) {
453
            if (array_key_exists(get_class($foo), static::$methodPrimary)) {
454
                $line = static::$methodPrimary[get_class($foo)];
455
                $fkMethodName = $line['fk'];
456
                $rkMethodName = $line['rk'];
457
            } else {
458
                $methodList = get_class_methods(get_class($foo));
459
                $fkMethodName = 'getQualifiedForeignPivotKeyName';
460
                foreach ($fkList as $option) {
461
                    if (in_array($option, $methodList)) {
462
                        $fkMethodName = $option;
463
                        break;
464
                    }
465
                }
466
                assert(in_array($fkMethodName, $methodList), 'Selected method, '.$fkMethodName.', not in method list');
467
                $rkMethodName = 'getQualifiedRelatedPivotKeyName';
468
                foreach ($rkList as $option) {
469
                    if (in_array($option, $methodList)) {
470
                        $rkMethodName = $option;
471
                        break;
472
                    }
473
                }
474
                assert(in_array($rkMethodName, $methodList), 'Selected method, '.$rkMethodName.', not in method list');
475
                $line = ['fk' => $fkMethodName, 'rk' => $rkMethodName];
476
                static::$methodPrimary[get_class($foo)] = $line;
477
            }
478
        }
479
        return [$fkMethodName, $rkMethodName];
480
    }
481
482
    private function polyglotKeyMethodBackupNames($foo, $condition = false)
@@ 489-515 (lines=27) @@
486
487
        $fkMethodName = null;
488
        $rkMethodName = null;
489
        if ($condition) {
490
            if (array_key_exists(get_class($foo), static::$methodAlternate)) {
491
                $line = static::$methodAlternate[get_class($foo)];
492
                $fkMethodName = $line['fk'];
493
                $rkMethodName = $line['rk'];
494
            } else {
495
                $methodList = get_class_methods(get_class($foo));
496
                $fkMethodName = 'getForeignKeyName';
497
                foreach ($fkList as $option) {
498
                    if (in_array($option, $methodList)) {
499
                        $fkMethodName = $option;
500
                        break;
501
                    }
502
                }
503
                assert(in_array($fkMethodName, $methodList), 'Selected method, '.$fkMethodName.', not in method list');
504
                $rkMethodName = 'getQualifiedParentKeyName';
505
                foreach ($rkList as $option) {
506
                    if (in_array($option, $methodList)) {
507
                        $rkMethodName = $option;
508
                        break;
509
                    }
510
                }
511
                assert(in_array($rkMethodName, $methodList), 'Selected method, '.$rkMethodName.', not in method list');
512
                $line = ['fk' => $fkMethodName, 'rk' => $rkMethodName];
513
                static::$methodAlternate[get_class($foo)] = $line;
514
            }
515
        }
516
        return [$fkMethodName, $rkMethodName];
517
    }
518