Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ShaFinder
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
5
 getSha
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Service;
6
7use Symfony\Component\DependencyInjection\Attribute\Autowire;
8
9class ShaFinder
10{
11    private string $sha = 'n/a';
12
13    public function __construct(#[Autowire('%kernel.project_dir%')] string $rootDir)
14    {
15        if (file_exists($rootDir.'/sha.txt')) {
16            $this->sha = file_get_contents($rootDir.'/sha.txt') ?: 'n/a';
17        } elseif (file_exists($rootDir.'/.git/refs/heads/master')) {
18            $this->sha = file_get_contents($rootDir.'/.git/refs/heads/master')
19                ?: 'n/a';
20        }
21    }
22
23    public function getSha(): string
24    {
25        return $this->sha;
26    }
27}