Code Duplication    Length = 20-21 lines in 3 locations

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

@@ 668-688 (lines=21) @@
665
    /**
666
     * {@inheritdoc}
667
     */
668
    public function hasForeignKey($tableName, $columns, $constraint = null)
669
    {
670
        if (is_string($columns)) {
671
            $columns = [$columns]; // str to array
672
        }
673
        $foreignKeys = $this->getForeignKeys($tableName);
674
        if ($constraint) {
675
            if (isset($foreignKeys[$constraint])) {
676
                return !empty($foreignKeys[$constraint]);
677
            }
678
679
            return false;
680
        } else {
681
            foreach ($foreignKeys as $key) {
682
                $a = array_diff($columns, $key['columns']);
683
                if (empty($a)) {
684
                    return true;
685
                }
686
            }
687
688
            return false;
689
        }
690
    }
691

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

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

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

@@ 763-783 (lines=21) @@
760
    /**
761
     * {@inheritdoc}
762
     */
763
    public function hasForeignKey($tableName, $columns, $constraint = null)
764
    {
765
        if (is_string($columns)) {
766
            $columns = [$columns]; // str to array
767
        }
768
        $foreignKeys = $this->getForeignKeys($tableName);
769
        if ($constraint) {
770
            if (isset($foreignKeys[$constraint])) {
771
                return !empty($foreignKeys[$constraint]);
772
            }
773
774
            return false;
775
        } else {
776
            foreach ($foreignKeys as $key) {
777
                $a = array_diff($columns, $key['columns']);
778
                if (empty($a)) {
779
                    return true;
780
                }
781
            }
782
783
            return false;
784
        }
785
    }
786