LintStage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 27 4
1
<?php
2
3
namespace JoaoRobertoPB\PhpGitHookSniffer\Pipelines;
4
5
use JoaoRobertoPB\PhpGitHookSniffer\Contracts\PipelineInterface;
6
7
class LintStage implements PipelineInterface
8
{
9
    /**
10
     * Process the payload.
11
     *
12
     * @param mixed $payload
13
     */
14
    public function __invoke($payload)
15
    {
16
        echo "[  ] ----- Check Syntax Error -----\n";
17
18
        foreach ($payload as $file) {
19
            $fileName = trim($file);
20
            $ext = pathinfo($fileName, PATHINFO_EXTENSION);
21
22
            $return = 0;
23
24
            if ('php' != $ext) {
25
                continue;
26
            }
27
28
            $lintOutput = [];
29
            exec('php -l '.escapeshellarg($fileName), $lintOutput, $return);
30
        }
31
32
        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 18. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
33
            echo implode("\n", $lintOutput), "\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $lintOutput does not seem to be defined for all execution paths leading up to this point.
Loading history...
34
            echo "[FAIL] ----- Check Syntax Error -----\n";
35
            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...
36
        }
37
38
        echo "[OK] ----- Check Syntax Error -----\n";
39
40
        return $payload;
41
    }
42
}
43