Options   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 191
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 22
c 7
b 1
f 1
lcom 1
cbo 2
dl 0
loc 191
ccs 47
cts 47
cp 1
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getDirection() 0 4 1
A withDirection() 0 4 1
A isForced() 0 4 1
A withForced() 0 4 1
A isDryRun() 0 4 1
A withDryRun() 0 4 1
A isExceptionOnSkip() 0 4 1
A withExceptionOnSkip() 0 4 1
A getCustom() 0 4 1
A withCustom() 0 4 1
A __toString() 0 4 1
A __construct() 0 17 2
B isSameValueAs() 0 13 7
A fromOptionsWithDirection() 0 9 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <https://github.com/baleen/migrations>.
18
 */
19
20
namespace Baleen\Migrations\Migration;
21
22
use Baleen\Migrations\Exception\InvalidArgumentException;
23
use Baleen\Migrations\Migration\Options\Direction;
24
use Baleen\Migrations\Common\ValueObjectInterface;
25
26
/**
27
 * @{inheritdoc}
28
 *
29
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
30
 *
31
 * @author Gabriel Somoza <[email protected]>
32
 */
33
final class Options implements OptionsInterface
34
{
35
    /**
36
     * @var Direction
37
     */
38
    private $direction;
39
40
    /**
41
     * @var bool
42
     */
43
    private $forced;
44
45
    /**
46
     * @var bool
47
     */
48
    private $dryRun;
49
50
    /**
51
     * @var array
52
     */
53
    private $custom;
54
55
    /**
56
     * @var bool
57
     */
58
    private $exceptionOnSkip;
59
60
    /**
61
     * @param $direction
62
     * @param bool $forced
63
     * @param bool $dryRun
64
     * @param bool $exceptionOnSkip
65
     * @param array $custom
66
     *
67
     * @throws InvalidArgumentException
68
     */
69 61
    public function __construct(
70
        Direction $direction = null,
71
        $forced = false,
72
        $dryRun = false,
73
        $exceptionOnSkip = true,
74
        array $custom = []
75
    ) {
76 61
        if (null === $direction) {
77 28
            $direction = Direction::up();
78 28
        }
79 61
        $this->direction = $direction;
80
81 61
        $this->forced = (bool) $forced;
82 61
        $this->dryRun = (bool) $dryRun;
83 61
        $this->exceptionOnSkip = (bool) $exceptionOnSkip;
84 61
        $this->custom = $custom;
85 61
    }
86
87
    /**
88
     * getDirection
89
     *
90
     * @return Direction
91
     */
92 52
    public function getDirection()
93
    {
94 52
        return $this->direction;
95
    }
96
97
    /**
98
     * @param Direction $direction
99
     *
100
     * @return static
101
     *
102
     * @throws InvalidArgumentException
103
     */
104 17
    public function withDirection(Direction $direction)
105
    {
106 17
        return new static($direction, $this->forced, $this->dryRun, $this->exceptionOnSkip, $this->custom);
107
    }
108
109
    /**
110
     * @return bool
111
     */
112 40
    public function isForced()
113
    {
114 40
        return $this->forced;
115
    }
116
117
    /**
118
     * withForced
119
     * @param $forced
120
     * @return static
121
     */
122 1
    public function withForced($forced)
123
    {
124 1
        return new static($this->direction, $forced, $this->dryRun, $this->exceptionOnSkip, $this->custom);
125
    }
126
127
    /**
128
     * @return bool
129
     */
130 17
    public function isDryRun()
131
    {
132 17
        return $this->dryRun;
133
    }
134
135
    /**
136
     * withDryRun
137
     * @param bool $dryRun
138
     * @return static
139
     */
140 1
    public function withDryRun($dryRun)
141
    {
142 1
        return new static($this->direction, $this->forced, $dryRun, $this->exceptionOnSkip, $this->custom);
143
    }
144
145
    /**
146
     * @return bool
147
     */
148 30
    public function isExceptionOnSkip()
149
    {
150 30
        return $this->exceptionOnSkip;
151
    }
152
153
    /**
154
     * @param bool $exceptionOnSkip
155
     * @return static
156
     */
157 20
    public function withExceptionOnSkip($exceptionOnSkip)
158
    {
159 20
        return new static($this->direction, $this->forced, $this->dryRun, $exceptionOnSkip, $this->custom);
160
    }
161
162
    /**
163
     * @return array
164
     */
165 14
    public function getCustom()
166
    {
167 14
        return $this->custom;
168
    }
169
170
    /**
171
     * @param array $custom
172
     * @return static
173
     */
174 1
    public function withCustom(array $custom)
175
    {
176 1
        return new static($this->direction, $this->forced, $this->dryRun, $this->exceptionOnSkip, $custom);
177
    }
178
179
    /**
180
     * @inheritdoc
181
     */
182 7
    public function isSameValueAs(ValueObjectInterface $options)
183
    {
184 7
        if (!$options instanceof OptionsInterface) {
185 1
            return false;
186
        }
187
188 6
        return get_class($options) === get_class($this)
189 6
            && $this->getDirection()->isSameValueAs($options->getDirection())
190 6
            && $this->isForced() === $options->isForced()
191 6
            && $this->isDryRun() === $options->isDryRun()
192 6
            && $this->isExceptionOnSkip() === $options->isExceptionOnSkip()
193 6
            && $this->getCustom() == $options->getCustom();
194
    }
195
196
    /**
197
     * fromOptionsWithDirection
198
     *
199
     * @param Direction $direction
200
     * @param OptionsInterface|null $options
201
     *
202
     * @return static
203
     */
204 10
    public static function fromOptionsWithDirection(Direction $direction, OptionsInterface $options = null)
205
    {
206 10
        if (null === $options) {
207 1
            $options = (new static($direction))->withExceptionOnSkip(false);
208 1
        } else {
209 9
            $options = $options->withDirection($direction);
210
        }
211 10
        return $options;
212
    }
213
214
    /**
215
     * Returns a string representation of the object.
216
     *
217
     * @return string
218
     */
219 1
    public function __toString()
220
    {
221 1
        return __CLASS__ . '@' . spl_object_hash($this);
222
    }
223
}
224