Conditions | 5 |
Paths | 12 |
Total Lines | 60 |
Code Lines | 37 |
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 |
||
117 | public function testCanCheckIfVersionComponentIsInDefaultOrNullState($expected, VersionComponent $versionComponent) |
||
1 ignored issue
–
show
|
|||
118 | { |
||
119 | static $format = '$versionComponent->{method}(); // {actual}'; |
||
120 | |||
121 | $actuals['isDefault'] = $versionComponent->isDefault(); |
||
122 | $actuals['isNotDefault'] = $versionComponent->isNotDefault(); |
||
123 | $actuals['isNull'] = $versionComponent->isNull(); |
||
124 | $actuals['isNotNull'] = $versionComponent->isNotNull(); |
||
125 | |||
126 | $messages = []; |
||
127 | |||
128 | foreach ($actuals as $method => $actual) { |
||
129 | $messages[$method] = Text::format($format, ['method' => $method, 'actual' => static::export($actual)]); |
||
1 ignored issue
–
show
|
|||
130 | } |
||
131 | |||
132 | foreach ($actuals as $method => $actual) { |
||
133 | // Pre-tests for returning type |
||
134 | $this->assertInternalType('boolean', $actual, $messages[$method].' # Should return a boolean #'); |
||
1 ignored issue
–
show
|
|||
135 | } |
||
136 | |||
137 | // Pre-tests for different values |
||
138 | $this->assertNotEquals( |
||
139 | $actuals['isDefault'], |
||
140 | $actuals['isNotDefault'], |
||
141 | $messages['isDefault'].PHP_EOL.$messages['isNotDefault'] |
||
142 | ); |
||
143 | |||
144 | $this->assertNotEquals( |
||
145 | $actuals['isNull'], |
||
146 | $actuals['isNotNull'], |
||
147 | $messages['isNull'].PHP_EOL.$messages['isNotNull'] |
||
148 | ); |
||
149 | |||
150 | |||
151 | // Test expected |
||
152 | if ($expected === 'default') { |
||
153 | $this->assertTrue($actuals['isDefault'], $messages['isDefault']); |
||
154 | |||
155 | // Can't be null AND default |
||
156 | $this->assertNotEquals( |
||
157 | $actuals['isNull'], |
||
158 | $actuals['isDefault'], |
||
159 | '#Can\'t be both, DEFAULT and NULL, at the same time'.PHP_EOL. |
||
160 | $messages['isDefault'].PHP_EOL. |
||
161 | $messages['isNull'] |
||
162 | ); |
||
163 | } elseif ($expected === 'null') { |
||
164 | $this->assertTrue($actuals['isNull'], $messages['isNull']); |
||
165 | |||
166 | // Can't be null AND default |
||
167 | $this->assertNotEquals( |
||
168 | $actuals['isNull'], |
||
169 | $actuals['isDefault'], |
||
170 | '#Can\'t be both, NULL and DEFAULT, at the same time'.PHP_EOL. |
||
171 | $messages['isNull'].PHP_EOL. |
||
172 | $messages['isDefault'] |
||
173 | ); |
||
174 | } else { |
||
175 | $this->assertTrue($actuals['isNotDefault'], $messages['isNotDefault']); |
||
176 | $this->assertTrue($actuals['isNotNull'], $messages['isNotNull']); |
||
177 | } |
||
180 |