| @@ 12-68 (lines=57) @@ | ||
| 9 | * @author Luke Adamczewski |
|
| 10 | * @package Tworzenieweb\SqlProvisioner\Check |
|
| 11 | */ |
|
| 12 | class HasSyntaxCorrectCheck 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 | } |
|
| @@ 12-68 (lines=57) @@ | ||
| 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 | } |
|