From dc4980e6d99b68764e142c0a0cbf23a7cd2d078e Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Thu, 12 Sep 2019 18:19:50 +0100 Subject: [PATCH] Fixing the log checker --- .scrutinizer.yml | 2 +- .travis.yml | 6 ++---- composer.json | 1 + src/Commands/CheckCommand.php | 6 ++++-- src/Utilities/LogChecker.php | 16 ++++++++-------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 42617ac8..3c0ca63d 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -21,7 +21,7 @@ checks: tools: external_code_coverage: timeout: 600 - runs: 3 + runs: 4 php_code_sniffer: enabled: true config: diff --git a/.travis.yml b/.travis.yml index 083fec75..311b6ad1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php -sudo: false - php: - 7.1.3 - 7.1 @@ -23,5 +21,5 @@ script: - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover after_script: - - if [ "$TRAVIS_PHP_VERSION" != "7.3" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$TRAVIS_PHP_VERSION" != "7.3" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi + - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi + - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/composer.json b/composer.json index 3ac54a4d..5ca51fa4 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "license": "MIT", "require": { "php": ">=7.1.3", + "ext-json": "*", "psr/log": "~1.0", "arcanedev/support": "~4.4.0" }, diff --git a/src/Commands/CheckCommand.php b/src/Commands/CheckCommand.php index aca4acd9..21f5f389 100644 --- a/src/Commands/CheckCommand.php +++ b/src/Commands/CheckCommand.php @@ -99,7 +99,9 @@ private function displayMessages() $rows[] = [$file, $message]; } - $this->frame('LogViewer messages'); - $this->table(['File', 'Message'], $rows); + if ( ! empty($rows)) { + $this->frame('LogViewer messages'); + $this->table(['File', 'Message'], $rows); + } } } diff --git a/src/Utilities/LogChecker.php b/src/Utilities/LogChecker.php index 0d6afd2c..e82146aa 100644 --- a/src/Utilities/LogChecker.php +++ b/src/Utilities/LogChecker.php @@ -268,16 +268,17 @@ private function checkLogFile($path) $status = true; $filename = basename($path); $message = "The log file [$filename] is valid."; + $pattern = $this->filesystem->getPattern(); if ($this->isSingleLogFile($filename)) { - $this->status = $status = false; + $this->status = $status = false; $this->messages['files'][$filename] = $message = "You have a single log file in your application, you should split the [$filename] into separate log files."; } - elseif ($this->isInvalidLogDate($filename)) { - $this->status = $status = false; + elseif ($this->isInvalidLogPattern($filename, $pattern)) { + $this->status = $status = false; $this->messages['files'][$filename] = $message = - "The log file [$filename] has an invalid date, the format must be like laravel-YYYY-MM-DD.log."; + "The log file [$filename] has an invalid date, the format must be like {$pattern}."; } $this->files[$filename] = compact('filename', 'status', 'message', 'path'); @@ -299,13 +300,12 @@ private function isSingleLogFile($file) * Check the date of the log file. * * @param string $file + * @param string $pattern * * @return bool */ - private function isInvalidLogDate($file) + private function isInvalidLogPattern($file, $pattern) { - $pattern = '/laravel-(\d){4}-(\d){2}-(\d){2}.log/'; - - return ((bool) preg_match($pattern, $file, $matches)) === false; + return ((bool) preg_match("/{$pattern}/", $file, $matches)) === false; } }