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)) { |
|
|
|
|
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) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
return $this->isSimulation() ? true : $check->pass($target, $value, $collector); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
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.