Conditions | 2 |
Paths | 2 |
Total Lines | 67 |
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 |
||
30 | public function providerHas() |
||
31 | { |
||
32 | $defaultPreconditions = [ |
||
33 | 'document' => [ |
||
34 | 'foo' => [ |
||
35 | 'bar' => 'baz' |
||
36 | ] |
||
37 | ] |
||
38 | ]; |
||
39 | $defaultExpectations = []; |
||
40 | |||
41 | $testCases = [ |
||
42 | '1-element subpath of existing 2-element-path' => [ |
||
43 | 'preconditions' => [ |
||
44 | 'path' => 'foo' |
||
45 | ], |
||
46 | 'expectations' => [ |
||
47 | 'has' => true |
||
48 | ] |
||
49 | ], |
||
50 | 'Existing, two-element path' => [ |
||
51 | 'preconditions' => [ |
||
52 | 'path' => 'foo.bar' |
||
53 | ], |
||
54 | 'expectations' => [ |
||
55 | 'has' => true |
||
56 | ] |
||
57 | ], |
||
58 | 'Non-existing, two-element path' => [ |
||
59 | 'preconditions' => [ |
||
60 | 'path' => 'foo.baz' |
||
61 | ], |
||
62 | 'expectations' => [ |
||
63 | 'has' => false |
||
64 | ] |
||
65 | ], |
||
66 | 'Non-existing 3-element-path in a document only containing 2-element-paths' => [ |
||
67 | 'preconditions' => [ |
||
68 | 'path' => 'foo.bar.baz' |
||
69 | ], |
||
70 | 'expectations' => [ |
||
71 | 'has' => false |
||
72 | ] |
||
73 | ], |
||
74 | 'Non-existing 3-element-path in a document only containing 2-element-paths with an empty array' => [ |
||
75 | 'preconditions' => [ |
||
76 | 'document' => [ |
||
77 | 'foo' => [ |
||
78 | 'bar' => [] |
||
79 | ] |
||
80 | ], |
||
81 | 'path' => 'foo.bar.baz' |
||
82 | ], |
||
83 | 'expectations' => [ |
||
84 | 'has' => false |
||
85 | ] |
||
86 | ], |
||
87 | ]; |
||
88 | |||
89 | // Merge test data with default data |
||
90 | foreach ($testCases as &$testCase) { |
||
91 | $testCase['preconditions'] = array_merge($defaultPreconditions, $testCase['preconditions']); |
||
92 | $testCase['expectations'] = array_merge($defaultExpectations, $testCase['expectations']); |
||
93 | } |
||
94 | |||
95 | return $testCases; |
||
96 | } |
||
97 | |||
110 |