Completed
Push — master ( bc1002...bc42f8 )
by Łukasz
03:30
created

CandidateProcessor::getLastErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Processor;
4
5
use Tworzenieweb\SqlProvisioner\Check\Check;
6
use Tworzenieweb\SqlProvisioner\Model\Candidate;
7
8
/**
9
 * @author Luke Adamczewski
10
 * @package Tworzenieweb\SqlProvisioner\Processor
11
 */
12
class CandidateProcessor
13
{
14
    /** @var Check[] */
15
    private $checks;
16
17
    /** @var string */
18
    private $lastError;
19
20
    /** @var string */
21
    private $lastErrorMessage;
22
23
24
25
    public function __construct()
26
    {
27
        $this->checks = [];
28
    }
29
30
31
32
    /**
33
     * @param Check $check
34
     */
35
    public function addCheck(Check $check)
36
    {
37
        array_push($this->checks, $check);
38
    }
39
40
41
42
    /**
43
     * @param Candidate $candidate
44
     * @return bool
45
     */
46
    public function isValid(Candidate $candidate)
47
    {
48
        $this->lastError = null;
49
        foreach ($this->checks as $check) {
50
            if ($check->execute($candidate)) {
51
                $this->lastError = $check->getErrorCode();
52
                $this->lastErrorMessage = $check->getLastErrorMessage();
53
54
                return false;
55
            }
56
        }
57
58
        return true;
59
    }
60
61
62
63
    /**
64
     * @return string
65
     */
66
    public function getLastError()
67
    {
68
        return $this->lastError;
69
    }
70
71
72
73
    /**
74
     * @return string
75
     */
76
    public function getLastErrorMessage()
77
    {
78
        return $this->lastErrorMessage;
79
    }
80
}