Code Duplication    Length = 20-21 lines in 3 locations

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

@@ 583-602 (lines=20) @@
580
    /**
581
     * {@inheritdoc}
582
     */
583
    public function hasForeignKey($tableName, $columns, $constraint = null)
584
    {
585
        if (is_string($columns)) {
586
            $columns = [$columns]; // str to array
587
        }
588
        $foreignKeys = $this->getForeignKeys($tableName);
589
        if ($constraint) {
590
            if (isset($foreignKeys[$constraint])) {
591
                return !empty($foreignKeys[$constraint]);
592
            }
593
594
            return false;
595
        } else {
596
            foreach ($foreignKeys as $key) {
597
                if ($columns == $key['columns']) {
598
                    return true;
599
                }
600
            }
601
602
            return false;
603
        }
604
    }
605

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

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