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

tarlepp / symfony-flex-backend / #6193

14 May 2026 11:44AM UTC coverage: 99.875% (-0.1%) from 100.0%
#6193

push

php-coveralls

web-flow
Merge pull request #3273 from tarlepp/chore(deps)/dependency-update

Chore(deps) - Dependency update

2392 of 2395 relevant lines covered (99.87%)

88.27 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
 * /src/Service/Version.php
5
 *
6
 * @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
7
 */
8

9
namespace App\Service;
10

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

23
/**
24
 * @package App\Service
25
 * @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
26
 */
27
class Version
28
{
29
    public function __construct(
30
        #[Autowire('%kernel.project_dir%')]
31
        private readonly string $projectDir,
32
        private readonly CacheInterface $appCacheApcu,
33
        private readonly LoggerInterface $logger
34
    ) {
35
    }
598✔
36

37
    /**
38
     * Method to get application version from cache or create new entry to
39
     * cache with version value from composer.json file.
40
     */
41
    public function get(): string
42
    {
43
        $output = '0.0.0';
598✔
44

45
        try {
46
            $output = (string)$this->appCacheApcu->get('application_version', $this->getClosure());
598✔
47
        } catch (Throwable $exception) {
1✔
48
            $this->logger->error($exception->getMessage(), $exception->getTrace());
1✔
49
        }
50

51
        return $output;
598✔
52
    }
53

54
    private function getClosure(): Closure
55
    {
56
        return function (ItemInterface $item): string {
598✔
57
            // One year
58
            $item->expiresAfter(31_536_000);
596✔
59

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

62
            assert(is_array($composerData));
×
63

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

© 2026 Coveralls, Inc