Skip to content

Commit

Permalink
Merge pull request #284 from ARCANEDEV/patch-2
Browse files Browse the repository at this point in the history
[4.7] Fixing the log checker
  • Loading branch information
arcanedev-maroc authored Sep 12, 2019
2 parents a373c51 + 9f50aa6 commit bb7bbce
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
runs: 4
php_code_sniffer:
enabled: true
config:
Expand Down
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

php:
- 7.1.3
- 7.1
Expand All @@ -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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": "MIT",
"require": {
"php": ">=7.1.3",
"ext-json": "*",
"psr/log": "~1.0",
"arcanedev/support": "~4.5.0"
},
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
14 changes: 7 additions & 7 deletions src/Utilities/LogChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 = $this->filesystem->getPattern();

return ((bool) preg_match("/{$pattern}/", $file, $matches)) === false;
}
}

0 comments on commit bb7bbce

Please sign in to comment.