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::getJobStats()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 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