Completed
Push — master ( 72f544...07d9db )
by Sebastian
06:33
created

Check   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 61
wmc 6
lcom 1
cbo 4
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasFailed() 0 4 1
A run() 0 17 3
A check() 0 4 2
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->check($check, $config->value, $target, $collector, $result)) {
0 ignored issues
show
Unused Code introduced by
The call to Check::check() has too many arguments starting with $result.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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 check(CheckExe $check, $value, Target $target, Collector $collector)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
78
    {
79
        return $this->isSimulation() ? true : $check->pass($target, $value, $collector);
80
    }
81
82
}
83