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 |
||
5 | trait MakesAssertions |
||
6 | { |
||
7 | /** {@inheritdoc} */ |
||
8 | public function assertTitle($title) |
||
14 | |||
15 | /** {@inheritdoc} */ |
||
16 | public function assertTitleContains($title) |
||
22 | |||
23 | /** {@inheritdoc} */ |
||
24 | public function assertHasCookie($name, $decrypt = true) |
||
30 | |||
31 | /** {@inheritdoc} */ |
||
32 | public function assertHasPlainCookie($name) |
||
38 | |||
39 | /** {@inheritdoc} */ |
||
40 | public function assertCookieMissing($name, $decrypt = true) |
||
46 | |||
47 | /** {@inheritdoc} */ |
||
48 | public function assertPlainCookieMissing($name) |
||
54 | |||
55 | /** {@inheritdoc} */ |
||
56 | public function assertCookieValue($name, $value, $decrypt = true) |
||
62 | |||
63 | /** {@inheritdoc} */ |
||
64 | public function assertPlainCookieValue($name, $value) |
||
70 | |||
71 | /** {@inheritdoc} */ |
||
72 | public function assertSee($text) |
||
78 | |||
79 | /** {@inheritdoc} */ |
||
80 | public function assertSeeIn($selector, $text) |
||
86 | |||
87 | /** {@inheritdoc} */ |
||
88 | public function assertDontSeeIn($selector, $text) |
||
94 | |||
95 | /** {@inheritdoc} */ |
||
96 | public function assertSourceHas($code) |
||
102 | |||
103 | /** {@inheritdoc} */ |
||
104 | public function assertSourceMissing($code) |
||
110 | |||
111 | /** {@inheritdoc} */ |
||
112 | public function assertSeeLink($link) |
||
118 | |||
119 | /** {@inheritdoc} */ |
||
120 | public function assertDontSeeLink($link) |
||
126 | |||
127 | /** {@inheritdoc} */ |
||
128 | public function seeLink($link) |
||
134 | |||
135 | /** {@inheritdoc} */ |
||
136 | public function assertInputValue($field, $value) |
||
142 | |||
143 | /** {@inheritdoc} */ |
||
144 | public function assertInputValueIsNot($field, $value) |
||
150 | |||
151 | /** {@inheritdoc} */ |
||
152 | public function inputValue($field) |
||
158 | |||
159 | /** {@inheritdoc} */ |
||
160 | public function assertChecked($field, $value = null) |
||
166 | |||
167 | /** {@inheritdoc} */ |
||
168 | public function assertNotChecked($field, $value = null) |
||
174 | |||
175 | /** {@inheritdoc} */ |
||
176 | public function assertRadioSelected($field, $value) |
||
182 | |||
183 | /** {@inheritdoc} */ |
||
184 | public function assertRadioNotSelected($field, $value = null) |
||
190 | |||
191 | /** {@inheritdoc} */ |
||
192 | public function assertSelected($field, $value) |
||
198 | |||
199 | /** {@inheritdoc} */ |
||
200 | public function assertNotSelected($field, $value) |
||
206 | |||
207 | /** {@inheritdoc} */ |
||
208 | public function assertSelectHasOptions($field, array $values) |
||
214 | |||
215 | /** {@inheritdoc} */ |
||
216 | public function assertSelectMissingOptions($field, array $values) |
||
222 | |||
223 | /** {@inheritdoc} */ |
||
224 | public function assertSelectHasOption($field, $value) |
||
228 | |||
229 | /** {@inheritdoc} */ |
||
230 | public function assertSelectMissingOption($field, $value) |
||
234 | |||
235 | /** {@inheritdoc} */ |
||
236 | public function selected($field, $value) |
||
242 | |||
243 | /** {@inheritdoc} */ |
||
244 | public function assertValue($selector, $value) |
||
250 | |||
251 | /** {@inheritdoc} */ |
||
252 | public function assertVisible($selector) |
||
258 | |||
259 | /** {@inheritdoc} */ |
||
260 | public function assertPresent($selector) |
||
266 | |||
267 | /** {@inheritdoc} */ |
||
268 | public function assertMissing($selector) |
||
274 | |||
275 | /** {@inheritdoc} */ |
||
276 | public function assertDialogOpened($message) |
||
282 | |||
283 | /** {@inheritdoc} */ |
||
284 | public function assertEnabled($field) |
||
290 | |||
291 | /** {@inheritdoc} */ |
||
292 | public function assertDisabled($field) |
||
298 | |||
299 | /** {@inheritdoc} */ |
||
300 | public function assertFocused($field) |
||
306 | |||
307 | /** {@inheritdoc} */ |
||
308 | public function assertNotFocused($field) |
||
314 | |||
315 | /** {@inheritdoc} */ |
||
316 | public function assertVue($key, $value, $componentSelector = null) |
||
322 | |||
323 | /** {@inheritdoc} */ |
||
324 | public function assertVueIsNot($key, $value, $componentSelector = null) |
||
330 | |||
331 | /** {@inheritdoc} */ |
||
332 | public function assertVueContains($key, $value, $componentSelector = null) |
||
338 | |||
339 | /** {@inheritdoc} */ |
||
340 | public function assertVueDoesNotContain($key, $value, $componentSelector = null) |
||
346 | |||
347 | /** {@inheritdoc} */ |
||
348 | public function vueAttribute($componentSelector, $key) |
||
354 | } |
||
355 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: