Completed
Push — master ( 07d9db...140b29 )
by Sebastian
05:12
created

Check::runCheck()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 4
crap 6
1
<?php
2
namespace phpbu\App\Runner;
3
4
use phpbu\App\Backup\Check as CheckExe;
5
use phpbu\App\Backup\Check\Exception;
6
use phpbu\App\Backup\Collector;
7
use phpbu\App\Backup\Target;
8
use phpbu\App\Configuration\Backup\Check as CheckConfig;
9
use phpbu\App\Result;
10
11
/**
12
 * Check Runner class.
13
 *
14
 * @package    phpbu
15
 * @subpackage App
16
 * @author     Sebastian Feldmann <[email protected]>
17
 * @copyright  Sebastian Feldmann <[email protected]>
18
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
19
 * @link       http://phpbu.de/
20
 * @since      Class available since Release 3.0.0
21
 */
22
class Check extends Abstraction
23
{
24
    /**
25
     * Failure state of all executed Checks.
26
     *
27
     * @var boolean
28
     */
29
    private $failure = false;
30
31
    /**
32
     * Executes a backup check.
33
     *
34
     * @param \phpbu\App\Backup\Check               $check
35
     * @param \phpbu\App\Configuration\Backup\Check $config
36
     * @param \phpbu\App\Backup\Target              $target
37
     * @param \phpbu\App\Backup\Collector           $collector
38
     * @param \phpbu\App\Result                     $result
39
     */
40 3
    public function run(CheckExe $check, CheckConfig $config, Target $target, Collector $collector, Result $result)
41
    {
42
        try {
43 3
            $result->checkStart($config);
44
45 3
            if ($this->runCheck($check, $config->value, $target, $collector)) {
46 1
                $result->checkEnd($config);
47 1
            } else {
48 1
                $this->failure = true;
49 1
                $result->checkFailed($config);
50
            }
51 3
        } catch (Exception $e) {
52 1
            $this->failure = true;
53 1
            $result->addError($e);
54 1
            $result->checkFailed($config);
55
        }
56 3
    }
57
58
    /**
59
     * Return true if the last check did fail.
60
     *
61
     * @return boolean
62
     */
63 3
    public function hasFailed()
64
    {
65 3
        return $this->failure;
66
    }
67
68
    /**
69
     * Executes the actual check.
70
     *
71
     * @param  \phpbu\App\Backup\Check     $check
72
     * @param  string                      $value
73
     * @param  \phpbu\App\Backup\Target    $target
74
     * @param  \phpbu\App\Backup\Collector $collector
75
     * @return bool
76
     */
77
    protected function runCheck(CheckExe $check, $value, Target $target, Collector $collector)
78
    {
79
        return $this->isSimulation() ? true : $check->pass($target, $value, $collector);
80
    }
81
}
82