Conditions | 2 |
Paths | 2 |
Total Lines | 67 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
9 | public function providerHas() |
||
10 | { |
||
11 | $defaultPreconditions = [ |
||
12 | 'document' => [ |
||
13 | 'foo' => [ |
||
14 | 'bar' => 'baz' |
||
15 | ] |
||
16 | ] |
||
17 | ]; |
||
18 | $defaultExpectations = []; |
||
19 | |||
20 | $testCases = [ |
||
21 | '1-element subpath of existing 2-element-path' => [ |
||
22 | 'preconditions' => [ |
||
23 | 'path' => 'foo' |
||
24 | ], |
||
25 | 'expectations' => [ |
||
26 | 'has' => true |
||
27 | ] |
||
28 | ], |
||
29 | 'Existing, two-element path' => [ |
||
30 | 'preconditions' => [ |
||
31 | 'path' => 'foo.bar' |
||
32 | ], |
||
33 | 'expectations' => [ |
||
34 | 'has' => true |
||
35 | ] |
||
36 | ], |
||
37 | 'Non-existing, two-element path' => [ |
||
38 | 'preconditions' => [ |
||
39 | 'path' => 'foo.baz' |
||
40 | ], |
||
41 | 'expectations' => [ |
||
42 | 'has' => false |
||
43 | ] |
||
44 | ], |
||
45 | 'Non-existing 3-element-path in a document only containing 2-element-paths' => [ |
||
46 | 'preconditions' => [ |
||
47 | 'path' => 'foo.bar.baz' |
||
48 | ], |
||
49 | 'expectations' => [ |
||
50 | 'has' => false |
||
51 | ] |
||
52 | ], |
||
53 | 'Non-existing 3-element-path in a document only containing 2-element-paths with an empty array' => [ |
||
54 | 'preconditions' => [ |
||
55 | 'document' => [ |
||
56 | 'foo' => [ |
||
57 | 'bar' => [] |
||
58 | ] |
||
59 | ], |
||
60 | 'path' => 'foo.bar.baz' |
||
61 | ], |
||
62 | 'expectations' => [ |
||
63 | 'has' => false |
||
64 | ] |
||
65 | ], |
||
66 | ]; |
||
67 | |||
68 | // Merge test data with default data |
||
69 | foreach ($testCases as &$testCase) { |
||
70 | $testCase['preconditions'] = array_merge($defaultPreconditions, $testCase['preconditions']); |
||
71 | $testCase['expectations'] = array_merge($defaultExpectations, $testCase['expectations']); |
||
72 | } |
||
73 | |||
74 | return $testCases; |
||
75 | } |
||
76 | |||
89 |