Completed
Push — master ( 1709bd...87026b )
by Łukasz
04:39 queued 02:13
created

HasSyntaxCorrectCheck::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 4
rs 10
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 View Code Duplication
class HasSyntaxCorrectCheck implements CheckInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
}