Complex classes like ExceptionConversion often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ExceptionConversion, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class ExceptionConversion extends Gateway |
||
20 | { |
||
21 | /** |
||
22 | * The wrapped gateway. |
||
23 | * |
||
24 | * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway |
||
25 | */ |
||
26 | protected $innerGateway; |
||
27 | |||
28 | /** |
||
29 | * Creates a new exception conversion gateway around $innerGateway. |
||
30 | * |
||
31 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway $innerGateway |
||
32 | */ |
||
33 | public function __construct(Gateway $innerGateway) |
||
37 | |||
38 | public function setTable($name) |
||
39 | { |
||
40 | try { |
||
41 | return $this->innerGateway->setTable($name); |
||
42 | } catch (DBALException $e) { |
||
43 | throw new \RuntimeException('Database error', 0, $e); |
||
44 | } catch (PDOException $e) { |
||
45 | throw new \RuntimeException('Database error', 0, $e); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Loads list of aliases by given $locationId. |
||
51 | * |
||
52 | * @param mixed $locationId |
||
53 | * @param bool $custom |
||
54 | * @param mixed $languageId |
||
55 | * |
||
56 | * @return array |
||
57 | */ |
||
58 | public function loadLocationEntries($locationId, $custom = false, $languageId = false) |
||
68 | |||
69 | /** |
||
70 | * Returns boolean indicating if the row with given $id is special root entry. |
||
71 | * |
||
72 | * Special root entry entry will have parentId=0 and text=''. |
||
73 | * In standard installation this entry will point to location with id=2. |
||
74 | * |
||
75 | * @param mixed $id |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function isRootEntry($id) |
||
89 | |||
90 | /** |
||
91 | * Downgrades autogenerated entry matched by given $action and $languageId and negatively matched by |
||
92 | * composite primary key. |
||
93 | * |
||
94 | * If language mask of the found entry is composite (meaning it consists of multiple language ids) given |
||
95 | * $languageId will be removed from mask. Otherwise entry will be marked as history. |
||
96 | * |
||
97 | * @param string $action |
||
98 | * @param mixed $languageId |
||
99 | * @param mixed $newId |
||
100 | * @param mixed $parentId |
||
101 | * @param string $textMD5 |
||
102 | */ |
||
103 | public function cleanupAfterPublish($action, $languageId, $newId, $parentId, $textMD5) |
||
104 | { |
||
105 | try { |
||
106 | $this->innerGateway->cleanupAfterPublish($action, $languageId, $newId, $parentId, $textMD5); |
||
107 | } catch (DBALException $e) { |
||
108 | throw new \RuntimeException('Database error', 0, $e); |
||
109 | } catch (PDOException $e) { |
||
110 | throw new \RuntimeException('Database error', 0, $e); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | public function historizeBeforeSwap($action, $languageMask) |
||
115 | { |
||
116 | try { |
||
117 | $this->innerGateway->historizeBeforeSwap($action, $languageMask); |
||
118 | } catch (DBALException $e) { |
||
119 | throw new \RuntimeException('Database error', 0, $e); |
||
120 | } catch (PDOException $e) { |
||
121 | throw new \RuntimeException('Database error', 0, $e); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Marks all entries with given $id as history entries. |
||
127 | * |
||
128 | * This method is used by Handler::locationMoved(). Each row is separately historized |
||
129 | * because future publishing needs to be able to take over history entries safely. |
||
130 | * |
||
131 | * @param mixed $id |
||
132 | * @param mixed $link |
||
133 | */ |
||
134 | public function historizeId($id, $link) |
||
144 | |||
145 | /** |
||
146 | * Updates parent id of autogenerated entries. |
||
147 | * |
||
148 | * Update includes history entries. |
||
149 | * |
||
150 | * @param mixed $oldParentId |
||
151 | * @param mixed $newParentId |
||
152 | */ |
||
153 | public function reparent($oldParentId, $newParentId) |
||
163 | |||
164 | /** |
||
165 | * Updates single row data matched by composite primary key. |
||
166 | * |
||
167 | * Use optional parameter $languageMaskMatch to additionally limit the query match with languages |
||
168 | * |
||
169 | * @param mixed $parentId |
||
170 | * @param string $textMD5 |
||
171 | * @param array $values associative array with column names as keys and column values as values |
||
172 | */ |
||
173 | public function updateRow($parentId, $textMD5, array $values) |
||
174 | { |
||
175 | try { |
||
176 | $this->innerGateway->updateRow($parentId, $textMD5, $values); |
||
177 | } catch (DBALException $e) { |
||
178 | throw new \RuntimeException('Database error', 0, $e); |
||
179 | } catch (PDOException $e) { |
||
180 | throw new \RuntimeException('Database error', 0, $e); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * Inserts new row in urlalias_ml table. |
||
186 | * |
||
187 | * @param array $values |
||
188 | * |
||
189 | * @return mixed |
||
190 | */ |
||
191 | public function insertRow(array $values) |
||
201 | |||
202 | /** |
||
203 | * Loads single row data matched by composite primary key. |
||
204 | * |
||
205 | * @param mixed $parentId |
||
206 | * @param string $textMD5 |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | public function loadRow($parentId, $textMD5) |
||
220 | |||
221 | /** |
||
222 | * Loads autogenerated entry id by given $action and optionally $parentId. |
||
223 | * |
||
224 | * @param string $action |
||
225 | * @param mixed|null $parentId |
||
226 | * |
||
227 | * @return array |
||
228 | */ |
||
229 | public function loadAutogeneratedEntry($action, $parentId = null) |
||
239 | |||
240 | /** |
||
241 | * Deletes all rows with given $action and optionally $id. |
||
242 | * |
||
243 | * If $id is set only autogenerated entries will be removed. |
||
244 | * |
||
245 | * @param string $action |
||
246 | * @param mixed|null $id |
||
247 | */ |
||
248 | public function remove($action, $id = null) |
||
249 | { |
||
250 | try { |
||
251 | $this->innerGateway->remove($action, $id); |
||
252 | } catch (DBALException $e) { |
||
253 | throw new \RuntimeException('Database error', 0, $e); |
||
254 | } catch (PDOException $e) { |
||
255 | throw new \RuntimeException('Database error', 0, $e); |
||
256 | } |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Loads paged list of global aliases. |
||
261 | * |
||
262 | * @param string|null $languageCode |
||
263 | * @param int $offset |
||
264 | * @param int $limit |
||
265 | * |
||
266 | * @return array |
||
267 | */ |
||
268 | public function listGlobalEntries($languageCode = null, $offset = 0, $limit = -1) |
||
278 | |||
279 | /** |
||
280 | * Deletes single custom alias row matched by composite primary key. |
||
281 | * |
||
282 | * If $id is set only autogenerated entries will be removed. |
||
283 | * |
||
284 | * @param mixed $parentId |
||
285 | * @param string $textMD5 |
||
286 | * |
||
287 | * @return bool |
||
288 | */ |
||
289 | public function removeCustomAlias($parentId, $textMD5) |
||
299 | |||
300 | /** |
||
301 | * Loads complete URL alias data by given array of path hashes. |
||
302 | * |
||
303 | * @param string[] $urlHashes URL string hashes |
||
304 | * |
||
305 | * @return array |
||
306 | */ |
||
307 | public function loadUrlAliasData(array $urlHashes) |
||
317 | |||
318 | /** |
||
319 | * Loads all data for the path identified by given $id. |
||
320 | * |
||
321 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
322 | * |
||
323 | * @param mixed $id |
||
324 | * |
||
325 | * @return array |
||
326 | */ |
||
327 | public function loadPathData($id) |
||
337 | |||
338 | /** |
||
339 | * Loads path data identified by given ordered array of hierarchy data. |
||
340 | * |
||
341 | * The first entry in $hierarchyData corresponds to the top-most path element in the path, the second entry the |
||
342 | * child of the first path element and so on. |
||
343 | * This method is faster than self::getPath() since it can fetch all elements using only one query, but can be used |
||
344 | * only for autogenerated paths. |
||
345 | * |
||
346 | * @param array $hierarchyData |
||
347 | * |
||
348 | * @return array |
||
349 | */ |
||
350 | public function loadPathDataByHierarchy(array $hierarchyData) |
||
360 | |||
361 | /** |
||
362 | * Loads all autogenerated entries with given $parentId with optionally included history entries. |
||
363 | * |
||
364 | * @param mixed $parentId |
||
365 | * @param bool $includeHistory |
||
366 | * |
||
367 | * @return array |
||
368 | */ |
||
369 | public function loadAutogeneratedEntries($parentId, $includeHistory = false) |
||
379 | |||
380 | /** |
||
381 | * Returns next value for "id" column. |
||
382 | * |
||
383 | * @return mixed |
||
384 | */ |
||
385 | public function getNextId() |
||
395 | |||
396 | public function getLocationContentMainLanguageId($locationId) |
||
397 | { |
||
398 | try { |
||
399 | return $this->innerGateway->getLocationContentMainLanguageId($locationId); |
||
400 | } catch (DBALException $e) { |
||
406 | |||
407 | /** |
||
408 | * {@inheritdoc} |
||
409 | */ |
||
410 | public function bulkRemoveTranslation($languageId, $actions) |
||
420 | |||
421 | /** |
||
422 | * {@inheritdoc} |
||
423 | */ |
||
424 | public function archiveUrlAliasesForDeletedTranslations($locationId, $parentId, array $languageIds) |
||
434 | |||
435 | /** |
||
436 | * {@inheritdoc} |
||
437 | */ |
||
438 | public function deleteUrlAliasesWithoutLocation() |
||
448 | |||
449 | /** |
||
450 | * {@inheritdoc} |
||
451 | */ |
||
452 | public function deleteUrlAliasesWithoutParent() |
||
462 | |||
463 | /** |
||
464 | * {@inheritdoc} |
||
465 | */ |
||
466 | public function deleteUrlAliasesWithBrokenLink() |
||
476 | |||
477 | /** |
||
478 | * {@inheritdoc} |
||
479 | */ |
||
480 | public function repairBrokenUrlAliasesForLocation(int $locationId) |
||
488 | } |
||
489 |