| Conditions | 5 |
| Paths | 12 |
| Total Lines | 62 |
| 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 declare(strict_types=1); |
||
| 89 | public function testCanCheckIfVersionComponentIsInDefaultOrNullState( |
||
| 90 | string $expected, |
||
| 91 | VersionComponent $versionComponent |
||
| 92 | ) : void { |
||
| 93 | static $format = '$versionComponent->{method}(); // {actual}'; |
||
| 94 | |||
| 95 | $actuals['isDefault'] = $versionComponent->isDefault(); |
||
|
|
|||
| 96 | $actuals['isNotDefault'] = $versionComponent->isNotDefault(); |
||
| 97 | $actuals['isNull'] = $versionComponent->isNull(); |
||
| 98 | $actuals['isNotNull'] = $versionComponent->isNotNull(); |
||
| 99 | |||
| 100 | $messages = []; |
||
| 101 | |||
| 102 | foreach ($actuals as $method => $actual) { |
||
| 103 | $messages[$method] = Text::format($format, ['method' => $method, 'actual' => static::export($actual)]); |
||
| 104 | } |
||
| 105 | |||
| 106 | foreach ($actuals as $method => $actual) { |
||
| 107 | // Pre-tests for returning type |
||
| 108 | $this->assertInternalType('boolean', $actual, $messages[$method].' # Should return a boolean #'); |
||
| 109 | } |
||
| 110 | |||
| 111 | // Pre-tests for different values |
||
| 112 | $this->assertNotEquals( |
||
| 113 | $actuals['isDefault'], |
||
| 114 | $actuals['isNotDefault'], |
||
| 115 | $messages['isDefault'].PHP_EOL.$messages['isNotDefault'] |
||
| 116 | ); |
||
| 117 | |||
| 118 | $this->assertNotEquals( |
||
| 119 | $actuals['isNull'], |
||
| 120 | $actuals['isNotNull'], |
||
| 121 | $messages['isNull'].PHP_EOL.$messages['isNotNull'] |
||
| 122 | ); |
||
| 123 | |||
| 124 | |||
| 125 | // Test expected |
||
| 126 | if ($expected === 'default') { |
||
| 127 | $this->assertTrue($actuals['isDefault'], $messages['isDefault']); |
||
| 128 | |||
| 129 | // Can't be null AND default |
||
| 130 | $this->assertNotEquals( |
||
| 131 | $actuals['isNull'], |
||
| 132 | $actuals['isDefault'], |
||
| 133 | '#Can\'t be both, DEFAULT and NULL, at the same time'.PHP_EOL. |
||
| 134 | $messages['isDefault'].PHP_EOL. |
||
| 135 | $messages['isNull'] |
||
| 136 | ); |
||
| 137 | } elseif ($expected === 'null') { |
||
| 138 | $this->assertTrue($actuals['isNull'], $messages['isNull']); |
||
| 139 | |||
| 140 | // Can't be null AND default |
||
| 141 | $this->assertNotEquals( |
||
| 142 | $actuals['isNull'], |
||
| 143 | $actuals['isDefault'], |
||
| 144 | '#Can\'t be both, NULL and DEFAULT, at the same time'.PHP_EOL. |
||
| 145 | $messages['isNull'].PHP_EOL. |
||
| 146 | $messages['isDefault'] |
||
| 147 | ); |
||
| 148 | } else { |
||
| 149 | $this->assertTrue($actuals['isNotDefault'], $messages['isNotDefault']); |
||
| 150 | $this->assertTrue($actuals['isNotNull'], $messages['isNotNull']); |
||
| 151 | } |
||
| 154 |