GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

JobStatsService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 49
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getJobStats() 0 16 3
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-09-09
7
 *
8
 * @link:    https://github.com/msiebeneicher/chapi/issues/24
9
 */
10
11
namespace Chapi\Service\Chronos;
12
13
use Chapi\Component\Cache\CacheInterface;
14
use Chapi\Component\RemoteClients\ApiClientInterface;
15
use Chapi\Entity\Chronos\JobStatsEntity;
16
17
class JobStatsService implements JobStatsServiceInterface
18
{
19
    const CACHE_TIME_JOB_STATS = 900;
20
21
    const CACHE_KEY_JOB_STATS = 'jobs.stats.%s';
22
23
    /**
24
     * @var \Chapi\Component\RemoteClients\ApiClientInterface
25
     */
26
    private $apiClient;
27
28
    /**
29
     * @var CacheInterface
30
     */
31
    private $cache;
32
33
    /**
34
     * @param \Chapi\Component\RemoteClients\ApiClientInterface $apiClient
35
     * @param CacheInterface $cache
36
     */
37 4
    public function __construct(
38
        \Chapi\Component\RemoteClients\ApiClientInterface $apiClient,
39
        CacheInterface $cache
40
    ) {
41 4
        $this->apiClient = $apiClient;
42 4
        $this->cache = $cache;
43 4
    }
44
45
    /**
46
     * @param $jobName
47
     * @return JobStatsEntity
48
     */
49 3
    public function getJobStats($jobName)
50
    {
51 3
        $cacheKey = sprintf(self::CACHE_KEY_JOB_STATS, $jobName);
52 3
        $stats = $this->cache->get($cacheKey);
53
54 3
        if (empty($stats)) {
55 2
            $stats = $this->apiClient->getJobStats($jobName);
56
57
            // set result to cache
58 2
            if (!empty($stats)) {
59 1
                $this->cache->set($cacheKey, $stats, self::CACHE_TIME_JOB_STATS);
60
            }
61
        }
62
63 3
        return new JobStatsEntity($stats);
64
    }
65
}
66