Code Duplication    Length = 20-21 lines in 3 locations

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

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

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

@@ 812-832 (lines=21) @@
809
    /**
810
     * {@inheritdoc}
811
     */
812
    public function hasForeignKey($tableName, $columns, $constraint = null)
813
    {
814
        if (is_string($columns)) {
815
            $columns = [$columns]; // str to array
816
        }
817
        $foreignKeys = $this->getForeignKeys($tableName);
818
        if ($constraint) {
819
            if (isset($foreignKeys[$constraint])) {
820
                return !empty($foreignKeys[$constraint]);
821
            }
822
823
            return false;
824
        } else {
825
            foreach ($foreignKeys as $key) {
826
                $a = array_diff($columns, $key['columns']);
827
                if (empty($a)) {
828
                    return true;
829
                }
830
            }
831
832
            return false;
833
        }
834
    }
835

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

@@ 889-909 (lines=21) @@
886
    /**
887
     * {@inheritdoc}
888
     */
889
    public function hasForeignKey($tableName, $columns, $constraint = null)
890
    {
891
        if (is_string($columns)) {
892
            $columns = [$columns]; // str to array
893
        }
894
        $foreignKeys = $this->getForeignKeys($tableName);
895
        if ($constraint) {
896
            if (isset($foreignKeys[$constraint])) {
897
                return !empty($foreignKeys[$constraint]);
898
            }
899
900
            return false;
901
        } else {
902
            foreach ($foreignKeys as $key) {
903
                $a = array_diff($columns, $key['columns']);
904
                if (empty($a)) {
905
                    return true;
906
                }
907
            }
908
909
            return false;
910
        }
911
    }
912