Base::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace Health\Checks\File;
3
4
use Health\Checks\BaseCheck;
5
6
abstract class Base extends BaseCheck
7
{
8
9
    /**
10
     * List of files
11
     *
12
     * @var array
13
     */
14
    protected $files = [];
15
16
    /**
17
     *
18
     * @param array $params
19
     */
20
    public function __construct(array $params = [])
21
    {
22
        parent::__construct($params);
23
24
        $this->files = $this->getParam('files', []);
25
    }
26
27
    /**
28
     *
29
     * {@inheritdoc}
30
     * @see \Health\Checks\HealthCheckInterface::call()
31
     */
32
    public function call()
33
    {
34
        $builder = $this->getBuilder();
35
36
        $errors = [];
37
38
        foreach ($this->files as $file) {
39
            if (! is_file($file) || ! $this->isValid($file)) {
40
                $errors[] = $file;
41
            }
42
        }
43
44
        if ($errors) {
45
            $builder->down()->withData('errors', $errors);
46
        }
47
48
        return $builder->withData('files', $this->files)->build();
49
    }
50
51
    /**
52
     *
53
     * @param string $file
54
     * @return boolean
55
     */
56
    abstract protected function isValid($file);
57
}
58