1 | <?php |
||
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() |
|
96 | |||
97 | /** |
||
98 | * @param Direction $direction |
||
99 | * |
||
100 | * @return static |
||
101 | * |
||
102 | * @throws InvalidArgumentException |
||
103 | */ |
||
104 | 17 | public function withDirection(Direction $direction) |
|
108 | |||
109 | /** |
||
110 | * @return bool |
||
111 | */ |
||
112 | 40 | public function isForced() |
|
116 | |||
117 | /** |
||
118 | * withForced |
||
119 | * @param $forced |
||
120 | * @return static |
||
121 | */ |
||
122 | 1 | public function withForced($forced) |
|
126 | |||
127 | /** |
||
128 | * @return bool |
||
129 | */ |
||
130 | 17 | public function isDryRun() |
|
134 | |||
135 | /** |
||
136 | * withDryRun |
||
137 | * @param bool $dryRun |
||
138 | * @return static |
||
139 | */ |
||
140 | 1 | public function withDryRun($dryRun) |
|
144 | |||
145 | /** |
||
146 | * @return bool |
||
147 | */ |
||
148 | 30 | public function isExceptionOnSkip() |
|
152 | |||
153 | /** |
||
154 | * @param bool $exceptionOnSkip |
||
155 | * @return static |
||
156 | */ |
||
157 | 20 | public function withExceptionOnSkip($exceptionOnSkip) |
|
161 | |||
162 | /** |
||
163 | * @return array |
||
164 | */ |
||
165 | 14 | public function getCustom() |
|
169 | |||
170 | /** |
||
171 | * @param array $custom |
||
172 | * @return static |
||
173 | */ |
||
174 | 1 | public function withCustom(array $custom) |
|
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() |
|
223 | } |
||
224 |