MakesAssertions   B
last analyzed

Complexity

Total Complexity 44

Size/Duplication

Total Lines 350
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 44
lcom 1
cbo 0
dl 0
loc 350
rs 8.8798
c 0
b 0
f 0

44 Methods

Rating   Name   Duplication   Size   Complexity  
A assertTitle() 0 6 1
A assertTitleContains() 0 6 1
A assertHasCookie() 0 6 1
A assertHasPlainCookie() 0 6 1
A assertCookieMissing() 0 6 1
A assertPlainCookieMissing() 0 6 1
A assertCookieValue() 0 6 1
A assertPlainCookieValue() 0 6 1
A assertSee() 0 6 1
A assertSeeIn() 0 6 1
A assertDontSeeIn() 0 6 1
A assertSourceHas() 0 6 1
A assertSourceMissing() 0 6 1
A assertSeeLink() 0 6 1
A assertDontSeeLink() 0 6 1
A seeLink() 0 6 1
A assertInputValue() 0 6 1
A assertInputValueIsNot() 0 6 1
A inputValue() 0 6 1
A assertChecked() 0 6 1
A assertNotChecked() 0 6 1
A assertRadioSelected() 0 6 1
A assertRadioNotSelected() 0 6 1
A assertSelected() 0 6 1
A assertNotSelected() 0 6 1
A assertSelectHasOptions() 0 6 1
A assertSelectMissingOptions() 0 6 1
A assertSelectHasOption() 0 4 1
A assertSelectMissingOption() 0 4 1
A selected() 0 6 1
A assertValue() 0 6 1
A assertVisible() 0 6 1
A assertPresent() 0 6 1
A assertMissing() 0 6 1
A assertDialogOpened() 0 6 1
A assertEnabled() 0 6 1
A assertDisabled() 0 6 1
A assertFocused() 0 6 1
A assertNotFocused() 0 6 1
A assertVue() 0 6 1
A assertVueIsNot() 0 6 1
A assertVueContains() 0 6 1
A assertVueDoesNotContain() 0 6 1
A vueAttribute() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like MakesAssertions often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MakesAssertions, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace BeyondCode\DuskDashboard\Dusk\Concerns;
4
5
trait MakesAssertions
6
{
7
    /** {@inheritdoc} */
8
    public function assertTitle($title)
9
    {
10
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
0 ignored issues
show
Bug introduced by
The property actionCollector does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
11
12
        return parent::assertTitle($title);
13
    }
14
15
    /** {@inheritdoc} */
16
    public function assertTitleContains($title)
17
    {
18
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
19
20
        return parent::assertTitleContains($title);
21
    }
22
23
    /** {@inheritdoc} */
24
    public function assertHasCookie($name, $decrypt = true)
25
    {
26
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
27
28
        return parent::assertHasCookie($name, $decrypt);
29
    }
30
31
    /** {@inheritdoc} */
32
    public function assertHasPlainCookie($name)
33
    {
34
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
35
36
        return parent::assertHasPlainCookie($name);
37
    }
38
39
    /** {@inheritdoc} */
40
    public function assertCookieMissing($name, $decrypt = true)
41
    {
42
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
43
44
        return parent::assertCookieMissing($name, $decrypt);
45
    }
46
47
    /** {@inheritdoc} */
48
    public function assertPlainCookieMissing($name)
49
    {
50
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
51
52
        return parent::assertPlainCookieMissing($name);
53
    }
54
55
    /** {@inheritdoc} */
56
    public function assertCookieValue($name, $value, $decrypt = true)
57
    {
58
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
59
60
        return parent::assertCookieValue($name, $value, $decrypt);
61
    }
62
63
    /** {@inheritdoc} */
64
    public function assertPlainCookieValue($name, $value)
65
    {
66
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
67
68
        return parent::assertPlainCookieValue($name, $value);
69
    }
70
71
    /** {@inheritdoc} */
72
    public function assertSee($text)
73
    {
74
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
75
76
        return parent::assertSee($text);
77
    }
78
79
    /** {@inheritdoc} */
80
    public function assertSeeIn($selector, $text)
81
    {
82
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
83
84
        return parent::assertSeeIn($selector, $text);
85
    }
86
87
    /** {@inheritdoc} */
88
    public function assertDontSeeIn($selector, $text)
89
    {
90
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
91
92
        return parent::assertDontSeeIn($selector, $text);
93
    }
94
95
    /** {@inheritdoc} */
96
    public function assertSourceHas($code)
97
    {
98
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
99
100
        return parent::assertSourceHas($code);
101
    }
102
103
    /** {@inheritdoc} */
104
    public function assertSourceMissing($code)
105
    {
106
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
107
108
        return parent::assertSourceMissing($code);
109
    }
110
111
    /** {@inheritdoc} */
112
    public function assertSeeLink($link)
113
    {
114
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
115
116
        return parent::assertSeeLink($link);
117
    }
118
119
    /** {@inheritdoc} */
120
    public function assertDontSeeLink($link)
121
    {
122
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
123
124
        return parent::assertDontSeeLink($link);
125
    }
126
127
    /** {@inheritdoc} */
128
    public function seeLink($link)
129
    {
130
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
131
132
        return parent::seeLink($link);
133
    }
134
135
    /** {@inheritdoc} */
136
    public function assertInputValue($field, $value)
137
    {
138
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
139
140
        return parent::assertInputValue($field, $value);
141
    }
142
143
    /** {@inheritdoc} */
144
    public function assertInputValueIsNot($field, $value)
145
    {
146
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
147
148
        return parent::assertInputValueIsNot($field, $value);
149
    }
150
151
    /** {@inheritdoc} */
152
    public function inputValue($field)
153
    {
154
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
155
156
        return parent::inputValue($field);
157
    }
158
159
    /** {@inheritdoc} */
160
    public function assertChecked($field, $value = null)
161
    {
162
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
163
164
        return parent::assertChecked($field, $value);
165
    }
166
167
    /** {@inheritdoc} */
168
    public function assertNotChecked($field, $value = null)
169
    {
170
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
171
172
        return parent::assertNotChecked($field, $value);
173
    }
174
175
    /** {@inheritdoc} */
176
    public function assertRadioSelected($field, $value)
177
    {
178
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
179
180
        return parent::assertRadioSelected($field, $value);
181
    }
182
183
    /** {@inheritdoc} */
184
    public function assertRadioNotSelected($field, $value = null)
185
    {
186
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
187
188
        return parent::assertRadioNotSelected($field, $value);
189
    }
190
191
    /** {@inheritdoc} */
192
    public function assertSelected($field, $value)
193
    {
194
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
195
196
        return parent::assertSelectHasOption($field, $value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSelectHasOption() instead of assertSelected()). Are you sure this is correct? If so, you might want to change this to $this->assertSelectHasOption().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
197
    }
198
199
    /** {@inheritdoc} */
200
    public function assertNotSelected($field, $value)
201
    {
202
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
203
204
        return parent::assertNotSelected($field, $value);
205
    }
206
207
    /** {@inheritdoc} */
208
    public function assertSelectHasOptions($field, array $values)
209
    {
210
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
211
212
        return parent::assertSelectHasOptions($field, $values);
213
    }
214
215
    /** {@inheritdoc} */
216
    public function assertSelectMissingOptions($field, array $values)
217
    {
218
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
219
220
        return parent::assertSelectMissingOptions($field, $values);
221
    }
222
223
    /** {@inheritdoc} */
224
    public function assertSelectHasOption($field, $value)
225
    {
226
        return $this->assertSelectHasOptions($field, [$value]);
227
    }
228
229
    /** {@inheritdoc} */
230
    public function assertSelectMissingOption($field, $value)
231
    {
232
        return $this->assertSelectMissingOptions($field, [$value]);
233
    }
234
235
    /** {@inheritdoc} */
236
    public function selected($field, $value)
237
    {
238
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
239
240
        return parent::select($field, $value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (select() instead of selected()). Are you sure this is correct? If so, you might want to change this to $this->select().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
241
    }
242
243
    /** {@inheritdoc} */
244
    public function assertValue($selector, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $selector is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
245
    {
246
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
247
248
        return parent::assertValue($field, $value);
0 ignored issues
show
Bug introduced by
The variable $field does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
249
    }
250
251
    /** {@inheritdoc} */
252
    public function assertVisible($selector)
253
    {
254
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
255
256
        return parent::assertVisible($selector);
257
    }
258
259
    /** {@inheritdoc} */
260
    public function assertPresent($selector)
261
    {
262
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
263
264
        return parent::assertPresent($selector);
265
    }
266
267
    /** {@inheritdoc} */
268
    public function assertMissing($selector)
269
    {
270
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
271
272
        return parent::assertMissing($selector);
273
    }
274
275
    /** {@inheritdoc} */
276
    public function assertDialogOpened($message)
277
    {
278
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
279
280
        return parent::assertDialogOpened($message);
281
    }
282
283
    /** {@inheritdoc} */
284
    public function assertEnabled($field)
285
    {
286
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
287
288
        return parent::assertEnabled($field);
289
    }
290
291
    /** {@inheritdoc} */
292
    public function assertDisabled($field)
293
    {
294
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
295
296
        return parent::assertDisabled($field);
297
    }
298
299
    /** {@inheritdoc} */
300
    public function assertFocused($field)
301
    {
302
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
303
304
        return parent::assertFocused($field);
305
    }
306
307
    /** {@inheritdoc} */
308
    public function assertNotFocused($field)
309
    {
310
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
311
312
        return parent::assertNotFocused($field);
313
    }
314
315
    /** {@inheritdoc} */
316
    public function assertVue($key, $value, $componentSelector = null)
317
    {
318
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
319
320
        return parent::assertVue($key, $value, $componentSelector);
321
    }
322
323
    /** {@inheritdoc} */
324
    public function assertVueIsNot($key, $value, $componentSelector = null)
325
    {
326
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
327
328
        return parent::assertVueIsNot($key, $value, $componentSelector);
329
    }
330
331
    /** {@inheritdoc} */
332
    public function assertVueContains($key, $value, $componentSelector = null)
333
    {
334
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
335
336
        return parent::assertVueContains($key, $value, $componentSelector);
337
    }
338
339
    /** {@inheritdoc} */
340
    public function assertVueDoesNotContain($key, $value, $componentSelector = null)
341
    {
342
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
343
344
        return parent::assertVueDoesNotContain($key, $value, $componentSelector);
345
    }
346
347
    /** {@inheritdoc} */
348
    public function vueAttribute($componentSelector, $key)
349
    {
350
        $this->actionCollector->collect(__FUNCTION__, func_get_args(), $this);
351
352
        return parent::vueAttribute($componentSelector, $key);
353
    }
354
}
355