Passed
Pull Request — master (#69)
by Dave
02:21
created

FindChangeHunkStartState::processDiffStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Static Analysis Results Baseliner (sarb).
5
 *
6
 * (c) Dave Liddament
7
 *
8
 * For the full copyright and licence information please view the LICENSE file distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal;
14
15
/**
16
 * Looks for:
17
 * - start of a new Change Hunk
18
 * - start of a new File Diff.
19
 */
20
class FindChangeHunkStartState implements State
21
{
22
    /**
23
     * @var FileMutationBuilder
24
     */
25
    private $fileMutationBuilder;
26
27
    /**
28
     * FindChangeHunkStartState constructor.
29
     */
30
    public function __construct(FileMutationBuilder $fileMutationBuilder)
31
    {
32
        $this->fileMutationBuilder = $fileMutationBuilder;
33
    }
34
35
    public function processLine(string $line): State
36
    {
37
        if (LineTypeDetector::isStartOfFileDiff($line)) {
38
            return $this->processDiffStart();
39
        }
40
41
        if (LineTypeDetector::isStartOfChangeHunk($line)) {
42
            return $this->processChangeHunkStart($line);
43
        }
44
45
        return $this;
46
    }
47
48
    private function processDiffStart(): State
49
    {
50
        $fileMutationsBuilder = $this->fileMutationBuilder->build();
51
52
        return new FindOriginalFileNameState($fileMutationsBuilder);
53
    }
54
55
    private function processChangeHunkStart(string $line): State
56
    {
57
        return new ChangeHunkParserState($this->fileMutationBuilder, $line);
58
    }
59
60
    public function finish(): void
61
    {
62
        $this->fileMutationBuilder->build();
63
    }
64
}
65