| Conditions | 3 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 35 |
| 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 |
||
| 44 | } |
||
| 45 | |||
| 46 | public function testExportMessages(): void |
||
| 47 | { |
||
| 48 | FileHelper::removeDirectory(dirname($this->getLogFilePath())); |
||
| 49 | |||
| 50 | $logFile = $this->getLogFilePath(); |
||
| 51 | $target = new FileTarget($logFile, null, 0777, 0777); |
||
| 52 | $target->setMessages([ |
||
| 53 | ['level', 'text', ['category' => 'alert', 'time' => 123]] |
||
| 54 | ]); |
||
| 55 | |||
| 56 | $target->export(); |
||
| 57 | |||
| 58 | self::assertDirectoryExists(dirname($logFile)); |
||
| 59 | self::assertFileExists($logFile); |
||
| 60 | self::assertEquals("1970-01-01 00:02:03.000000 [level][alert] text\n", file_get_contents($logFile)); |
||
| 61 | } |
||
| 62 | |||
| 63 | private function getLogFilePath(): string |
||
| 64 | { |
||
| 65 | return __DIR__ . '/runtime/log/file-target-test.log'; |
||
| 66 | } |
||
| 67 | } |
||
| 68 |