Complex classes like OptionalTest 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 OptionalTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class OptionalTest extends TestCase |
||
25 | { |
||
26 | public function testNewEmptyAlwaysProducesSameInstance(): void |
||
30 | |||
31 | public function testNewEmptyProducesEmptyInstance(): void |
||
35 | |||
36 | public function testOfNullableFromEmptyValueProducesAnEmptyInstance(): void |
||
40 | |||
41 | /** |
||
42 | * @param mixed $value |
||
43 | * |
||
44 | * @dataProvider getValidValues |
||
45 | */ |
||
46 | public function testOfNullableFromNonEmptyValueProducesNonEmptyInstance($value): void |
||
55 | |||
56 | public function testOfFromEmptyValueCausesExceptionWhenDisallowed(): void |
||
62 | |||
63 | /** |
||
64 | * @param mixed $value |
||
65 | * |
||
66 | * @dataProvider getValidValues |
||
67 | */ |
||
68 | public function testOfFromNonEmptyValueProducesNonEmptyInstance($value): void |
||
77 | |||
78 | public function testEmptyValueDisallowsGettingWrappedValue(): void |
||
84 | |||
85 | /** |
||
86 | * @throws ReflectionException |
||
87 | */ |
||
88 | public function testIfPresentIsNotExecutedIfValueIsNotPresent(): void |
||
99 | |||
100 | /** |
||
101 | * @param mixed $value |
||
102 | * |
||
103 | * @throws ReflectionException |
||
104 | * |
||
105 | * @dataProvider getValidValues |
||
106 | */ |
||
107 | public function testIfPresentIsExecutedWhenValueIsPresent($value): void |
||
118 | |||
119 | /** |
||
120 | * @throws ReflectionException |
||
121 | */ |
||
122 | public function testFilterIsNotExecutedIfValueIsNotPresent(): void |
||
133 | |||
134 | /** |
||
135 | * @param mixed $value |
||
136 | * |
||
137 | * @throws ReflectionException |
||
138 | * |
||
139 | * @dataProvider getValidValues |
||
140 | */ |
||
141 | public function testFilteringProducesEmptyOptionalWhenValueIsNotAccepted($value): void |
||
152 | |||
153 | /** |
||
154 | * @param mixed $value |
||
155 | * |
||
156 | * @throws ReflectionException |
||
157 | * |
||
158 | * @dataProvider getValidValues |
||
159 | */ |
||
160 | public function testFilteringProducesSameOptionalInstanceWhenValueIsAccepted($value): void |
||
172 | |||
173 | /** |
||
174 | * @throws ReflectionException |
||
175 | */ |
||
176 | public function testMappingEmptyOptionalProducesEmptyOptional(): void |
||
187 | |||
188 | /** |
||
189 | * @param mixed $value |
||
190 | * |
||
191 | * @throws ReflectionException |
||
192 | * |
||
193 | * @dataProvider getValidValues |
||
194 | */ |
||
195 | public function testMappingNonEmptyValuesProducesOptionalWithMapMethodReturnValue($value): void |
||
210 | |||
211 | /** |
||
212 | * @throws ReflectionException |
||
213 | */ |
||
214 | public function testMappingNonEmptyValuesMayProduceEmptyOptional(): void |
||
225 | |||
226 | /** |
||
227 | * @throws ReflectionException |
||
228 | */ |
||
229 | public function testFlatMappingEmptyOptionalProducesEmptyOptional(): void |
||
240 | |||
241 | /** |
||
242 | * @param mixed $value |
||
243 | * |
||
244 | * @throws ReflectionException |
||
245 | * |
||
246 | * @dataProvider getValidValues |
||
247 | */ |
||
248 | public function testFlatMappingNonEmptyOptionalProducesNonEmptyOptional($value): void |
||
260 | |||
261 | /** |
||
262 | * @throws ReflectionException |
||
263 | */ |
||
264 | public function testFlatMappingNonEmptyOptionalDisallowsEmptyMapperResult(): void |
||
277 | |||
278 | /** |
||
279 | * @param mixed $value |
||
280 | * |
||
281 | * @dataProvider getValidValues |
||
282 | */ |
||
283 | public function testOrElseRetrievesGivenValueOnEmptyOptional($value): void |
||
287 | |||
288 | /** |
||
289 | * @param mixed $value |
||
290 | * |
||
291 | * @dataProvider getValidValues |
||
292 | */ |
||
293 | public function testOrElseRetrievesOptionalValueWhenValueIsPresent($value): void |
||
297 | |||
298 | /** |
||
299 | * @param mixed $value |
||
300 | * |
||
301 | * @throws ReflectionException |
||
302 | * |
||
303 | * @dataProvider getValidValues |
||
304 | */ |
||
305 | public function testOrElseGetRetrievesCallableReturnValueOnEmptyOptional($value): void |
||
316 | |||
317 | /** |
||
318 | * @param mixed $value |
||
319 | * |
||
320 | * @throws ReflectionException |
||
321 | * @throws Exception |
||
322 | * |
||
323 | * @dataProvider getValidValues |
||
324 | */ |
||
325 | public function testOrElseThrowRetrievesGivenValueWhenValueIsAvailable($value): void |
||
336 | |||
337 | /** |
||
338 | * @throws ReflectionException |
||
339 | */ |
||
340 | public function testOrElseThrowThrowsExceptionOnEmptyOptional(): void |
||
358 | |||
359 | /** |
||
360 | * @param mixed $value |
||
361 | * |
||
362 | * @throws ReflectionException |
||
363 | * |
||
364 | * @dataProvider getValidValues |
||
365 | */ |
||
366 | public function testOrElseGetRetrievesOptionalValueIfValueIsPresent($value): void |
||
377 | |||
378 | public function testInequality(): void |
||
388 | |||
389 | /** |
||
390 | * @param mixed $value |
||
391 | * |
||
392 | * @dataProvider getValidValues |
||
393 | */ |
||
394 | public function testEquals($value): void |
||
398 | |||
399 | /** |
||
400 | * @param mixed $value |
||
401 | * |
||
402 | * @dataProvider getValidValues |
||
403 | */ |
||
404 | public function testInequalityWithEmptyOptional($value): void |
||
409 | |||
410 | public function testStringCast(): void |
||
415 | |||
416 | /** |
||
417 | * Data provider: provides valid Optional values |
||
418 | * |
||
419 | * @return mixed[][] |
||
420 | * |
||
421 | * @throws ReflectionException |
||
422 | */ |
||
423 | public function getValidValues(): array |
||
436 | } |
||
437 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.