1 | <?php |
||
20 | class MarathonJobComparisonBusinessCase extends AbstractJobComparisionBusinessCase |
||
21 | { |
||
22 | /** |
||
23 | * @param JobRepositoryInterface $localRepository |
||
24 | * @param JobRepositoryInterface $remoteRepository |
||
25 | * @param DiffCompareInterface $diffCompare |
||
26 | */ |
||
27 | 24 | public function __construct( |
|
36 | |||
37 | 4 | protected function preCompareModifications(JobEntityInterface &$localJob, JobEntityInterface &$remoteJob) |
|
38 | { |
||
39 | 4 | if (!$localJob instanceof MarathonAppEntity || |
|
40 | 4 | !$remoteJob instanceof MarathonAppEntity |
|
41 | ) { |
||
42 | throw new \RuntimeException('Required MarathonAppEntity. Something else encountered.'); |
||
43 | } |
||
44 | // marathon returns portDefinitions values for auto configured port as well |
||
45 | // we want to only check if the port is defined in local file. |
||
46 | // otherwise we ignore the remote values. |
||
47 | 4 | if (!$localJob->portDefinitions) { |
|
|
|||
48 | 4 | $remoteJob->portDefinitions = null; |
|
49 | } |
||
50 | |||
51 | 4 | if ($localJob->container && $localJob->container->docker && |
|
52 | 4 | $remoteJob->container && $remoteJob->container->docker) { |
|
53 | |||
54 | 1 | foreach ($localJob->container->docker->portMappings as $index => $localPortMapping) { |
|
55 | 1 | if ($localPortMapping->servicePort !== 0) { |
|
56 | continue; |
||
57 | } |
||
58 | |||
59 | 1 | if (!isset($remoteJob->container->docker->portMappings, $index)) { |
|
60 | continue; |
||
61 | } |
||
62 | |||
63 | 1 | $remotePortMapping = $remoteJob->container->docker->portMappings[$index]; |
|
64 | |||
65 | 1 | if ($remotePortMapping != $localPortMapping) { |
|
66 | 1 | $fixedPortMapping = clone $remotePortMapping; |
|
67 | 1 | $fixedPortMapping->servicePort = 0; |
|
68 | |||
69 | 1 | if ($fixedPortMapping == $localPortMapping) { |
|
70 | 1 | unset($localJob->container->docker->portMappings[$index]); |
|
71 | 1 | unset($remoteJob->container->docker->portMappings[$index]); |
|
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | 4 | } |
|
77 | |||
78 | /** |
||
79 | * @return JobEntityInterface |
||
80 | */ |
||
81 | protected function getEntitySetWithDefaults() |
||
85 | |||
86 | /** |
||
87 | * @param JobEntityInterface|ChronosJobEntity $jobEntityA |
||
88 | * @param JobEntityInterface|ChronosJobEntity $jobEntityB |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function hasSameJobType(JobEntityInterface $jobEntityA, JobEntityInterface $jobEntityB) |
||
97 | |||
98 | /** |
||
99 | * @param $property |
||
100 | * @param $jobEntityA |
||
101 | * @param $jobEntityB |
||
102 | * @return bool |
||
103 | */ |
||
104 | 18 | protected function isEntityEqual($property, JobEntityInterface $jobEntityA, JobEntityInterface $jobEntityB) |
|
114 | |||
115 | /** |
||
116 | * @param mixed $valueA |
||
117 | * @param mixed $valueB |
||
118 | * @return bool |
||
119 | */ |
||
120 | 19 | private function isEqual($valueA, $valueB) |
|
132 | |||
133 | /** |
||
134 | * @param array $valuesA |
||
135 | * @param array $valuesB |
||
136 | * @return bool |
||
137 | */ |
||
138 | 12 | private function isArrayEqual(array $valuesA, array $valuesB) |
|
142 | |||
143 | /** |
||
144 | * @param array $valuesA |
||
145 | * @param array $valuesB |
||
146 | * @return bool |
||
147 | */ |
||
148 | 12 | private function isArrayHalfEqual(array $valuesA, array $valuesB) |
|
168 | } |
||
169 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.