Completed
Pull Request — master (#1339)
by José
01:55
created

DropIndex   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 7 1
A buildFromName() 0 7 1
A getIndex() 0 4 1
1
<?php
2
/**
3
 * Phinx
4
 *
5
 * (The MIT license)
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated * documentation files (the "Software"), to
9
 * deal in the Software without restriction, including without limitation the
10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11
 * sell copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
 * IN THE SOFTWARE.
24
 */
25
namespace Phinx\Db\Action;
26
27
use InvalidArgumentException;
28
use Phinx\Db\Table\Index;
29
use Phinx\Db\Table\Table;
30
31
class DropIndex extends Action
32
{
33
34
    /**
35
     * The index to drop
36
     *
37
     * @var Index
38
     */
39
    protected $index;
40
41
    /**
42
     * Constructor
43
     *
44
     * @param Table $table The table owning the index
45
     * @param Index $index The index to be dropped
46
     */
47
    public function __construct(Table $table, Index $index)
48
    {
49
        parent::__construct($table);
50
        $this->index = $index;
51
    }
52
53
    /**
54
     * Creates a new DropIndex object after assembling the passed
55
     * arguments.
56
     *
57
     * @param Table $table The table where the index is
58
     * @param array $columns the indexed columns
59
     * @return DropIndex
60
     */
61
    public static function build(Table $table, array $columns = [])
62
    {
63
        $index = new Index();
64
        $index->setColumns($columns);
65
66
        return new static($table, $index);
67
    }
68
69
    /**
70
     * Creates a new DropIndex when the name of the index to drop
71
     * is knonwn.
72
     *
73
     * @param Table $table The table where the index is
74
     * @param mixed $name The name of the index
75
     * @return DropIndex
76
     */
77
    public static function buildFromName(Table $table, $name)
78
    {
79
        $index = new Index();
80
        $index->setName($name);
81
82
        return new static($table, $index);
83
    }
84
85
    /**
86
     * Returns the index to be dropped
87
     *
88
     * @return Index
89
     */
90
    public function getIndex()
91
    {
92
        return $this->index;
93
    }
94
}
95