Code Duplication    Length = 20-21 lines in 3 locations

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

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

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

@@ 612-632 (lines=21) @@
609
    /**
610
     * {@inheritdoc}
611
     */
612
    public function hasForeignKey($tableName, $columns, $constraint = null)
613
    {
614
        if (is_string($columns)) {
615
            $columns = [$columns]; // str to array
616
        }
617
        $foreignKeys = $this->getForeignKeys($tableName);
618
        if ($constraint) {
619
            if (isset($foreignKeys[$constraint])) {
620
                return !empty($foreignKeys[$constraint]);
621
            }
622
623
            return false;
624
        } else {
625
            foreach ($foreignKeys as $key) {
626
                $a = array_diff($columns, $key['columns']);
627
                if (empty($a)) {
628
                    return true;
629
                }
630
            }
631
632
            return false;
633
        }
634
    }
635

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

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