Code Duplication    Length = 20-21 lines in 3 locations

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

@@ 877-897 (lines=21) @@
874
    /**
875
     * {@inheritdoc}
876
     */
877
    public function hasForeignKey($tableName, $columns, $constraint = null)
878
    {
879
        if (is_string($columns)) {
880
            $columns = [$columns]; // str to array
881
        }
882
        $foreignKeys = $this->getForeignKeys($tableName);
883
        if ($constraint) {
884
            if (isset($foreignKeys[$constraint])) {
885
                return !empty($foreignKeys[$constraint]);
886
            }
887
888
            return false;
889
        } else {
890
            foreach ($foreignKeys as $key) {
891
                $a = array_diff($columns, $key['columns']);
892
                if (empty($a)) {
893
                    return true;
894
                }
895
            }
896
897
            return false;
898
        }
899
    }
900

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

@@ 794-814 (lines=21) @@
791
    /**
792
     * {@inheritdoc}
793
     */
794
    public function hasForeignKey($tableName, $columns, $constraint = null)
795
    {
796
        if (is_string($columns)) {
797
            $columns = [$columns]; // str to array
798
        }
799
        $foreignKeys = $this->getForeignKeys($tableName);
800
        if ($constraint) {
801
            if (isset($foreignKeys[$constraint])) {
802
                return !empty($foreignKeys[$constraint]);
803
            }
804
805
            return false;
806
        } else {
807
            foreach ($foreignKeys as $key) {
808
                $a = array_diff($columns, $key['columns']);
809
                if (empty($a)) {
810
                    return true;
811
                }
812
            }
813
814
            return false;
815
        }
816
    }
817

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

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