Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| GitDataCollector | |
100.00% |
13 / 13 |
|
100.00% |
9 / 9 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| collect | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getLastCommitMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| reset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGitBranch | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLastCommitAuthor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLastCommitDate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSha | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\DataCollector; |
| 6 | |
| 7 | use App\Helper\GitLoader; |
| 8 | use Override; |
| 9 | use Symfony\Component\HttpFoundation\Request; |
| 10 | use Symfony\Component\HttpFoundation\Response; |
| 11 | use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
| 12 | use Throwable; |
| 13 | |
| 14 | class GitDataCollector extends DataCollector |
| 15 | { |
| 16 | public function __construct( |
| 17 | private readonly GitLoader $gitLoader |
| 18 | ) {} |
| 19 | |
| 20 | #[Override] |
| 21 | public function collect( |
| 22 | Request $request, |
| 23 | Response $response, |
| 24 | ?Throwable $exception = null |
| 25 | ): void |
| 26 | { |
| 27 | $this->data = [ |
| 28 | 'git_branch' => $this->gitLoader->getBranchName(), |
| 29 | 'last_commit_message' => $this->gitLoader->getLastCommitMessage(), |
| 30 | 'logs' => $this->gitLoader->getLastCommitDetail(), |
| 31 | ]; |
| 32 | } |
| 33 | |
| 34 | public function getLastCommitMessage(): string |
| 35 | { |
| 36 | return $this->data['last_commit_message']; |
| 37 | } |
| 38 | |
| 39 | #[Override] |
| 40 | public function getName(): string |
| 41 | { |
| 42 | return 'app.git_data_collector'; |
| 43 | } |
| 44 | |
| 45 | #[Override] |
| 46 | public function reset(): void |
| 47 | { |
| 48 | $this->data = []; |
| 49 | } |
| 50 | |
| 51 | public function getGitBranch(): string |
| 52 | { |
| 53 | return $this->data['git_branch']; |
| 54 | } |
| 55 | |
| 56 | public function getLastCommitAuthor(): string |
| 57 | { |
| 58 | return $this->data['logs']['author']; |
| 59 | } |
| 60 | |
| 61 | public function getLastCommitDate(): string |
| 62 | { |
| 63 | return $this->data['logs']['date']; |
| 64 | } |
| 65 | |
| 66 | public function getSha(): string |
| 67 | { |
| 68 | return $this->data['logs']['sha']; |
| 69 | } |
| 70 | } |