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

Parser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

3 Methods

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