GitCommit   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A asString() 0 3 1
A validateGitSha() 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\Plugins\GitDiffHistoryAnalyser;
14
15
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryMarker;
16
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\InvalidHistoryMarkerException;
17
18
final class GitCommit implements HistoryMarker
19
{
20
    /**
21
     * @var string
22
     */
23
    private $gitSha;
24
25
    /**
26
     * @throws InvalidHistoryMarkerException
27
     */
28
    public function __construct(string $gitSha)
29
    {
30
        if (!self::validateGitSha($gitSha)) {
31
            throw InvalidHistoryMarkerException::invalidHistoryMarker("Invalid git SHA [$gitSha]");
32
        }
33
        $this->gitSha = $gitSha;
34
    }
35
36
    public function asString(): string
37
    {
38
        return $this->gitSha;
39
    }
40
41
    /**
42
     * Validates the string provided could be a valid git SHA.
43
     */
44
    public static function validateGitSha(string $gitSha): bool
45
    {
46
        return 1 === preg_match('/^[0-9a-f]{40}$/', $gitSha);
47
    }
48
}
49