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.
Completed
Pull Request — master (#68)
by Bidesh
03:32
created

getLocalMissingJobs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 3
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author: bthapaliya
6
 * @since: 2017-01-18
7
 *
8
 */
9
10
namespace Chapi\BusinessCase\Comparison;
11
12
use Chapi\Component\Comparison\DiffCompareInterface;
13
use Chapi\Component\DatePeriod\DatePeriodFactoryInterface;
14
use Chapi\Entity\Chronos\JobCollection;
15
use Chapi\Entity\Chronos\ChronosJobEntity;
16
use Chapi\Entity\JobEntityInterface;
17
use Chapi\Service\JobRepository\JobRepositoryInterface;
18
use Psr\Log\LoggerInterface;
19
use Symfony\Component\Config\Definition\Exception\Exception;
20
21
class CompositeJobComparisonBusinessCase implements JobComparisonInterface
22
{
23
    /** @var JobComparisonInterface[] */
24
    private $aComposites = [];
25
26 4
    public function addComparisonCases(JobComparisonInterface $comparer)
27
    {
28 4
        $this->aComposites[] = $comparer;
29 4
    }
30
31
    /**
32
     * @return array
33
     */
34 1
    public function getLocalMissingJobs()
35
    {
36 1
        $_aMissingJobs = array();
37 1
        foreach($this->aComposites as $jobComparers)
38
        {
39 1
            $missing = $jobComparers->getLocalMissingJobs();
40 1
            $_aMissingJobs = array_merge($_aMissingJobs,  $missing);
41 1
        }
42 1
        return $_aMissingJobs;
43
    }
44
45
    /**
46
     * @return array
47
     */
48 1
    public function getRemoteMissingJobs()
49
    {
50 1
        $_aChronosMissingJobs = array();
51 1
        foreach($this->aComposites as $jobComparers)
52
        {
53 1
            $_aChronosMissingJobs = array_merge($_aChronosMissingJobs, $jobComparers->getRemoteMissingJobs());
54 1
        }
55 1
        return $_aChronosMissingJobs;
56
    }
57
58
    /**
59
     * @return array
60
     */
61 1
    public function getLocalJobUpdates()
62
    {
63 1
        $_aLocalJobUpdates = array();
64 1
        foreach($this->aComposites as $jobComparers)
65
        {
66 1
            $_aLocalJobUpdates = array_merge($_aLocalJobUpdates, $jobComparers->getLocalJobUpdates());
67 1
        }
68 1
        return $_aLocalJobUpdates;
69
    }
70
71
    /**
72
     * @param string $sJobName
73
     * @return array
74
     */
75 1
    public function getJobDiff($sJobName)
76
    {
77 1
        $_aJobDiffs = array();
78 1
        foreach($this->aComposites as $jobComparers)
79
        {
80
            // assuming same name won't be in all subsystems.
81
            // TODO: add support to handle the duplicate names in different subsystems
82 1
            if ($jobComparers->isJobAvailable($sJobName))
83 1
            {
84 1
                $_aJobDiffs = $jobComparers->getJobDiff($sJobName);
85 1
                break;
86
            }
87 1
        }
88 1
        return $_aJobDiffs;
89
    }
90
91
    /**
92
     * @param JobEntityInterface|ChronosJobEntity $oJobEntityA
93
     * @param JobEntityInterface|ChronosJobEntity $oJobEntityB
94
     * @return bool
95
     */
96
    public function hasSameJobType(JobEntityInterface $oJobEntityA, JobEntityInterface $oJobEntityB)
97
    {
98
        if ($oJobEntityA->getEntityType() != $oJobEntityB->getEntityType())
99
        {
100
            throw new Exception('type compared for different entity types.');
101
        }
102
        /** @var JobComparisonInterface $comparer */
103
        $comparer = null;
104
        foreach($this->aComposites as $child)
105
        {
106
            if ($child->isJobAvailable($oJobEntityA->getKey()))
107
            {
108
                $comparer = $child;
109
                break;
110
            }
111
        }
112
113
        if ($comparer == null)
114
        {
115
            throw new Exception(sprintf('could not find appropriate comparision businesscase to operate', $oJobEntityA->getKey()));
116
        }
117
118
        return $comparer->hasSameJobType($oJobEntityA, $oJobEntityB);
119
    }
120
121
122
    /**
123
     * @param $sJobName
124
     * @return bool
125
     */
126
    public function isJobAvailable($sJobName)
127
    {
128
        foreach($this->aComposites as $child)
129
        {
130
            if ($child->isJobAvailable($sJobName))
131
            {
132
                return true;
133
            }
134
        }
135
        return false;
136
    }
137
}