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

HasSyntaxCorrectCheck   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 2
dl 57
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A execute() 13 13 2
A getLastErrorMessage() 4 4 1
A getErrorCode() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}