Total Complexity | 6 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
20 | abstract class GitObject implements \Stringable |
||
21 | { |
||
22 | protected ?string $hash; |
||
23 | protected Repository $repository; |
||
24 | |||
25 | public function __construct(Repository $repository, string $commitHash) |
||
26 | { |
||
27 | $this->repository = $repository; |
||
28 | $this->hash = $commitHash; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Returns the SHA1 hash of the commit. |
||
33 | */ |
||
34 | public function __toString(): string |
||
35 | { |
||
36 | $hash = $this->hash; |
||
37 | |||
38 | if (empty($hash) || !\preg_match('/^[0-9a-f]{40}$/', $hash)) { |
||
39 | throw new \InvalidArgumentException(\sprintf('Invalid commit hash%s', empty($hash) ? '. Empty hash provided' : " \"$hash\"")); |
||
40 | } |
||
41 | |||
42 | return $hash; |
||
43 | } |
||
44 | |||
45 | public function getRepository(): Repository |
||
48 | } |
||
49 | } |
||
50 |