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

FindRenameToState::processLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
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
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\NewFileName;
16
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\StringUtils;
17
18
/**
19
 * Previous line in diff was renaming a file from Original Name. This is looking for the New Name.
20
 */
21
class FindRenameToState implements State
22
{
23
    const RENAME_TO = 'rename to ';
24
25
    /**
26
     * @var FileMutationBuilder
27
     */
28
    private $fileMutationBuilder;
29
30
    /**
31
     * FindRenameToState constructor.
32
     */
33
    public function __construct(FileMutationBuilder $fileMutationBuilder)
34
    {
35
        $this->fileMutationBuilder = $fileMutationBuilder;
36
    }
37
38
    public function processLine(string $line): State
39
    {
40
        if (!StringUtils::startsWith(self::RENAME_TO, $line)) {
41
            throw DiffParseException::missingRenameTo($line);
42
        }
43
44
        $newFileName = StringUtils::removeFromStart(self::RENAME_TO, $line);
45
        $this->fileMutationBuilder->setNewFileName(new NewFileName($newFileName));
46
47
        return new FindChangeHunkStartState($this->fileMutationBuilder);
48
    }
49
50
    public function finish(): void
51
    {
52
        throw DiffParseException::missingRenameTo('<EOF>');
53
    }
54
}
55