Code Duplication    Length = 20-21 lines in 3 locations

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

@@ 594-613 (lines=20) @@
591
    /**
592
     * {@inheritdoc}
593
     */
594
    public function hasForeignKey($tableName, $columns, $constraint = null)
595
    {
596
        if (is_string($columns)) {
597
            $columns = [$columns]; // str to array
598
        }
599
        $foreignKeys = $this->getForeignKeys($tableName);
600
        if ($constraint) {
601
            if (isset($foreignKeys[$constraint])) {
602
                return !empty($foreignKeys[$constraint]);
603
            }
604
605
            return false;
606
        } else {
607
            foreach ($foreignKeys as $key) {
608
                if ($columns == $key['columns']) {
609
                    return true;
610
                }
611
            }
612
613
            return false;
614
        }
615
    }
616

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

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

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

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