Code Duplication    Length = 20-24 lines in 4 locations

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

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

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

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

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

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

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

@@ 602-625 (lines=24) @@
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
609
        if ($constraint) {
610
            if (isset($foreignKeys[$constraint])) {
611
                return !empty($foreignKeys[$constraint]);
612
            }
613
614
            return false;
615
        } else {
616
            foreach ($foreignKeys as $key) {
617
                $a = array_diff($columns, $key['COLUMNS']);
618
                if (empty($a)) {
619
                    return true;
620
                }
621
            }
622
623
            return false;
624
        }
625
    }
626
627
    /**
628
     * Get an array of foreign keys from a particular table.