Completed
Push — master ( 456549...47da6e )
by Łukasz
02:25
created

HasSyntaxCorrectCheckInterface::__construct()   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 1
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Check;
4
5
use Tworzenieweb\SqlProvisioner\Database\Parser;
6
use Tworzenieweb\SqlProvisioner\Model\Candidate;
7
8
/**
9
 * @author Luke Adamczewski
10
 * @package Tworzenieweb\SqlProvisioner\Check
11
 */
12
class HasSyntaxCorrectCheckInterface implements CheckInterface
13
{
14
    const ERROR_STATUS = 'PARSER_ERROR';
15
16
    /** @var Parser */
17
    private $parser;
18
19
    /** @var string */
20
    private $lastError;
21
22
23
24
    /**
25
     * @param Parser $parser
26
     */
27
    public function __construct(Parser $parser)
28
    {
29
        $this->parser = $parser;
30
    }
31
32
33
34
    /**
35
     * @param Candidate $candidate
36
     * @return bool True / False based on the fact if check is met or not
37
     */
38
    public function execute(Candidate $candidate)
39
    {
40
        $this->lastError = null;
41
        $parsingResult = $this->parser->execute($candidate);
42
43
        if (!empty($parsingResult)) {
44
            $this->lastError = sprintf("Syntax error during processing of %s:\n%s", $candidate->getName(), $parsingResult);
45
46
            return true;
47
        }
48
49
        return false;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getLastErrorMessage()
56
    {
57
        return $this->lastError;
58
    }
59
60
61
    /**
62
     * @return string
63
     */
64
    public function getErrorCode()
65
    {
66
        return self::ERROR_STATUS;
67
    }
68
}