FindChangeHunkStartState   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 41
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A processDiffStart() 0 5 1
A finish() 0 3 1
A __construct() 0 3 1
A processLine() 0 11 3
A processChangeHunkStart() 0 3 1
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
final class FindChangeHunkStartState implements State
21
{
22
    /**
23
     * FindChangeHunkStartState constructor.
24
     */
25
    public function __construct(
26
        private FileMutationBuilder $fileMutationBuilder,
27
    ) {
28
    }
29
30
    public function processLine(string $line): State
31
    {
32
        if (LineTypeDetector::isStartOfFileDiff($line)) {
33
            return $this->processDiffStart();
34
        }
35
36
        if (LineTypeDetector::isStartOfChangeHunk($line)) {
37
            return $this->processChangeHunkStart($line);
38
        }
39
40
        return $this;
41
    }
42
43
    private function processDiffStart(): State
44
    {
45
        $fileMutationsBuilder = $this->fileMutationBuilder->build();
46
47
        return new FindOriginalFileNameState($fileMutationsBuilder);
48
    }
49
50
    /**
51
     * @throws DiffParseException
52
     */
53
    private function processChangeHunkStart(string $line): State
54
    {
55
        return new ChangeHunkParserState($this->fileMutationBuilder, $line);
56
    }
57
58
    public function finish(): void
59
    {
60
        $this->fileMutationBuilder->build();
61
    }
62
}
63