Skip to content

Commit

Permalink
Merge pull request #286 from ARCANEDEV/patch-4
Browse files Browse the repository at this point in the history
[4.5] Fixing the log checker
  • Loading branch information
arcanedev-maroc authored Sep 12, 2019
2 parents f7348ea + 1763b1e commit a462a7a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: php

sudo: false

php:
- 7.1.3
- 7.1
- 7.2
- 7.3
- nightly

matrix:
Expand Down
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.3.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);
}
}
}
16 changes: 8 additions & 8 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 = '/laravel-(\d){4}-(\d){2}-(\d){2}.log/';

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

0 comments on commit a462a7a

Please sign in to comment.