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.

JobIndexService   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 0
loc 124
ccs 35
cts 35
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __destruct() 0 4 1
A addJob() 0 5 1
A addJobs() 0 8 2
A removeJob() 0 8 2
A removeJobs() 0 8 2
A resetJobIndex() 0 5 1
A getJobIndex() 0 4 1
A isJobInIndex() 0 4 1
A getJobIndexFromStorage() 0 5 2
A setJobIndexToStorage() 0 4 1
1
<?php
2
/**
3
 * @package: Chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-07-31
7
 *
8
 */
9
10
11
namespace Chapi\Service\JobIndex;
12
13
use Chapi\Component\Cache\CacheInterface;
14
15
class JobIndexService implements JobIndexServiceInterface
16
{
17
    const JOB_INDEX_CACHE_KEY = 'job.index';
18
19
    /**
20
     * @var CacheInterface
21
     */
22
    private $cache;
23
24
    /**
25
     * @var array
26
     */
27
    private $jobIndex = [];
28
29
    /**
30
     * @param CacheInterface $cache
31
     */
32 7
    public function __construct(
33
        CacheInterface $cache
34
    ) {
35 7
        $this->cache = $cache;
36 7
        $this->jobIndex = $this->getJobIndexFromStorage();
37 7
    }
38
39
    /**
40
     *
41
     */
42 7
    public function __destruct()
43
    {
44 7
        $this->setJobIndexToStorage();
45 7
    }
46
47
    /**
48
     * @param string $jobName
49
     * @return $this
50
     */
51 2
    public function addJob($jobName)
52
    {
53 2
        $this->jobIndex[$jobName] = $jobName;
54 2
        return $this;
55
    }
56
57
    /**
58
     * @param array $jobNames
59
     * @return $this
60
     */
61 1
    public function addJobs(array $jobNames)
62
    {
63 1
        foreach ($jobNames as $jobName) {
64 1
            $this->addJob($jobName);
65
        }
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * @param string $jobName
72
     * @return $this
73
     */
74 2
    public function removeJob($jobName)
75
    {
76 2
        if (isset($this->jobIndex[$jobName])) {
77 2
            unset($this->jobIndex[$jobName]);
78
        }
79
80 2
        return $this;
81
    }
82
83
    /**
84
     * @param array $jobNames
85
     * @return $this
86
     */
87 1
    public function removeJobs(array $jobNames)
88
    {
89 1
        foreach ($jobNames as $jobName) {
90 1
            $this->removeJob($jobName);
91
        }
92
93 1
        return $this;
94
    }
95
96
    /**
97
     * @return $this
98
     */
99 1
    public function resetJobIndex()
100
    {
101 1
        $this->jobIndex = [];
102 1
        return $this;
103
    }
104
105
    /**
106
     * @return array
107
     */
108 1
    public function getJobIndex()
109
    {
110 1
        return $this->jobIndex;
111
    }
112
113
    /**
114
     * @param $jobName
115
     * @return bool
116
     */
117 1
    public function isJobInIndex($jobName)
118
    {
119 1
        return (isset($this->jobIndex[$jobName]));
120
    }
121
122
    /**
123
     * @return array
124
     */
125 7
    private function getJobIndexFromStorage()
126
    {
127 7
        $jobIndex = $this->cache->get(self::JOB_INDEX_CACHE_KEY);
128 7
        return (is_array($jobIndex)) ? $jobIndex : [];
129
    }
130
131
    /**
132
     *
133
     */
134 7
    private function setJobIndexToStorage()
135
    {
136 7
        $this->cache->set(self::JOB_INDEX_CACHE_KEY, $this->jobIndex);
137 7
    }
138
}
139