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
            return false;
610
        } else {
611
            foreach ($foreignKeys as $key) {
612
                if ($columns == $key['columns']) {
613
                    return true;
614
                }
615
            }
616
            return false;
617
        }
618
    }
619
620
    /**
621
     * Get an array of foreign keys from a particular table.

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

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

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

@@ 736-756 (lines=21) @@
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
            return false;
747
        } else {
748
            foreach ($foreignKeys as $key) {
749
                $a = array_diff($columns, $key['columns']);
750
                if (empty($a)) {
751
                    return true;
752
                }
753
            }
754
            return false;
755
        }
756
    }
757
758
    /**
759
     * Get an array of foreign keys from a particular table.