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/PostgresAdapter.php 1 location

@@ 627-647 (lines=21) @@
624
    /**
625
     * {@inheritdoc}
626
     */
627
    public function hasForeignKey($tableName, $columns, $constraint = null)
628
    {
629
        if (is_string($columns)) {
630
            $columns = [$columns]; // str to array
631
        }
632
        $foreignKeys = $this->getForeignKeys($tableName);
633
        if ($constraint) {
634
            if (isset($foreignKeys[$constraint])) {
635
                return !empty($foreignKeys[$constraint]);
636
            }
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
647
            return false;
648
        }
649
    }
650

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

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