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