Completed
Push — master ( 152a5f...57e856 )
by José
11s
created

AddColumn   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 17.65 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 9
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 9 9 1
A getColumn() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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