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
02:54
created

getLocalJobUpdates()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 3
b 0
f 0
cc 2
eloc 5
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
            // NOTE: only gets the first one.
81
            // does it make sense?
82 1
            if ($jobComparers->isJobAvailable($sJobName)) {
83 1
                $_aJobDiffs = $jobComparers->getJobDiff($sJobName);
84 1
                break;
85
            }
86 1
        }
87 1
        return $_aJobDiffs;
88
    }
89
90
    /**
91
     * @param JobEntityInterface|ChronosJobEntity $oJobEntityA
92
     * @param JobEntityInterface|ChronosJobEntity $oJobEntityB
93
     * @return bool
94
     */
95
    public function hasSameJobType(JobEntityInterface $oJobEntityA, JobEntityInterface $oJobEntityB)
96
    {
97
        if ($oJobEntityA->getEntityType() != $oJobEntityB->getEntityType()) {
98
            throw new Exception('type compared for different entity types.');
99
        }
100
        /** @var JobComparisonInterface $comparer */
101
        $comparer = null;
102
        foreach($this->aComposites as $child)
103
        {
104
            if ($child->isJobAvailable($oJobEntityA->getKey()))
105
            {
106
                $comparer = $child;
107
                break;
108
            }
109
        }
110
111
        if ($comparer == null)
112
        {
113
            throw new Exception(sprintf('could not find appropriate comparision businesscase to operate', $oJobEntityA->getKey()));
114
        }
115
116
        return $comparer->hasSameJobType($oJobEntityA, $oJobEntityB);
117
    }
118
119
120
    /**
121
     * @param $sJobName
122
     * @return bool
123
     */
124
    public function isJobAvailable($sJobName)
125
    {
126
        foreach($this->aComposites as $child) {
127
            if ($child->isJobAvailable($sJobName))
128
            {
129
                return true;
130
            }
131
        }
132
        return false;
133
    }
134
}