These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Chubbyphp\Mock; |
||
6 | |||
7 | class Call |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | private $method; |
||
13 | |||
14 | /** |
||
15 | * @var bool |
||
16 | */ |
||
17 | private $hasWith = false; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | private $with = []; |
||
23 | |||
24 | /** |
||
25 | * @var \Throwable|null |
||
26 | */ |
||
27 | private $exception; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | */ |
||
32 | private $hasReturnSelf = false; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $hasReturn = false; |
||
38 | |||
39 | /** |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $hasReturnCallback = false; |
||
43 | |||
44 | /** |
||
45 | * @var mixed |
||
46 | */ |
||
47 | private $return; |
||
48 | |||
49 | /** |
||
50 | * @var callable|null |
||
51 | */ |
||
52 | private $returnCallback; |
||
53 | |||
54 | 19 | private function __construct() |
|
55 | { |
||
56 | 19 | } |
|
57 | |||
58 | /** |
||
59 | * @param string $method |
||
60 | * |
||
61 | * @return self |
||
62 | */ |
||
63 | 19 | public static function create(string $method): self |
|
64 | { |
||
65 | 19 | $self = new self(); |
|
66 | 19 | $self->method = $method; |
|
67 | |||
68 | 19 | return $self; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param mixed ...$with |
||
73 | * |
||
74 | * @return self |
||
75 | */ |
||
76 | 2 | public function with(...$with): self |
|
77 | { |
||
78 | 2 | $this->hasWith = true; |
|
79 | 2 | $this->with = $with; |
|
80 | |||
81 | 2 | return $this; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param \Throwable $exception |
||
86 | * |
||
87 | * @return self |
||
88 | */ |
||
89 | 8 | View Code Duplication | public function willThrowException(\Throwable $exception): self |
0 ignored issues
–
show
|
|||
90 | { |
||
91 | 8 | if ($this->hasReturnSelf) { |
|
92 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return self', __METHOD__)); |
|
93 | } |
||
94 | |||
95 | 7 | if ($this->hasReturn) { |
|
96 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return', __METHOD__)); |
|
97 | } |
||
98 | |||
99 | 6 | if ($this->hasReturnCallback) { |
|
100 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return callback', __METHOD__)); |
|
101 | } |
||
102 | |||
103 | 5 | $this->exception = $exception; |
|
104 | |||
105 | 5 | return $this; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return self |
||
110 | */ |
||
111 | 7 | View Code Duplication | public function willReturnSelf(): self |
112 | { |
||
113 | 7 | if (null !== $this->exception) { |
|
114 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a exception', __METHOD__)); |
|
115 | } |
||
116 | |||
117 | 6 | if ($this->hasReturn) { |
|
118 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return', __METHOD__)); |
|
119 | } |
||
120 | |||
121 | 5 | if ($this->hasReturnCallback) { |
|
122 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return callback', __METHOD__)); |
|
123 | } |
||
124 | |||
125 | 4 | $this->hasReturnSelf = true; |
|
126 | |||
127 | 4 | return $this; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param mixed $return |
||
132 | * |
||
133 | * @return self |
||
134 | */ |
||
135 | 7 | View Code Duplication | public function willReturn($return): self |
136 | { |
||
137 | 7 | if (null !== $this->exception) { |
|
138 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a exception', __METHOD__)); |
|
139 | } |
||
140 | |||
141 | 6 | if ($this->hasReturnSelf) { |
|
142 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return self', __METHOD__)); |
|
143 | } |
||
144 | |||
145 | 5 | if ($this->hasReturnCallback) { |
|
146 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return callback', __METHOD__)); |
|
147 | } |
||
148 | |||
149 | 4 | $this->hasReturn = true; |
|
150 | 4 | $this->return = $return; |
|
151 | |||
152 | 4 | return $this; |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * @return self |
||
157 | */ |
||
158 | 7 | View Code Duplication | public function willReturnCallback(callable $returnCallback): self |
0 ignored issues
–
show
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...
|
|||
159 | { |
||
160 | 7 | if (null !== $this->exception) { |
|
161 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a exception', __METHOD__)); |
|
162 | } |
||
163 | |||
164 | 6 | if ($this->hasReturnSelf) { |
|
165 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return self', __METHOD__)); |
|
166 | } |
||
167 | |||
168 | 5 | if ($this->hasReturn) { |
|
169 | 1 | throw new \InvalidArgumentException(sprintf('%s: There is already a return', __METHOD__)); |
|
170 | } |
||
171 | |||
172 | 4 | $this->hasReturnCallback = true; |
|
173 | 4 | $this->returnCallback = $returnCallback; |
|
174 | |||
175 | 4 | return $this; |
|
176 | } |
||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | 7 | public function getMethod(): string |
|
182 | { |
||
183 | 7 | return $this->method; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * @return bool |
||
188 | */ |
||
189 | 7 | public function hasWith(): bool |
|
190 | { |
||
191 | 7 | return $this->hasWith; |
|
192 | } |
||
193 | |||
194 | /** |
||
195 | * @return bool |
||
196 | */ |
||
197 | 7 | public function hasReturnSelf(): bool |
|
198 | { |
||
199 | 7 | return $this->hasReturnSelf; |
|
200 | } |
||
201 | |||
202 | /** |
||
203 | * @return bool |
||
204 | */ |
||
205 | 7 | public function hasReturn(): bool |
|
206 | { |
||
207 | 7 | return $this->hasReturn; |
|
208 | } |
||
209 | |||
210 | /** |
||
211 | * @return bool |
||
212 | */ |
||
213 | 7 | public function hasReturnCallback(): bool |
|
214 | { |
||
215 | 7 | return $this->hasReturnCallback; |
|
216 | } |
||
217 | |||
218 | /** |
||
219 | * @return array |
||
220 | */ |
||
221 | 7 | public function getWith(): array |
|
222 | { |
||
223 | 7 | return $this->with; |
|
224 | } |
||
225 | |||
226 | /** |
||
227 | * @return \Throwable|null |
||
228 | */ |
||
229 | 7 | public function getException() |
|
230 | { |
||
231 | 7 | return $this->exception; |
|
232 | } |
||
233 | |||
234 | /** |
||
235 | * @return mixed |
||
236 | */ |
||
237 | 7 | public function getReturn() |
|
238 | { |
||
239 | 7 | return $this->return; |
|
240 | } |
||
241 | |||
242 | /** |
||
243 | * @return mixed |
||
244 | */ |
||
245 | 7 | public function getReturnCallback() |
|
246 | { |
||
247 | 7 | return $this->returnCallback; |
|
248 | } |
||
249 | } |
||
250 |
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.