1 | <?php |
||
17 | abstract class AbstractChecker |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Source database. |
||
22 | * |
||
23 | * @var ExtendedPdoInterface |
||
24 | */ |
||
25 | protected $sourceDatabase; |
||
26 | |||
27 | /** |
||
28 | * Target database. |
||
29 | * |
||
30 | * @var ExtendedPdoInterface |
||
31 | */ |
||
32 | protected $targetDatabase; |
||
33 | |||
34 | /** |
||
35 | * Cache. |
||
36 | * |
||
37 | * @var CacheProvider |
||
38 | */ |
||
39 | protected $cache; |
||
40 | |||
41 | /** |
||
42 | * Incidents. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | private $_incidents = array(); |
||
47 | |||
48 | /** |
||
49 | * Determines the order used to sort incidents with different types. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $typeSorting = array(); |
||
54 | |||
55 | /** |
||
56 | * AbstractChecker constructor. |
||
57 | * |
||
58 | * @param CacheProvider $cache Cache provider. |
||
59 | */ |
||
60 | 12 | public function __construct(CacheProvider $cache) |
|
64 | |||
65 | /** |
||
66 | * Returns backwards compatibility checker name. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | abstract public function getName(); |
||
71 | |||
72 | /** |
||
73 | * Checks backwards compatibility and returns violations by category. |
||
74 | * |
||
75 | * @param ExtendedPdoInterface $source_db Source DB. |
||
76 | * @param ExtendedPdoInterface $target_db Target DB. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | 8 | public function check(ExtendedPdoInterface $source_db, ExtendedPdoInterface $target_db) |
|
91 | |||
92 | /** |
||
93 | * Sorts incidents by type. |
||
94 | * |
||
95 | * @param array $incident_a Incident A. |
||
96 | * @param array $incident_b Incident B. |
||
97 | * |
||
98 | * @return integer |
||
99 | */ |
||
100 | 3 | public function sortByType(array $incident_a, array $incident_b) |
|
111 | |||
112 | /** |
||
113 | * Collects backwards compatibility violations. |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | abstract protected function doCheck(); |
||
118 | |||
119 | /** |
||
120 | * Builds string representation of a parameter. |
||
121 | * |
||
122 | * @param array $parameter_data Parameter data. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | 6 | protected function paramToString(array $parameter_data) |
|
163 | |||
164 | /** |
||
165 | * Determines if 2 param signatures are compatible. |
||
166 | * |
||
167 | * @param string $source_signature Source signature. |
||
168 | * @param string $target_signature Target signature. |
||
169 | * |
||
170 | * @return boolean |
||
171 | */ |
||
172 | 6 | protected function isParamSignatureCompatible($source_signature, $target_signature) |
|
211 | |||
212 | /** |
||
213 | * Decodes json-encoded PHP value. |
||
214 | * |
||
215 | * @param string $json_string JSON string. |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | 6 | protected function decodeValue($json_string) |
|
227 | |||
228 | /** |
||
229 | * Adds incident. |
||
230 | * |
||
231 | * @param string $type Incident type. |
||
232 | * @param string $element Element affected. |
||
233 | * @param string|null $old_value Old value. |
||
234 | * @param string|null $new_value New value. |
||
235 | * |
||
236 | * @return void |
||
237 | */ |
||
238 | 4 | protected function addIncident($type, $element, $old_value = null, $new_value = null) |
|
252 | |||
253 | /** |
||
254 | * Returns cache key valid for specific database only. |
||
255 | * |
||
256 | * @param ExtendedPdoInterface $db Database. |
||
257 | * @param string $cache_key Cache key. |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | 4 | protected function getCacheKey(ExtendedPdoInterface $db, $cache_key) |
|
265 | |||
266 | } |
||
267 |