Completed
Pull Request — master (#59)
by David
01:28
created

LogFilesDontExist::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Collection;
7
8
class LogFilesDontExist implements Check
9
{
10
    /** @var Collection */
11
    protected $ignoreFiles;
12
13
    /** @var Collection */
14
    protected $logFiles;
15
16
    /**
17
     * The name of the check.
18
     *
19
     * @param array $config
20
     * @return string
21
     */
22
    public function name(array $config): string
23
    {
24
        return trans('self-diagnosis::checks.log_files_dont_exist.name');
25
    }
26
27
    /**
28
     * Perform the actual verification of this check.
29
     *
30
     * @param array $config
31
     * @return bool
32
     */
33
    public function check(array $config): bool
34
    {
35
        $this->ignoreFiles = new Collection(array_get($config, 'ignore_files', []));
36
        
37
        $logHandlers = Collection::make(app('log')->driver()->getLogger()->getHandlers());
38
        $fileInfo = pathinfo($logHandlers->first()->getUrl());
39
        $globPattern = Str::finish($fileInfo['dirname'], '/*.' . $fileInfo['extension']);
40
        $this->logFiles = Collection::make(glob($globPattern))->reject(function ($file) {
41
            return Str::is($this->ignoreFiles->toArray(), pathinfo($file, PATHINFO_BASENAME));
42
        });
43
44
        return $this->logFiles->isEmpty();
45
    }
46
47
    /**
48
     * The error message to display in case the check does not pass.
49
     *
50
     * @param array $config
51
     * @return string
52
     */
53
    public function message(array $config): string
54
    {
55
        return trans('self-diagnosis::checks.log_files_dont_exist.message', [
56
            'files' => $this->logFiles->implode(PHP_EOL)
57
        ]);
58
    }
59
}
60