Code Duplication    Length = 20-21 lines in 3 locations

src/Phinx/Db/Adapter/MysqlAdapter.php 1 location

@@ 599-618 (lines=20) @@
596
    /**
597
     * {@inheritdoc}
598
     */
599
    public function hasForeignKey($tableName, $columns, $constraint = null)
600
    {
601
        if (is_string($columns)) {
602
            $columns = [$columns]; // str to array
603
        }
604
        $foreignKeys = $this->getForeignKeys($tableName);
605
        if ($constraint) {
606
            if (isset($foreignKeys[$constraint])) {
607
                return !empty($foreignKeys[$constraint]);
608
            }
609
610
            return false;
611
        } else {
612
            foreach ($foreignKeys as $key) {
613
                if ($columns == $key['columns']) {
614
                    return true;
615
                }
616
            }
617
618
            return false;
619
        }
620
    }
621

src/Phinx/Db/Adapter/SqlServerAdapter.php 1 location

@@ 732-752 (lines=21) @@
729
    /**
730
     * {@inheritdoc}
731
     */
732
    public function hasForeignKey($tableName, $columns, $constraint = null)
733
    {
734
        if (is_string($columns)) {
735
            $columns = [$columns]; // str to array
736
        }
737
        $foreignKeys = $this->getForeignKeys($tableName);
738
        if ($constraint) {
739
            if (isset($foreignKeys[$constraint])) {
740
                return !empty($foreignKeys[$constraint]);
741
            }
742
743
            return false;
744
        } else {
745
            foreach ($foreignKeys as $key) {
746
                $a = array_diff($columns, $key['columns']);
747
                if (empty($a)) {
748
                    return true;
749
                }
750
            }
751
752
            return false;
753
        }
754
    }
755

src/Phinx/Db/Adapter/PostgresAdapter.php 1 location

@@ 625-645 (lines=21) @@
622
    /**
623
     * {@inheritdoc}
624
     */
625
    public function hasForeignKey($tableName, $columns, $constraint = null)
626
    {
627
        if (is_string($columns)) {
628
            $columns = [$columns]; // str to array
629
        }
630
        $foreignKeys = $this->getForeignKeys($tableName);
631
        if ($constraint) {
632
            if (isset($foreignKeys[$constraint])) {
633
                return !empty($foreignKeys[$constraint]);
634
            }
635
636
            return false;
637
        } else {
638
            foreach ($foreignKeys as $key) {
639
                $a = array_diff($columns, $key['columns']);
640
                if (empty($a)) {
641
                    return true;
642
                }
643
            }
644
645
            return false;
646
        }
647
    }
648