Parser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Database;
4
5
use Symfony\Component\Process\Process;
6
use Tworzenieweb\SqlProvisioner\Model\Candidate;
7
8
/**
9
 * @author Luke Adamczewski
10
 * @package Tworzenieweb\SqlProvisioner\Database
11
 */
12
class Parser
13
{
14
    const PROCESS_TIMEOUT = 120;
15
    const PROCESS_COMMAND = 'vendor/bin/php-sqllint -r emacs -';
16
17
    /** @var string */
18
    private $rootPath;
19
20
21
22
    /**
23
     * @param string $rootPath
24
     */
25 2
    public function __construct($rootPath)
26
    {
27 2
        $this->rootPath = $rootPath;
28 2
    }
29
30
31
32
    /**
33
     * @param Candidate $candidate
34
     * @return array
35
     */
36 1
    public function execute(Candidate $candidate)
37
    {
38 1
        $process = new Process(
39 1
            self::PROCESS_COMMAND,
40 1
            realpath($this->rootPath),
41 1
            null,
42 1
            $candidate->getContent(),
43
            self::PROCESS_TIMEOUT
44 1
        );
45 1
        $process->run();
46
47
        // remove extra header
48 1
        $parsingResult = explode("\n", $process->getOutput());
49 1
        array_shift($parsingResult);
50
51 1
        return implode("\n", $parsingResult);
52
    }
53
}
54