Completed
Push — master ( bc1002...bc42f8 )
by Łukasz
03:30
created

Parser::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
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
16
17
    /**
18
     * @param string $composerBinPath
19
     */
20
    public function __construct($composerBinPath)
21
    {
22
        $this->composerBinPath = $composerBinPath;
0 ignored issues
show
Bug introduced by
The property composerBinPath does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
    }
24
25
26
27
    /**
28
     * @param Candidate $candidate
29
     * @return array
30
     */
31
    public function execute(Candidate $candidate)
32
    {
33
        $input = new InputStream();
34
        $input->write($candidate->getContent());
35
36
        $process = new Process($this->getCommandString());
37
        $process->setInput($input);
38
        $process->start();
39
40
        $input->close();
41
        $process->wait();
42
43
        // remove extra header
44
        $parsingResult = explode("\n", $process->getOutput());
45
        array_shift($parsingResult);
46
47
        return implode("\n", $parsingResult);
48
    }
49
50
51
52
    /**
53
     * @return string
54
     */
55
    private function getCommandString()
56
    {
57
        return sprintf('%s/php-sqllint -', realpath($this->composerBinPath));
58
    }
59
}