Code Duplication    Length = 20-21 lines in 3 locations

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

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

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

@@ 867-887 (lines=21) @@
864
    /**
865
     * {@inheritdoc}
866
     */
867
    public function hasForeignKey($tableName, $columns, $constraint = null)
868
    {
869
        if (is_string($columns)) {
870
            $columns = [$columns]; // str to array
871
        }
872
        $foreignKeys = $this->getForeignKeys($tableName);
873
        if ($constraint) {
874
            if (isset($foreignKeys[$constraint])) {
875
                return !empty($foreignKeys[$constraint]);
876
            }
877
878
            return false;
879
        } else {
880
            foreach ($foreignKeys as $key) {
881
                $a = array_diff($columns, $key['columns']);
882
                if (empty($a)) {
883
                    return true;
884
                }
885
            }
886
887
            return false;
888
        }
889
    }
890

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

@@ 707-726 (lines=20) @@
704
    /**
705
     * {@inheritdoc}
706
     */
707
    public function hasForeignKey($tableName, $columns, $constraint = null)
708
    {
709
        if (is_string($columns)) {
710
            $columns = [$columns]; // str to array
711
        }
712
        $foreignKeys = $this->getForeignKeys($tableName);
713
        if ($constraint) {
714
            if (isset($foreignKeys[$constraint])) {
715
                return !empty($foreignKeys[$constraint]);
716
            }
717
718
            return false;
719
        } else {
720
            foreach ($foreignKeys as $key) {
721
                if ($columns == $key['columns']) {
722
                    return true;
723
                }
724
            }
725
726
            return false;
727
        }
728
    }
729