Conditions | 3 |
Paths | 3 |
Total Lines | 52 |
Code Lines | 35 |
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 |
||
55 | public function assertResourceCollectionEqualsCollectionFailedProvider() |
||
56 | { |
||
57 | $expected = new Collection(); |
||
58 | $collection = []; |
||
59 | for ($i = 1; $i < 3; $i++) { |
||
60 | $attributes = [ |
||
61 | 'TST_ID' => 10 + $i, |
||
62 | 'TST_NAME' => 'test' . $i, |
||
63 | 'TST_NUMBER' => 1000 * $i + 123, |
||
64 | 'TST_CREATION_DATE' => null |
||
65 | ]; |
||
66 | |||
67 | $model = new ModelForTest(); |
||
68 | $model->setRawAttributes($attributes); |
||
69 | $expected->push($model); |
||
70 | |||
71 | $resource = [ |
||
72 | 'type' => $model->getResourceType(), |
||
73 | 'id' => $model->getKey(), |
||
74 | 'attributes' => $attributes |
||
75 | ]; |
||
76 | |||
77 | if ($i == 2) { |
||
78 | $resource['attributes']['TST_NAME'] = 'wrong'; |
||
79 | } |
||
80 | array_push($collection, $resource); |
||
81 | } |
||
82 | |||
83 | $resourceType = $model->getResourceType(); |
||
84 | |||
85 | return [ |
||
86 | 'collection is not an array of objects' => [ |
||
87 | $expected, |
||
88 | $resourceType, |
||
89 | [ |
||
90 | 'key' => 'not an array ofg objects' |
||
91 | ], |
||
92 | Messages::MUST_BE_ARRAY_OF_OBJECTS |
||
93 | ], |
||
94 | 'not the same counts' => [ |
||
95 | $expected, |
||
96 | $resourceType, |
||
97 | [ |
||
98 | $collection[0] |
||
99 | ], |
||
100 | null |
||
101 | ], |
||
102 | 'collections are not equal' => [ |
||
103 | $expected, |
||
104 | $resourceType, |
||
105 | $collection, |
||
106 | null |
||
107 | ] |
||
136 |