JsonLintProcessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 6 1
A execute() 0 14 1
A setErrors() 0 6 2
1
<?php
2
3
namespace PhpGitHooks\Module\JsonLint\Infrastructure\Tool;
4
5
use PhpGitHooks\Infrastructure\Tool\ToolPathFinder;
6
use PhpGitHooks\Module\JsonLint\Model\JsonLintProcessorInterface;
7
use Symfony\Component\Process\Process;
8
9
class JsonLintProcessor implements JsonLintProcessorInterface
10
{
11
    /**
12
     * @var ToolPathFinder
13
     */
14
    private $toolPathFinder;
15
16
    /**
17
     * JsonLintProcessor constructor.
18
     *
19
     * @param ToolPathFinder $toolPathFinder
20
     */
21
    public function __construct(ToolPathFinder $toolPathFinder)
22
    {
23
        $this->toolPathFinder = $toolPathFinder;
24
    }
25
26
    /**
27
     * @param string $file
28
     *
29
     * @return string
30
     */
31
    public function process($file)
32
    {
33
        $process = $this->execute($file);
34
35
        return $this->setErrors($process);
36
    }
37
38
    /**
39
     * @param string $file
40
     *
41
     * @return Process
42
     */
43
    private function execute($file)
44
    {
45
        $process = new Process(
46
            [
47
                'php',
48
                $this->toolPathFinder->find('jsonlint'),
49
                $file,
50
            ]
51
        );
52
53
        $process->run();
54
55
        return $process;
56
    }
57
58
    /**
59
     * @param Process $process
60
     *
61
     * @return string
62
     */
63
    private function setErrors(Process $process)
64
    {
65
        if (false === $process->isSuccessful()) {
66
            return $process->getErrorOutput();
67
        }
68
    }
69
}
70