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
Push — master ( 7cd694...e4df7a )
by Marc
11s
created

getRemoteMissingJobs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

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 4
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: bthapaliya
5
 * Date: 15/02/17
6
 * Time: 15:01
7
 */
8
9
namespace Chapi\BusinessCase\Comparison;
10
11
12
use Chapi\Component\Comparison\DiffCompareInterface;
13
use Chapi\Entity\Chronos\JobCollection;
14
use Chapi\Entity\JobEntityInterface;
15
use Chapi\Service\JobRepository\JobRepositoryInterface;
16
17
abstract class AbstractJobComparisionBusinessCase implements JobComparisonInterface
18
{
19
    /**
20
     * @var JobRepositoryInterface
21
     */
22
    protected $oRemoteRepository;
23
    /**
24
     * @var JobRepositoryInterface
25
     */
26
    protected $oLocalRepository;
27
    /**
28
     * @var DiffCompareInterface
29
     */
30
    protected $oDiffCompare;
31
32
    /**
33
     * @inheritdoc
34
     */
35 1
    public function getLocalMissingJobs()
36
    {
37 1
        return $this->getMissingJobsInCollectionA(
38 1
            $this->oLocalRepository->getJobs(),
39 1
            $this->oRemoteRepository->getJobs()
40
        );
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 1
    public function getRemoteMissingJobs()
47
    {
48 1
        return $this->getMissingJobsInCollectionA(
49 1
            $this->oRemoteRepository->getJobs(),
50 1
            $this->oLocalRepository->getJobs()
51
        );
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 1
    public function isJobAvailable($sJobName)
58
    {
59 1
        $_bLocallyAvailable = $this->oLocalRepository->getJob($sJobName);
60 1
        $_bRemotelyAvailable = $this->oRemoteRepository->getJob($sJobName);
61 1
        return $_bLocallyAvailable || $_bRemotelyAvailable;
62
    }
63
64
65
    /**
66
     * @param JobCollection $oJobCollectionA
67
     * @param JobCollection $oJobCollectionB
68
     * @return array<string>
0 ignored issues
show
Documentation introduced by
Should the return type not be array<integer|string>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
69
     */
70 2
    protected function getMissingJobsInCollectionA(JobCollection $oJobCollectionA, JobCollection $oJobCollectionB)
71
    {
72 2
        return array_diff(
73 2
            array_keys($oJobCollectionB->getArrayCopy()),
74 2
            array_keys($oJobCollectionA->getArrayCopy())
75
        );
76
    }
77
78 9
    protected function getDifference(JobEntityInterface $oJobEntityA, JobEntityInterface $oJobEntityB)
79
    {
80 9
        $aJobACopy = [];
81 9
        $aJobBCopy = [];
82
83 9
        if ($oJobEntityA)
84
        {
85 9
            $aJobACopy = $oJobEntityA->getSimpleArrayCopy();
86
        }
87
88 9
        if ($oJobEntityB)
89
        {
90 9
            $aJobBCopy = $oJobEntityB->getSimpleArrayCopy();
91
        }
92
93 9
        return array_merge(
94
            array_diff_assoc(
95
                $aJobACopy,
96
                $aJobBCopy
97
            ),
98
            array_diff_assoc(
99
                $aJobBCopy,
100
                $aJobACopy
101
            )
102
        );
103
    }
104
105
106
    /**
107
     * @param JobEntityInterface $oJobEntityA
108
     * @param JobEntityInterface $oJobEntityB
109
     * @return array
110
     */
111 9
    protected function compareJobEntities(JobEntityInterface $oJobEntityA, JobEntityInterface $oJobEntityB)
112
    {
113 9
        $_aNonidenticalProperties = [];
114
115 9
        $_aDiff = $this->getDifference($oJobEntityA, $oJobEntityB);
116
117 9
        if (count($_aDiff) > 0)
118
        {
119 7
            $_aDiffKeys = array_keys($_aDiff);
120
121 7
            foreach ($_aDiffKeys as $_sDiffKey)
122
            {
123 7
                if (!$this->isEntityEqual($_sDiffKey, $oJobEntityA, $oJobEntityB))
124
                {
125 7
                    $_aNonidenticalProperties[] = $_sDiffKey;
126
                }
127
            }
128
        }
129
130 9
        return $_aNonidenticalProperties;
131
    }
132
133
134
    /**
135
     * @inheritdoc
136
     */
137 2
    public function getJobDiff($sJobName)
138
    {
139 2
        $_aDifferences = [];
140 2
        $_oLocalEntity = $this->oLocalRepository->getJob($sJobName);
141 2
        $_oRemoteEntity = $this->oRemoteRepository->getJob($sJobName);
142
143 2
        if (!$_oLocalEntity && !$_oRemoteEntity)
144
        {
145
            // return as jobs doesnt exist
146
            return [];
147
        }
148
149 2
        if (!$_oLocalEntity)
150
        {
151
            $_oLocalEntity = $this->getEntitySetWithDefaults();
152
        }
153
154 2
        if (!$_oRemoteEntity)
155
        {
156
            $_oRemoteEntity = $this->getEntitySetWithDefaults();
157
        }
158
159 2
        $this->preCompareModifications($_oLocalEntity, $_oRemoteEntity);
160 2
        $_aNonIdenticalProps = $this->compareJobEntities(
161
            $_oLocalEntity,
162
            $_oRemoteEntity
163
        );
164
165 2
        foreach ($_aNonIdenticalProps as $_sProperty)
166
        {
167 1
            $_aDifferences[$_sProperty] = $this->oDiffCompare->compare(
168 1
                $_oRemoteEntity->{$_sProperty},
169 1
                $_oLocalEntity->{$_sProperty}
170
            );
171
        }
172
173 2
        return $_aDifferences;
174
    }
175
176
177
178
    /**
179
     * @inheritdoc
180
     */
181 7
    public function getLocalJobUpdates()
182
    {
183 7
        $_aLocallyUpdatedJobs = [];
184 7
        $_aLocalJobs = $this->oLocalRepository->getJobs();
185
186
        /** @var JobEntityInterface $_oLocalJob */
187 7
        foreach ($_aLocalJobs as $_oLocalJob)
188
        {
189
190
            /** @var JobEntityInterface $_oRemoteJob */
191 7
            $_oRemoteJob = $this->oRemoteRepository->getJob($_oLocalJob->getKey());
192 7
            if (!$_oRemoteJob)
193
            {
194
                // if doesn't exist in remote, its not update. its new
195
                continue;
196
            }
197
198 7
            $this->preCompareModifications($_oLocalJob, $_oRemoteJob);
199
200 7
            $_aNonidenticalProperties = $this->compareJobEntities($_oLocalJob, $_oRemoteJob);
201
202 7
            if (!empty($_aNonidenticalProperties))
203
            {
204 7
                $_aLocallyUpdatedJobs[] = $_oLocalJob->getKey();
205
            }
206
        }
207 7
        return $_aLocallyUpdatedJobs;
208
    }
209
210
211
    /**
212
     * This method should perform any operation that is desired before comparing remote and local entities.
213
     * Why this is required?
214
     * For system like marathon, it is essential to set/unset certain values before comparing to make sane
215
     * comparision.
216
     *
217
     * Note: Should be careful with the parameters as they are passed by value.
218
     *
219
     * @param JobEntityInterface $oLocalJob
220
     * @param JobEntityInterface $oRemoteJob
221
     * @return null
222
     */
223
    abstract protected function preCompareModifications(JobEntityInterface &$oLocalJob, JobEntityInterface &$oRemoteJob);
224
225
    /**
226
     * Gets entity for each system with defaults set
227
     * @return JobEntityInterface
228
     */
229
    abstract protected function getEntitySetWithDefaults();
230
231
    /**
232
     * Verify if two entities are equal.
233
     *
234
     * @param $sProperty
235
     * @param JobEntityInterface $oJobEntityA
236
     * @param JobEntityInterface $oJobEntityB
237
     * @return mixed
238
     */
239
    abstract protected function isEntityEqual($sProperty, JobEntityInterface $oJobEntityA, JobEntityInterface $oJobEntityB);
240
241
    /**
242
     * @param JobEntityInterface $oJobEntityA
243
     * @param JobEntityInterface $oJobEntityB
244
     * @return bool
245
     */
246
    abstract public function hasSameJobType(JobEntityInterface $oJobEntityA, JobEntityInterface $oJobEntityB);
247
}