| Conditions | 10 |
| Paths | 16 |
| Total Lines | 59 |
| 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 |
||
| 186 | private function dealInvokeExpectation($method, $command, array $arguments, &$out = null, &$err = null) |
||
| 187 | { |
||
| 188 | $current = array_shift($this->expects); |
||
| 189 | $testCase = $this->testCase; |
||
| 190 | if (null === $current) { |
||
| 191 | $testCase::fail( |
||
| 192 | sprintf( |
||
| 193 | "Exec tester violation: %s() with command '%s' called with no more expectations", |
||
| 194 | $method, |
||
| 195 | $command |
||
| 196 | ) |
||
| 197 | ); |
||
| 198 | } |
||
| 199 | |||
| 200 | list ( |
||
| 201 | $expectedMethod, |
||
| 202 | $expectedCommand, |
||
| 203 | $context, |
||
| 204 | $message |
||
| 205 | ) = $current; |
||
| 206 | |||
| 207 | $testCase::assertSame( |
||
| 208 | $expectedMethod, |
||
| 209 | $method, |
||
| 210 | sprintf("Method on exec mismatch with command '%s'%s", $command, $message ? " // ${message}" : '') |
||
| 211 | ); |
||
| 212 | |||
| 213 | if ('' !== $expectedCommand && '~' === $expectedCommand[0]) { |
||
| 214 | $testCase::assertMatchesRegularExpression( |
||
| 215 | $expectedCommand, |
||
| 216 | $command, |
||
| 217 | sprintf("Command on exec mismatch with method '%s'%s", $method, $message ? " // ${message}" : '') |
||
| 218 | ); |
||
| 219 | } else { |
||
| 220 | $testCase::assertSame( |
||
| 221 | $expectedCommand, |
||
| 222 | $command, |
||
| 223 | sprintf("Command on exec mismatch with method '%s'%s", $method, $message ? " // ${message}" : '') |
||
| 224 | ); |
||
| 225 | } |
||
| 226 | |||
| 227 | if (is_int($context)) { |
||
| 228 | return $context; |
||
| 229 | } |
||
| 230 | |||
| 231 | if (is_string($context)) { |
||
| 232 | $out = $context; |
||
| 233 | |||
| 234 | return 0; |
||
| 235 | } |
||
| 236 | |||
| 237 | if (is_callable($context)) { |
||
| 238 | return call_user_func_array( |
||
| 239 | $context, |
||
| 240 | array($command, $arguments, &$out, &$err) |
||
| 241 | ); |
||
| 242 | } |
||
| 243 | |||
| 244 | throw new UnexpectedValueException('Invalid context'); |
||
| 245 | } |
||
| 247 |