Code Duplication    Length = 20-21 lines in 3 locations

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

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

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

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

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

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