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 Phinx\Db\Table\Column; |
28
|
|
|
use Phinx\Db\Table\Table; |
29
|
|
|
|
30
|
|
|
class AddColumn extends Action |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The column to add |
35
|
|
|
* |
36
|
|
|
* @var Column |
37
|
|
|
*/ |
38
|
|
|
protected $column; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructo |
42
|
|
|
* |
43
|
|
|
* @param Table $table The table to add the column to |
44
|
|
|
* @param Column $column The column to add |
45
|
|
|
*/ |
46
|
|
|
public function __construct(Table $table, Column $column) |
47
|
|
|
{ |
48
|
|
|
parent::__construct($table); |
49
|
|
|
$this->column = $column; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns a new AddColumn object after assembling the given commands |
54
|
|
|
* |
55
|
|
|
* @param Table $table The table to add the column to |
56
|
|
|
* @param mixed $columnName The column name |
57
|
|
|
* @param mixed $type The column type |
58
|
|
|
* @param mixed $options The column options |
59
|
|
|
* @return AddColumn |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public static function build(Table $table, $columnName, $type = null, $options = []) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$column = new Column(); |
64
|
|
|
$column->setName($columnName); |
65
|
|
|
$column->setType($type); |
66
|
|
|
$column->setOptions($options); // map options to column methods |
67
|
|
|
|
68
|
|
|
return new static($table, $column); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the column to be added |
73
|
|
|
* |
74
|
|
|
* @return Column |
75
|
|
|
*/ |
76
|
|
|
public function getColumn() |
77
|
|
|
{ |
78
|
|
|
return $this->column; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.