| Conditions | 5 |
| Paths | 12 |
| Total Lines | 62 |
| Code Lines | 38 |
| 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 |
||
| 118 | public function testCanCheckIfVersionComponentIsInDefaultOrNullState($expected, VersionComponent $versionComponent) |
||
| 119 | { |
||
| 120 | static $format = '$versionComponent->{method}(); // {actual}'; |
||
| 121 | |||
| 122 | $actuals['isDefault'] = $versionComponent->isDefault(); |
||
| 123 | $actuals['isNotDefault'] = $versionComponent->isNotDefault(); |
||
| 124 | $actuals['isNull'] = $versionComponent->isNull(); |
||
| 125 | $actuals['isNotNull'] = $versionComponent->isNotNull(); |
||
| 126 | |||
| 127 | $messages = []; |
||
| 128 | |||
| 129 | foreach ($actuals as $method => $actual) { |
||
| 130 | $messages[$method] = String::format($format, ['method' => $method, 'actual' => static::export($actual)]); |
||
| 131 | } |
||
| 132 | |||
| 133 | foreach ($actuals as $method => $actual) { |
||
| 134 | // Pre-tests for returning type |
||
| 135 | $this->assertInternalType('boolean', $actual, $messages[$method].' # Should return a boolean #'); |
||
| 136 | } |
||
| 137 | |||
| 138 | // Pre-tests for different values |
||
| 139 | $this->assertNotEquals( |
||
| 140 | $actuals['isDefault'], |
||
| 141 | $actuals['isNotDefault'], |
||
| 142 | $messages['isDefault'].PHP_EOL.$messages['isNotDefault'] |
||
| 143 | ); |
||
| 144 | |||
| 145 | $this->assertNotEquals( |
||
| 146 | $actuals['isNull'], |
||
| 147 | $actuals['isNotNull'], |
||
| 148 | $messages['isNull'].PHP_EOL.$messages['isNotNull'] |
||
| 149 | ); |
||
| 150 | |||
| 151 | |||
| 152 | // Test expected |
||
| 153 | if ($expected === 'default') { |
||
| 154 | $this->assertTrue($actuals['isDefault'], $messages['isDefault']); |
||
| 155 | |||
| 156 | // Can't be null AND default |
||
| 157 | $this->assertNotEquals( |
||
| 158 | $actuals['isNull'], |
||
| 159 | $actuals['isDefault'], |
||
| 160 | '#Can\'t be both, DEFAULT and NULL, at the same time'.PHP_EOL. |
||
| 161 | $messages['isDefault'].PHP_EOL. |
||
| 162 | $messages['isNull'] |
||
| 163 | ); |
||
| 164 | } elseif ($expected === 'null') { |
||
| 165 | $this->assertTrue($actuals['isNull'], $messages['isNull']); |
||
| 166 | |||
| 167 | // Can't be null AND default |
||
| 168 | $this->assertNotEquals( |
||
| 169 | $actuals['isNull'], |
||
| 170 | $actuals['isDefault'], |
||
| 171 | '#Can\'t be both, NULL and DEFAULT, at the same time'.PHP_EOL. |
||
| 172 | $messages['isNull'].PHP_EOL. |
||
| 173 | $messages['isDefault'] |
||
| 174 | ); |
||
| 175 | } else { |
||
| 176 | $this->assertTrue($actuals['isNotDefault'], $messages['isNotDefault']); |
||
| 177 | $this->assertTrue($actuals['isNotNull'], $messages['isNotNull']); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.