ApplicationInformationService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 29
ccs 9
cts 12
cp 0.75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLatestVersionNumber() 0 11 2
A __construct() 0 5 1
1
<?php
2
3
namespace App\Services;
4
5
use App\Application;
6
use Exception;
7
use GuzzleHttp\Client;
8
use Illuminate\Contracts\Cache\Repository as Cache;
9
use Illuminate\Log\Logger;
10
11
class ApplicationInformationService
12
{
13
    private const CACHE_KEY = 'latestKoelVersion';
14
15
    private $client;
16
    private $cache;
17
    private $logger;
18
19 1
    public function __construct(Client $client, Cache $cache, Logger $logger)
20
    {
21 1
        $this->client = $client;
22 1
        $this->cache = $cache;
23 1
        $this->logger = $logger;
24 1
    }
25
26
    /**
27
     * Get the latest version number of Koel from GitHub.
28
     */
29 1
    public function getLatestVersionNumber(): string
30
    {
31
        return $this->cache->remember(self::CACHE_KEY, 1 * 24 * 60, function (): string {
32
            try {
33 1
                return json_decode(
34 1
                    $this->client->get('https://api.github.com/repos/phanan/koel/tags')->getBody()
35 1
                )[0]->name;
36
            } catch (Exception $e) {
37
                $this->logger->error($e);
38
39
                return Application::KOEL_VERSION;
40
            }
41 1
        });
42
    }
43
}
44