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.

JobRepository::getJob()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-08-28
7
 */
8
9
10
namespace Chapi\Service\JobRepository;
11
12
use Chapi\Entity\Chronos\JobCollection;
13
use Chapi\Entity\Chronos\ChronosJobEntity;
14
use Chapi\Entity\JobEntityInterface;
15
use Chapi\Service\JobRepository\Filter\JobFilterInterface;
16
17
class JobRepository implements JobRepositoryInterface
18
{
19
20
    /**
21
     * @var JobCollection
22
     */
23
    private $jobCollection;
24
25
    /**
26
     * @var BridgeInterface
27
     */
28
    private $repositoryBridge;
29
30
    /**
31
     * @var JobFilterInterface
32
     */
33
    private $jobFilter;
34
35
    /**
36
     * @param BridgeInterface $repositoryBridge
37
     * @param JobFilterInterface $jobFilter
38
     */
39 12
    public function __construct(
40
        BridgeInterface $repositoryBridge,
41
        JobFilterInterface $jobFilter
42
    ) {
43 12
        $this->repositoryBridge = $repositoryBridge;
44 12
        $this->jobFilter = $jobFilter;
45 12
    }
46
47
    /**
48
     * @param string $jobName
49
     * @return ChronosJobEntity
50
     */
51 6
    public function getJob($jobName)
52
    {
53 6
        $jobs = $this->getJobs();
54 6
        if (isset($jobs[$jobName])) {
55 4
            return $jobs[$jobName];
56
        }
57
58 4
        return null;
59
    }
60
61
    /**
62
     * @param string $jobName
63
     * @return bool
64
     */
65 1
    public function hasJob($jobName)
66
    {
67 1
        $jobs = $this->getJobs();
68 1
        return (isset($jobs[$jobName]));
69
    }
70
71
    /**
72
     * @return \Chapi\Entity\Chronos\JobCollection
73
     */
74 9
    public function getJobs()
75
    {
76 9
        if (!is_null($this->jobCollection)) {
77 4
            return $this->jobCollection;
78
        }
79
80
        // apply filter
81 9
        $jobs = array_filter(
82 9
            $this->repositoryBridge->getJobs(),
83 9
            array($this->jobFilter, 'isInteresting')
84
        );
85
86 9
        return $this->jobCollection = new JobCollection(
87 9
            $jobs
88
        );
89
    }
90
91
    /**
92
     * @param ChronosJobEntity|JobEntityInterface $jobEntity
93
     * @return bool
94
     */
95 3
    public function addJob(JobEntityInterface $jobEntity)
96
    {
97 3
        if ($this->repositoryBridge->addJob($jobEntity)) {
98
            // if no collection inited the new job will init by chronos request
99 2
            if (!is_null($this->jobCollection)) {
100 1
                $this->jobCollection->offsetSet($jobEntity->getKey(), $jobEntity);
101
            }
102
103 2
            return true;
104
        }
105
106 1
        return false;
107
    }
108
109
    /**
110
     * @param ChronosJobEntity|JobEntityInterface $jobEntity
111
     * @return bool
112
     */
113 1
    public function updateJob(JobEntityInterface $jobEntity)
114
    {
115 1
        return $this->repositoryBridge->updateJob($jobEntity);
116
    }
117
118
    /**
119
     * @param string $jobName
120
     * @return bool
121
     */
122 3
    public function removeJob($jobName)
123
    {
124 3
        $jobEntity = $this->getJob($jobName);
125 3
        if (!$jobEntity) {
126 1
            throw new \InvalidArgumentException(sprintf('Can\'t remove unknown job "%s"', $jobName));
127
        }
128
129 2
        if ($this->repositoryBridge->removeJob($jobEntity)) {
130 1
            $this->jobCollection->offsetUnset($jobEntity->getKey());
131 1
            return true;
132
        }
133
134 1
        return false;
135
    }
136
}
137