Completed
Push — master ( d401ab...1f0fb6 )
by Łukasz
02:47
created

Parser::getCommandString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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