Code Duplication    Length = 56-58 lines in 2 locations

src/Phinx/Db/Action/AddIndex.php 1 location

@@ 31-88 (lines=58) @@
28
use Phinx\Db\Table\Index;
29
use Phinx\Db\Table\Table;
30
31
class AddIndex extends Action
32
{
33
    /**
34
     * The index to add to the table
35
     *
36
     * @var Index
37
     */
38
    protected $index;
39
40
    /**
41
     * Constructor
42
     *
43
     * @param Table $table The table to add the index to
44
     * @param Index $index The index to be added
45
     */
46
    public function __construct(Table $table, Index $index)
47
    {
48
        parent::__construct($table);
49
        $this->index = $index;
50
    }
51
52
    /**
53
     * Creates a new AddIndex object after building the index object with the
54
     * provided arguments
55
     *
56
     * @param Table $table The table to add the index to
57
     * @param mixed $columns The columns to index
58
     * @param array $options Additional options for the index creation
59
     * @return AddIndex
60
     */
61
    public static function build(Table $table, $columns, array $options = [])
62
    {
63
        // create a new index object if strings or an array of strings were supplied
64
        $index = $columns;
65
66
        if (!$columns instanceof Index) {
67
            $index = new Index();
68
69
            if (is_string($columns)) {
70
                $columns = [$columns]; // str to array
71
            }
72
73
            $index->setColumns($columns);
74
            $index->setOptions($options);
75
        }
76
77
        return new static($table, $index);
78
    }
79
80
    /**
81
     * Returns the index to be added
82
     *
83
     * @return Index
84
     */
85
    public function getIndex()
86
    {
87
        return $this->index;
88
    }
89
}
90

src/Phinx/Db/Action/DropForeignKey.php 1 location

@@ 31-86 (lines=56) @@
28
use Phinx\Db\Table\ForeignKey;
29
use Phinx\Db\Table\Table;
30
31
class DropForeignKey extends Action
32
{
33
34
    /**
35
     * The foreing key to remove
36
     *
37
     * @var ForeignKey
38
     */
39
    protected $foreignKey;
40
41
    /**
42
     * Constructor
43
     *
44
     * @param Table $table The table to remove the constraint from
45
     * @param ForeignKey $foreignKey The foreign key to remove
46
     */
47
    public function __construct(Table $table, ForeignKey $foreignKey)
48
    {
49
        parent::__construct($table);
50
        $this->foreignKey = $foreignKey;
51
    }
52
53
    /**
54
     * Creates a new DropForeignKey object after building the ForeignKey
55
     * definition out of the passed arguments.
56
     *
57
     * @param Table $table The table to dele the foreign key from
58
     * @param string|string[] $columns The columns participating in the foreign key
59
     * @param string|null $constraint The constraint name
60
     * @return DropForeignKey
61
     */
62
    public static function build(Table $table, $columns, $constraint = null)
63
    {
64
        if (is_string($columns)) {
65
            $columns = [$columns];
66
        }
67
68
        $foreignKey = new ForeignKey();
69
        $foreignKey->setColumns($columns);
70
71
        if ($constraint) {
72
            $foreignKey->setConstraint($constraint);
73
        }
74
75
        return new static($table, $foreignKey);
76
    }
77
78
    /**
79
     * Returns the  foreign key to remove
80
     *
81
     * @return ForeignKey
82
     */
83
    public function getForeignKey()
84
    {
85
        return $this->foreignKey;
86
    }
87
}
88