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.

JobDependencyService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-09-10
7
 *
8
 * @link:    https://github.com/msiebeneicher/chapi/issues/24
9
 */
10
11
namespace Chapi\Service\JobDependencies;
12
13
use Chapi\Entity\Chronos\ChronosJobEntity;
14
use Chapi\Service\JobRepository\JobRepositoryInterface;
15
16
class JobDependencyService implements JobDependencyServiceInterface
17
{
18
    /**
19
     * @var JobRepositoryInterface
20
     */
21
    private $jobRepositoryLocal;
22
23
    /**
24
     * @var JobRepositoryInterface
25
     */
26
    private $jobRepositoryChronos;
27
28
    /**
29
     * @var array
30
     */
31
    private $jobTreeLocal = [];
32
33
    /**
34
     * @var array
35
     */
36
    private $jobTreeChronos = [];
37
38
    /**
39
     * @param JobRepositoryInterface $jobRepositoryLocal
40
     * @param JobRepositoryInterface $jobRepositoryChronos
41
     */
42 3
    public function __construct(
43
        JobRepositoryInterface $jobRepositoryLocal,
44
        JobRepositoryInterface $jobRepositoryChronos
45
    ) {
46 3
        $this->jobRepositoryLocal = $jobRepositoryLocal;
47 3
        $this->jobRepositoryChronos = $jobRepositoryChronos;
48 3
    }
49
50
    /**
51
     * @param string $jobName
52
     * @param int $repository
53
     * @return string[]
54
     */
55 2
    public function getChildJobs($jobName, $repository)
56
    {
57 2
        $jobTree = ($repository == self::REPOSITORY_LOCAL) ? $this->getJobTreeLocal() : $this->getJobTreeChronos();
58 2
        return (isset($jobTree[$jobName])) ? $jobTree[$jobName] : [];
59
    }
60
61
    /**
62
     * @param string $jobName
63
     * @param int $repository
64
     * @return bool
65
     */
66 2
    public function hasChildJobs($jobName, $repository)
67
    {
68 2
        $_aJobs = $this->getChildJobs($jobName, $repository);
69 2
        return (!empty($_aJobs));
70
    }
71
72
    /**
73
     * @return array
74
     */
75 1
    private function getJobTreeLocal()
76
    {
77 1
        if (empty($this->jobTreeLocal)) {
78 1
            $this->initJobTree($this->jobTreeLocal, $this->jobRepositoryLocal);
79
        }
80
81 1
        return $this->jobTreeLocal;
82
    }
83
84
    /**
85
     * @return array
86
     */
87 1
    private function getJobTreeChronos()
88
    {
89 1
        if (empty($this->jobTreeChronos)) {
90 1
            $this->initJobTree($this->jobTreeChronos, $this->jobRepositoryChronos);
91
        }
92
93 1
        return $this->jobTreeChronos;
94
    }
95
96
    /**
97
     * @param array $jobTree
98
     * @param JobRepositoryInterface $jobRepository
99
     * @return void
100
     */
101 2
    private function initJobTree(&$jobTree, JobRepositoryInterface $jobRepository)
102
    {
103
        // reset job tree in case of reloading
104 2
        $jobTree = [];
105
106
        /** @var ChronosJobEntity $jobEntity */
107 2
        foreach ($jobRepository->getJobs() as $jobEntity) {
108 2
            if ($jobEntity->isDependencyJob()) {
109 2
                foreach ($jobEntity->parents as $parentJobName) {
110
                    // init parent in tree
111 2
                    if (!isset($jobTree[$parentJobName])) {
112 2
                        $jobTree[$parentJobName] = [];
113
                    }
114
                    // set job as children to parent
115 2
                    $jobTree[$parentJobName][] = $jobEntity->name;
116
                }
117
            }
118
        }
119 2
    }
120
}
121