| 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 |
||
| 43 | public function testRotate(bool $rotateByCopy): void |
||
| 44 | { |
||
| 45 | $logFile = __DIR__ . '/runtime/log/filetargettest.log'; |
||
| 46 | FileHelper::removeDirectory(dirname($logFile)); |
||
| 47 | mkdir(dirname($logFile), 0777, true); |
||
| 48 | |||
| 49 | $rotator = new FileRotator(1024, 1, null, $rotateByCopy); |
||
| 50 | $fileTarget = new FileTarget($logFile, $rotator); |
||
| 51 | |||
| 52 | $logger = new Logger([ |
||
| 53 | 'file' => $fileTarget, |
||
| 54 | ]); |
||
| 55 | |||
| 56 | // one file |
||
| 57 | |||
| 58 | $logger->log(LogLevel::WARNING, str_repeat('x', 1024)); |
||
| 59 | $logger->flush(true); |
||
| 60 | |||
| 61 | clearstatcache(); |
||
| 62 | |||
| 63 | $this->assertFileExists($logFile); |
||
| 64 | $this->assertFileNotExists($logFile . '.1'); |
||
| 65 | $this->assertFileNotExists($logFile . '.2'); |
||
| 66 | $this->assertFileNotExists($logFile . '.3'); |
||
| 67 | $this->assertFileNotExists($logFile . '.4'); |
||
| 68 | |||
| 69 | // exceed max size |
||
| 70 | for ($i = 0; $i < 1024; $i++) { |
||
| 71 | $logger->log(LogLevel::WARNING, str_repeat('x', 1024)); |
||
| 72 | } |
||
| 73 | $logger->flush(true); |
||
| 74 | |||
| 75 | // first rotate |
||
| 76 | |||
| 77 | $logger->log(LogLevel::WARNING, str_repeat('x', 1024)); |
||
| 78 | $logger->flush(true); |
||
| 79 | |||
| 80 | clearstatcache(); |
||
| 81 | |||
| 82 | $this->assertFileExists($logFile); |
||
| 83 | $this->assertFileExists($logFile . '.1'); |
||
| 84 | $this->assertFileNotExists($logFile . '.2'); |
||
| 85 | $this->assertFileNotExists($logFile . '.3'); |
||
| 86 | $this->assertFileNotExists($logFile . '.4'); |
||
| 87 | |||
| 88 | // second rotate |
||
| 89 | |||
| 90 | for ($i = 0; $i < 1024; $i++) { |
||
| 91 | $logger->log(LogLevel::WARNING, str_repeat('x', 1024)); |
||
| 92 | } |
||
| 93 | $logger->flush(true); |
||
| 94 | |||
| 95 | clearstatcache(); |
||
| 96 | |||
| 97 | $this->assertFileExists($logFile); |
||
| 98 | $this->assertFileExists($logFile . '.1'); |
||
| 99 | $this->assertFileNotExists($logFile . '.2'); |
||
| 100 | $this->assertFileNotExists($logFile . '.3'); |
||
| 101 | $this->assertFileNotExists($logFile . '.4'); |
||
| 102 | } |
||
| 104 |