Passed
Pull Request — master (#226)
by Fabien
01:59
created

ResultsParser::parseCommits()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php declare(strict_types = 1);
2
3
4
namespace Churn\Results;
5
6
use Illuminate\Support\Collection;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Collection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class ResultsParser
9
{
10
    /**
11
     * Collection of results.
12
     * @var ResultCollection
13
     */
14
    private $resultsCollection;
15
16
    /**
17
     * Turns a collection of completed processes into a
18
     * collection of parsed result objects.
19
     * @param Collection $completedProcesses Collection of completed processes.
20
     * @return ResultCollection
21
     */
22
    public function parse(Collection $completedProcesses): ResultCollection
23
    {
24
        $this->resultsCollection = new ResultCollection;
25
26
        foreach ($completedProcesses as $file => $processes) {
27
            $this->parseCompletedProcessesForFile($file, $processes);
28
        }
29
30
        return $this->resultsCollection;
31
    }
32
33
    /**
34
     * Parse the list of processes for a file.
35
     * @param string $file      The file the processes were executed on.
36
     * @param array  $processes The processes that were executed on the file.
37
     * @return void
38
     */
39
    private function parseCompletedProcessesForFile(string $file, array $processes): void
40
    {
41
        $commits = (integer) $processes['GitCommitProcess']->getOutput();
42
        $complexity = (integer) $processes['CyclomaticComplexityProcess']->getOutput();
43
44
        $result = new Result([
45
            'file' => $file,
46
            'commits' => $commits,
47
            'complexity' => $complexity,
48
        ]);
49
50
        $this->resultsCollection->push($result);
51
    }
52
}
53