Parser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 42
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 17 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