| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 19 | public function testDefaultConfigHasMessageFormats(): void |
||
| 20 | { |
||
| 21 | $config = Config::getDefault(); |
||
| 22 | |||
| 23 | $messageFormats = $config->getMessageFormats(); |
||
| 24 | |||
| 25 | $expectedMessageFormats = [ |
||
| 26 | Camt052\MessageFormat\V01::class, |
||
| 27 | Camt052\MessageFormat\V02::class, |
||
| 28 | Camt052\MessageFormat\V04::class, |
||
| 29 | Camt052\MessageFormat\V06::class, |
||
| 30 | Camt053\MessageFormat\V02::class, |
||
| 31 | Camt053\MessageFormat\V03::class, |
||
| 32 | Camt053\MessageFormat\V04::class, |
||
| 33 | Camt054\MessageFormat\V02::class, |
||
| 34 | Camt054\MessageFormat\V04::class, |
||
| 35 | ]; |
||
| 36 | |||
| 37 | $actualMessageFormats = array_map(static function (MessageFormatInterface $messageFormat): string { |
||
| 38 | return get_class($messageFormat); |
||
| 39 | }, $messageFormats); |
||
| 40 | |||
| 41 | $additionalMessageFormats = array_diff( |
||
| 42 | $actualMessageFormats, |
||
| 43 | $expectedMessageFormats |
||
| 44 | ); |
||
| 45 | |||
| 46 | self::assertEmpty($additionalMessageFormats, sprintf( |
||
| 47 | <<<TXT |
||
| 48 | Failed asserting that the default configuration does not configure additional message formats. |
||
| 49 | |||
| 50 | Did you intend to add the following message formats? |
||
| 51 | |||
| 52 | - %s |
||
| 53 | |||
| 54 | TXT |
||
| 55 | , |
||
| 56 | implode("\n- ", $additionalMessageFormats) |
||
| 57 | )); |
||
| 58 | |||
| 59 | $missingMessageFormats = array_diff( |
||
| 60 | $expectedMessageFormats, |
||
| 61 | $actualMessageFormats |
||
| 62 | ); |
||
| 63 | |||
| 64 | self::assertEmpty($missingMessageFormats, sprintf( |
||
| 65 | <<<TXT |
||
| 66 | Failed asserting that the default configuration configures all expected formats. |
||
| 67 | |||
| 68 | Have you forgotten to add the following message formats? |
||
| 69 | |||
| 70 | - %s |
||
| 71 | |||
| 72 | TXT |
||
| 73 | , |
||
| 74 | implode("\n- ", $missingMessageFormats) |
||
| 75 | )); |
||
| 93 |