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/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.

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

@@ 628-648 (lines=21) @@
625
    /**
626
     * {@inheritdoc}
627
     */
628
    public function hasForeignKey($tableName, $columns, $constraint = null)
629
    {
630
        if (is_string($columns)) {
631
            $columns = [$columns]; // str to array
632
        }
633
        $foreignKeys = $this->getForeignKeys($tableName);
634
        if ($constraint) {
635
            if (isset($foreignKeys[$constraint])) {
636
                return !empty($foreignKeys[$constraint]);
637
            }
638
            return false;
639
        } else {
640
            foreach ($foreignKeys as $key) {
641
                $a = array_diff($columns, $key['columns']);
642
                if (empty($a)) {
643
                    return true;
644
                }
645
            }
646
            return false;
647
        }
648
    }
649
650
    /**
651
     * Get an array of foreign keys from a particular table.