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

systemsdk / docker-symfony-api / #83

pending completion
#83

push

DKravtsov
Updated composer dependencies, refactoring.

45 of 45 new or added lines in 12 files covered. (100.0%)

1483 of 2844 relevant lines covered (52.14%)

22.41 hits per line

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

84.62
/src/Tool/Application/Service/VersionService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Tool\Application\Service;
6

7
use App\General\Domain\Utils\JSON;
8
use Closure;
9
use Psr\Log\LoggerInterface;
10
use Symfony\Contracts\Cache\CacheInterface;
11
use Symfony\Contracts\Cache\ItemInterface;
12
use Throwable;
13

14
use function array_key_exists;
15
use function assert;
16
use function is_array;
17
use function is_string;
18

19
/**
20
 * Class VersionService
21
 *
22
 * @package App\Tool
23
 */
24
class VersionService
25
{
26
    public function __construct(
27
        private readonly string $projectDir,
28
        private readonly CacheInterface $appCache,
29
        private readonly LoggerInterface $logger,
30
    ) {
31
    }
148✔
32

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

41
        try {
42
            $output = (string)$this->appCache->get('application_version', $this->getClosure());
148✔
43
        } catch (Throwable $exception) {
×
44
            $this->logger->error($exception->getMessage(), $exception->getTrace());
×
45
        }
46

47
        return $output;
148✔
48
    }
49

50
    private function getClosure(): Closure
51
    {
52
        return function (ItemInterface $item): string {
148✔
53
            // One year
54
            $item->expiresAfter(31536000);
1✔
55
            $composerData = JSON::decode((string)file_get_contents($this->projectDir . '/composer.json'), true);
1✔
56
            assert(is_array($composerData));
57

58
            return array_key_exists('version', $composerData) && is_string($composerData['version'])
1✔
59
                ? $composerData['version']
1✔
60
                : '0.0.0';
1✔
61
        };
148✔
62
    }
63
}
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

© 2025 Coveralls, Inc