Completed
Push — master ( 4ee28c...27c466 )
by Marcel
34:36 queued 25:34
created

DirectoriesHaveCorrectPermissions::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Collection;
7
use Illuminate\Filesystem\Filesystem;
8
9
class DirectoriesHaveCorrectPermissions implements Check
10
{
11
    /** @var Filesystem */
12
    private $filesystem;
13
14
    /** @var Collection */
15
    private $paths;
16
17
    /**
18
     * DirectoriesHaveCorrectPermissions constructor.
19
     * @param Filesystem $filesystem
20
     */
21 4
    public function __construct(Filesystem $filesystem)
22
    {
23 4
        $this->filesystem = $filesystem;
24 4
    }
25
26
    /**
27
     * The name of the check.
28
     *
29
     * @param array $config
30
     * @return string
31
     */
32
    public function name(array $config): string
33
    {
34
        return trans('self-diagnosis::checks.directories_have_correct_permissions.name');
35
    }
36
37
    /**
38
     * The error message to display in case the check does not pass.
39
     *
40
     * @param array $config
41
     * @return string
42
     */
43
    public function message(array $config): string
44
    {
45
        return trans('self-diagnosis::checks.directories_have_correct_permissions.message', [
46
            'directories' => $this->paths->implode(PHP_EOL),
47
        ]);
48
    }
49
50
    /**
51
     * Perform the actual verification of this check.
52
     *
53
     * @param array $config
54
     * @return bool
55
     */
56 4
    public function check(array $config): bool
57
    {
58 4
        $this->paths = Collection::make(Arr::get($config, 'directories', []));
59
60
        $this->paths = $this->paths->reject(function ($path) {
61 4
            return $this->filesystem->isWritable($path);
62 4
        });
63
64 4
        return $this->paths->isEmpty();
65
    }
66
}
67