CsFixerStage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 28 4
1
<?php
2
3
namespace JoaoRobertoPB\PhpGitHookSniffer\Pipelines;
4
5
use JoaoRobertoPB\PhpGitHookSniffer\Contracts\PipelineInterface;
6
7
class CsFixerStage implements PipelineInterface
8
{
9
    /**
10
     * Runs php -l on PHP staged files.
11
     *
12
     *
13
     * @return void
14
     */
15
    public function __invoke($payload)
16
    {
17
        echo "[  ] ----- Fix Code Standards -----\n";
18
19
        foreach ($payload as $file) {
20
            $fileName = trim($file);
21
            $ext = pathinfo($fileName, PATHINFO_EXTENSION);
22
23
            $return = 0;
24
25
            if ('php' != $ext) {
26
                continue;
27
            }
28
29
            $csOutput = [];
30
            exec(__DIR__.'/../../../../../vendor/bin/php-cs-fixer --using-cache=no fix '.escapeshellarg($fileName), $csOutput, $return);
31
            exec("git add {$fileName}");
32
        }
33
34
        if ($return != 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $return seems to be defined by a foreach iteration on line 19. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
35
            echo implode("\n", $csOutput), "\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $csOutput does not seem to be defined for all execution paths leading up to this point.
Loading history...
36
            echo "[FAIL] ----- Fix Code Standards -----\n";
37
            exit(1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
38
        }
39
40
        echo "[OK] ----- Fix Code Standards -----\n";
41
42
        return $payload;
43
    }
44
}
45