• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarlepp / symfony-flex-backend / #6272

12 Jul 2026 07:50PM UTC coverage: 99.68% (-0.2%) from 99.876%
#6272

Pull #3336

php-coveralls

web-flow
Merge 764e37d64 into db63c2324
Pull Request #3336: Chore(deps) - Dependency update

2490 of 2498 relevant lines covered (99.68%)

87.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/Service/Version.php
1
<?php
2
declare(strict_types = 1);
3

4
/**
5
 * /src/Service/Version.php
6
 */
7

8
namespace App\Service;
9

10
use App\Utils\JSON;
11
use Closure;
12
use Psr\Log\LoggerInterface;
13
use Symfony\Component\DependencyInjection\Attribute\Autowire;
14
use Symfony\Contracts\Cache\CacheInterface;
15
use Symfony\Contracts\Cache\ItemInterface;
16
use Throwable;
17
use function array_key_exists;
18
use function assert;
19
use function is_array;
20
use function is_string;
21

22
class Version
23
{
24
    public function __construct(
25
        #[Autowire('%kernel.project_dir%')]
26
        private readonly string $projectDir,
27
        private readonly CacheInterface $appCacheApcu,
28
        private readonly LoggerInterface $logger
29
    ) {
30
    }
598✔
31

32
    /**
33
     * Method to get application version from cache or create new entry to
34
     * cache with version value from composer.json file.
35
     */
36
    public function get(): string
37
    {
38
        $output = '0.0.0';
598✔
39

40
        try {
41
            $output = $this->appCacheApcu->get('application_version', $this->getClosure());
598✔
42
        } catch (Throwable $exception) {
1✔
43
            $this->logger->error($exception->getMessage(), $exception->getTrace());
1✔
44
        }
45

46
        return $output;
598✔
47
    }
48

49
    /**
50
     * @return Closure(ItemInterface, bool): string
51
     */
52
    private function getClosure(): Closure
53
    {
54
        return function (ItemInterface $item, bool $isHit): string {
598✔
55
            // One year
56
            $item->expiresAfter(31_536_000);
596✔
57

58
            $composerData = JSON::decode((string)file_get_contents($this->projectDir . '/composer.json'), true);
596✔
59

60
            assert(is_array($composerData));
×
61

62
            return array_key_exists('version', $composerData) && is_string($composerData['version'])
596✔
63
                ? $composerData['version']
596✔
64
                : '0.0.0';
596✔
65
        };
598✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc