PhpLintToolProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 6 1
A execute() 0 14 1
A setErrors() 0 4 2
1
<?php
2
3
namespace PhpGitHooks\Module\PhpLint\Infrastructure\Tool;
4
5
use PhpGitHooks\Module\PhpLint\Model\PhpLintToolProcessorInterface;
6
use Symfony\Component\Process\Process;
7
8
class PhpLintToolProcessor implements PhpLintToolProcessorInterface
9
{
10
    /**
11
     * @param string $file
12
     *
13
     * @return string
14
     */
15
    public function process($file)
16
    {
17
        $process = $this->execute($file);
18
19
        return $this->setErrors($process);
20
    }
21
22
    /**
23
     * @param string $file
24
     *
25
     * @return Process
26
     */
27
    private function execute($file)
28
    {
29
        $process = new Process(
30
            [
31
                'php',
32
                '-l',
33
                $file,
34
            ]
35
        );
36
37
        $process->run();
38
39
        return $process;
40
    }
41
42
    /**
43
     * @param Process $process
44
     *
45
     * @return null|string
46
     */
47
    private function setErrors(Process $process)
48
    {
49
        return false === $process->isSuccessful() ? $process->getErrorOutput() : null;
50
    }
51
}
52