diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000..adacd73 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,21 @@ +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + +name: rector + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.0'] diff --git a/CHANGELOG.md b/CHANGELOG.md index b94f53e..fa1a893 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.2 under development -- Enh: Add composer require checker into CI +- no changes in this release. ## 2.0.1 July 25, 2022 diff --git a/composer.json b/composer.json index 23a1c39..918b302 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "require-dev": { "maglnet/composer-require-checker": "^4.2", "phpunit/phpunit": "^9.5", + "rector/rector": "^0.15.1", "roave/infection-static-analysis-plugin": "^1.25", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^4.30|^5.2", diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..63713ce --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, + ]); +}; diff --git a/src/FileRotator.php b/src/FileRotator.php index 44dd6e9..c2692ee 100644 --- a/src/FileRotator.php +++ b/src/FileRotator.php @@ -54,13 +54,6 @@ final class FileRotator implements FileRotatorInterface */ private int $maxFiles; - /** - * @var int|null The permission to be set for newly created files. - * This value will be used by PHP chmod() function. No umask will be applied. - * If not set, the permission will be determined by the current environment. - */ - private ?int $fileMode; - /** * @var bool Whether to compress rotated files with gzip. Defaults to `false`. * @@ -69,15 +62,17 @@ final class FileRotator implements FileRotatorInterface private bool $compressRotatedFiles; /** - * @param int $maxFileSize The maximum file size, in kilo-bytes. Defaults to 10240, meaning 10MB. + * @param int $maxFileSize The maximum file size, in kilobytes. Defaults to 10240, meaning 10MB. * @param int $maxFiles The number of files used for rotation. Defaults to 5. - * @param int|null $fileMode The permission to be set for newly created files. + * @param int|null $fileMode The permission to be set for newly created files. This value will be used by PHP + * `chmod()` function. No umask will be applied. If not set, the permission will be determined by the current + * environment. * @param bool $compressRotatedFiles Whether to compress rotated files with gzip. */ public function __construct( int $maxFileSize = 10240, int $maxFiles = 5, - int $fileMode = null, + private ?int $fileMode = null, bool $compressRotatedFiles = false ) { $this->checkCannotBeLowerThanOne($maxFileSize, '$maxFileSize'); @@ -85,7 +80,6 @@ public function __construct( $this->maxFileSize = $maxFileSize; $this->maxFiles = $maxFiles; - $this->fileMode = $fileMode; if ($compressRotatedFiles && !extension_loaded('zlib')) { throw new RuntimeException(sprintf( @@ -154,8 +148,6 @@ private function rotate(string $rotateFile, string $newFile): void /** * Compresses a file with gzip and renames it by appending `.gz` to the file. - * - * @param string $file */ private function compress(string $file): void { @@ -191,8 +183,6 @@ private function clear(string $file): void /** * Checks the existence of file and removes it. - * - * @param string $file */ private function safeRemove(string $file): void { @@ -203,10 +193,6 @@ private function safeRemove(string $file): void /** * Whether the file is compressed. - * - * @param string $file - * - * @return bool */ private function isCompressed(string $file): bool { diff --git a/src/FileTarget.php b/src/FileTarget.php index defdd29..7378fa0 100644 --- a/src/FileTarget.php +++ b/src/FileTarget.php @@ -38,44 +38,22 @@ final class FileTarget extends Target { /** - * @var string The log file path. If not set, it will use the "/tmp/app.log" file. - * The directory containing the log files will be automatically created if not existing. - */ - private string $logFile; - - /** - * @var int The permission to be set for newly created directories. - * This value will be used by PHP chmod() function. No umask will be applied. - * Defaults to 0775, meaning the directory is read-writable by owner and group, - * but read-only for other users. - */ - private int $dirMode; - - /** - * @var int|null The permission to be set for newly created log files. - * This value will be used by PHP chmod() function. No umask will be applied. - * If not set, the permission will be determined by the current environment. - */ - private ?int $fileMode; - - private ?FileRotatorInterface $rotator; - - /** - * @param string $logFile The log file path. If not set, it will use the "/tmp/app.log" file. + * @param string $logFile The log file path. If not set, it will use the "/tmp/app.log" file. The directory + * containing the log files will be automatically created if not existing. * @param FileRotatorInterface|null $rotator The instance that takes care of rotating files. - * @param int $dirMode The permission to be set for newly created directories. - * @param int|null $fileMode The permission to be set for newly created log files. + * @param int $dirMode The permission to be set for newly created directories. This value will be used by PHP + * `chmod()` function. No umask will be applied. Defaults to 0775, meaning the directory is read-writable by owner + * and group, but read-only for other users. + * @param int|null $fileMode The permission to be set for newly created log files. This value will be used by PHP + * `chmod()` function. No umask will be applied. If not set, the permission will be determined by the current + * environment. */ public function __construct( - string $logFile = '/tmp/app.log', - FileRotatorInterface $rotator = null, - int $dirMode = 0775, - int $fileMode = null + private string $logFile = '/tmp/app.log', + private ?FileRotatorInterface $rotator = null, + private int $dirMode = 0775, + private ?int $fileMode = null ) { - $this->logFile = $logFile; - $this->rotator = $rotator; - $this->dirMode = $dirMode; - $this->fileMode = $fileMode; parent::__construct(); } diff --git a/tests/FileRotatorTest.php b/tests/FileRotatorTest.php index 3e20917..91b83d6 100644 --- a/tests/FileRotatorTest.php +++ b/tests/FileRotatorTest.php @@ -42,8 +42,6 @@ public function rotateDataProvider(): array /** * @dataProvider rotateDataProvider - * - * @param bool $compress */ public function testRotate(bool $compress): void { @@ -75,8 +73,6 @@ public function testRotate(bool $compress): void /** * @dataProvider rotateDataProvider - * - * @param bool $compress */ public function testRotateMaxFiles(bool $compress): void { @@ -108,8 +104,6 @@ public function testRotateMaxFiles(bool $compress): void /** * @dataProvider rotateDataProvider - * - * @param bool $compress */ public function testRotateMaxFileSize(bool $compress): void { diff --git a/tests/FileTargetTest.php b/tests/FileTargetTest.php index c2d2713..fe6f418 100644 --- a/tests/FileTargetTest.php +++ b/tests/FileTargetTest.php @@ -56,9 +56,9 @@ public function testExportMessagesWithSetFormat(): void { $logFile = $this->getLogFilePath(); $target = new FileTarget($logFile, null, 0777, 0777); - $target->setFormat(function (Message $message) { - return "[{$message->level()}][{$message->context('category')}] {$message->message()}"; - }); + $target->setFormat( + fn (Message $message) => "[{$message->level()}][{$message->context('category')}] {$message->message()}" + ); $target->collect( [ new Message(LogLevel::INFO, 'text-1', ['category' => 'category-1']),