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 |
||
27 | class ExceptionConversion extends Gateway |
||
28 | { |
||
29 | /** |
||
30 | * The wrapped gateway. |
||
31 | * |
||
32 | * @var Gateway |
||
33 | */ |
||
34 | protected $innerGateway; |
||
35 | |||
36 | /** |
||
37 | * Creates a new exception conversion gateway around $innerGateway. |
||
38 | * |
||
39 | * @param Gateway $innerGateway |
||
40 | */ |
||
41 | public function __construct(Gateway $innerGateway) |
||
45 | |||
46 | /** |
||
47 | * Get context definition for external storage layers. |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | public function getContext() |
||
61 | |||
62 | /** |
||
63 | * Inserts a new content object. |
||
64 | * |
||
65 | * @param \eZ\Publish\SPI\Persistence\Content\CreateStruct $struct |
||
66 | * @param mixed $currentVersionNo |
||
67 | * |
||
68 | * @return int ID |
||
69 | */ |
||
70 | public function insertContentObject(CreateStruct $struct, $currentVersionNo = 1) |
||
80 | |||
81 | /** |
||
82 | * Inserts a new version. |
||
83 | * |
||
84 | * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $versionInfo |
||
85 | * @param \eZ\Publish\SPI\Persistence\Content\Field[] $fields |
||
86 | * |
||
87 | * @return int ID |
||
88 | */ |
||
89 | public function insertVersion(VersionInfo $versionInfo, array $fields) |
||
99 | |||
100 | /** |
||
101 | * Updates an existing content identified by $contentId in respect to $struct. |
||
102 | * |
||
103 | * @param int $contentId |
||
104 | * @param \eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct $struct |
||
105 | * @param \eZ\Publish\SPI\Persistence\Content\VersionInfo $prePublishVersionInfo Provided on publish |
||
106 | */ |
||
107 | public function updateContent($contentId, MetadataUpdateStruct $struct, VersionInfo $prePublishVersionInfo = null) |
||
117 | |||
118 | /** |
||
119 | * Updates version $versionNo for content identified by $contentId, in respect to $struct. |
||
120 | * |
||
121 | * @param int $contentId |
||
122 | * @param int $versionNo |
||
123 | * @param \eZ\Publish\SPI\Persistence\Content\UpdateStruct $struct |
||
124 | */ |
||
125 | public function updateVersion($contentId, $versionNo, UpdateStruct $struct) |
||
135 | |||
136 | /** |
||
137 | * Updates "always available" flag for content identified by $contentId, in respect to $alwaysAvailable. |
||
138 | * |
||
139 | * @param int $contentId |
||
140 | * @param bool $newAlwaysAvailable New "always available" value |
||
141 | */ |
||
142 | public function updateAlwaysAvailableFlag($contentId, $newAlwaysAvailable) |
||
152 | |||
153 | /** |
||
154 | * Sets the state of object identified by $contentId and $version to $state. |
||
155 | * |
||
156 | * The $status can be one of STATUS_DRAFT, STATUS_PUBLISHED, STATUS_ARCHIVED |
||
157 | * |
||
158 | * @param int $contentId |
||
159 | * @param int $version |
||
160 | * @param int $status |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function setStatus($contentId, $version, $status) |
||
174 | |||
175 | /** |
||
176 | * Inserts a new field. |
||
177 | * |
||
178 | * Only used when a new field is created (i.e. a new object or a field in a |
||
179 | * new language!). After that, field IDs need to stay the same, only the |
||
180 | * version number changes. |
||
181 | * |
||
182 | * @param \eZ\Publish\SPI\Persistence\Content $content |
||
183 | * @param \eZ\Publish\SPI\Persistence\Content\Field $field |
||
184 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value |
||
185 | * |
||
186 | * @return int ID |
||
187 | */ |
||
188 | public function insertNewField(Content $content, Field $field, StorageFieldValue $value) |
||
198 | |||
199 | /** |
||
200 | * Inserts an existing field. |
||
201 | * |
||
202 | * Used to insert a field with an exsting ID but a new version number. |
||
203 | * |
||
204 | * @param Content $content |
||
205 | * @param Field $field |
||
206 | * @param StorageFieldValue $value |
||
207 | */ |
||
208 | public function insertExistingField(Content $content, Field $field, StorageFieldValue $value) |
||
218 | |||
219 | /** |
||
220 | * Updates an existing field. |
||
221 | * |
||
222 | * @param Field $field |
||
223 | * @param StorageFieldValue $value |
||
224 | */ |
||
225 | public function updateField(Field $field, StorageFieldValue $value) |
||
235 | |||
236 | /** |
||
237 | * Updates an existing, non-translatable field. |
||
238 | * |
||
239 | * @param \eZ\Publish\SPI\Persistence\Content\Field $field |
||
240 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value |
||
241 | * @param int $contentId |
||
242 | */ |
||
243 | public function updateNonTranslatableField( |
||
256 | |||
257 | /** |
||
258 | * Loads data for a content object. |
||
259 | * |
||
260 | * Returns an array with the relevant data. |
||
261 | * |
||
262 | * @param mixed $contentId |
||
263 | * @param mixed $version |
||
264 | * @param string[] $translations |
||
265 | * |
||
266 | * @return array |
||
267 | */ |
||
268 | public function load($contentId, $version, array $translations = null) |
||
278 | |||
279 | /** |
||
280 | * {@inheritdoc} |
||
281 | */ |
||
282 | public function loadContentList(array $IdVersionTranslationPairs): array |
||
290 | |||
291 | /** |
||
292 | * Loads data for a content object identified by its remote ID. |
||
293 | * |
||
294 | * Returns an array with the relevant data. |
||
295 | * |
||
296 | * @param mixed $remoteId |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | public function loadContentInfoByRemoteId($remoteId) |
||
310 | |||
311 | /** |
||
312 | * Loads info for a content object identified by its location ID (node ID). |
||
313 | * |
||
314 | * Returns an array with the relevant data. |
||
315 | * |
||
316 | * @param int $locationId |
||
317 | * |
||
318 | * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException |
||
319 | * |
||
320 | * @return array |
||
321 | */ |
||
322 | public function loadContentInfoByLocationId($locationId) |
||
332 | |||
333 | /** |
||
334 | * Loads info for content identified by $contentId. |
||
335 | * Will basically return a hash containing all field values for ezcontentobject table plus following keys: |
||
336 | * - always_available => Boolean indicating if content's language mask contains alwaysAvailable bit field |
||
337 | * - main_language_code => Language code for main (initial) language. E.g. "eng-GB". |
||
338 | * |
||
339 | * @param int $contentId |
||
340 | * |
||
341 | * @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException |
||
342 | * |
||
343 | * @return array |
||
344 | */ |
||
345 | public function loadContentInfo($contentId) |
||
355 | |||
356 | public function loadContentInfoList(array $contentIds) |
||
366 | |||
367 | /** |
||
368 | * Loads version info for content identified by $contentId and $versionNo. |
||
369 | * Will basically return a hash containing all field values from ezcontentobject_version table plus following keys: |
||
370 | * - names => Hash of content object names. Key is the language code, value is the name. |
||
371 | * - languages => Hash of language ids. Key is the language code (e.g. "eng-GB"), value is the language numeric id without the always available bit. |
||
372 | * - initial_language_code => Language code for initial language in this version. |
||
373 | * |
||
374 | * @param int $contentId |
||
375 | * @param int $versionNo |
||
376 | * |
||
377 | * @return array |
||
378 | */ |
||
379 | public function loadVersionInfo($contentId, $versionNo) |
||
389 | |||
390 | /** |
||
391 | * Returns data for all versions with given status created by the given $userId. |
||
392 | * |
||
393 | * @param int $userId |
||
394 | * @param int $status |
||
395 | * |
||
396 | * @return string[][] |
||
397 | */ |
||
398 | public function listVersionsForUser($userId, $status = VersionInfo::STATUS_DRAFT) |
||
408 | |||
409 | /** |
||
410 | * Returns all version data for the given $contentId. |
||
411 | * |
||
412 | * Result is returned with oldest version first (using version id as it has index and is auto increment). |
||
413 | * |
||
414 | * @param mixed $contentId |
||
415 | * @param mixed|null $status Optional argument to filter versions by status, like {@see VersionInfo::STATUS_ARCHIVED}. |
||
416 | * @param int $limit Limit for items returned, -1 means none. |
||
417 | * |
||
418 | * @return string[][] |
||
419 | */ |
||
420 | public function listVersions($contentId, $status = null, $limit = -1) |
||
430 | |||
431 | /** |
||
432 | * Returns all version numbers for the given $contentId. |
||
433 | * |
||
434 | * @param mixed $contentId |
||
435 | * |
||
436 | * @return int[] |
||
437 | */ |
||
438 | public function listVersionNumbers($contentId) |
||
448 | |||
449 | /** |
||
450 | * Returns last version number for content identified by $contentId. |
||
451 | * |
||
452 | * @param int $contentId |
||
453 | * |
||
454 | * @return int |
||
455 | */ |
||
456 | public function getLastVersionNumber($contentId) |
||
466 | |||
467 | /** |
||
468 | * Returns all IDs for locations that refer to $contentId. |
||
469 | * |
||
470 | * @param int $contentId |
||
471 | * |
||
472 | * @return int[] |
||
473 | */ |
||
474 | public function getAllLocationIds($contentId) |
||
484 | |||
485 | /** |
||
486 | * Returns all field IDs of $contentId grouped by their type. |
||
487 | * If $versionNo is set only field IDs for that version are returned. |
||
488 | * If $languageCode is set, only field IDs for that language are returned. |
||
489 | * |
||
490 | * @param int $contentId |
||
491 | * @param int|null $versionNo |
||
492 | * @param string|null $languageCode |
||
493 | * |
||
494 | * @return int[][] |
||
495 | */ |
||
496 | public function getFieldIdsByType($contentId, $versionNo = null, $languageCode = null) |
||
506 | |||
507 | /** |
||
508 | * Deletes relations to and from $contentId. |
||
509 | * If $versionNo is set only relations for that version are deleted. |
||
510 | * |
||
511 | * @param int $contentId |
||
512 | * @param int|null $versionNo |
||
513 | */ |
||
514 | public function deleteRelations($contentId, $versionNo = null) |
||
524 | |||
525 | /** |
||
526 | * Removes relations to Content with $contentId from Relation and RelationList field type fields. |
||
527 | * |
||
528 | * @param int $contentId |
||
529 | */ |
||
530 | public function removeReverseFieldRelations($contentId) |
||
540 | |||
541 | /** |
||
542 | * Deletes the field with the given $fieldId. |
||
543 | * |
||
544 | * @param int $fieldId |
||
545 | */ |
||
546 | public function deleteField($fieldId) |
||
556 | |||
557 | /** |
||
558 | * Deletes all fields of $contentId in all versions. |
||
559 | * If $versionNo is set only fields for that version are deleted. |
||
560 | * |
||
561 | * @param int $contentId |
||
562 | * @param int|null $versionNo |
||
563 | */ |
||
564 | public function deleteFields($contentId, $versionNo = null) |
||
574 | |||
575 | /** |
||
576 | * Deletes all versions of $contentId. |
||
577 | * If $versionNo is set only that version is deleted. |
||
578 | * |
||
579 | * @param int $contentId |
||
580 | * @param int|null $versionNo |
||
581 | */ |
||
582 | public function deleteVersions($contentId, $versionNo = null) |
||
592 | |||
593 | /** |
||
594 | * Deletes all names of $contentId. |
||
595 | * If $versionNo is set only names for that version are deleted. |
||
596 | * |
||
597 | * @param int $contentId |
||
598 | * @param int|null $versionNo |
||
599 | */ |
||
600 | public function deleteNames($contentId, $versionNo = null) |
||
610 | |||
611 | /** |
||
612 | * Sets the content object name. |
||
613 | * |
||
614 | * @param int $contentId |
||
615 | * @param int $version |
||
616 | * @param string $name |
||
617 | * @param string $language |
||
618 | */ |
||
619 | public function setName($contentId, $version, $name, $language) |
||
629 | |||
630 | /** |
||
631 | * Deletes the actual content object referred to by $contentId. |
||
632 | * |
||
633 | * @param int $contentId |
||
634 | */ |
||
635 | public function deleteContent($contentId) |
||
645 | |||
646 | /** |
||
647 | * Loads data of related to/from $contentId. |
||
648 | * |
||
649 | * @param int $contentId |
||
650 | * @param int $contentVersionNo |
||
651 | * @param int $relationType |
||
652 | * |
||
653 | * @return mixed[][] Content data, array structured like {@see \eZ\Publish\Core\Persistence\Legacy\Content\Gateway::load()} |
||
654 | */ |
||
655 | public function loadRelations($contentId, $contentVersionNo = null, $relationType = null) |
||
665 | |||
666 | /** |
||
667 | * Loads data of related to/from $contentId. |
||
668 | * |
||
669 | * @param int $contentId |
||
670 | * @param bool $reverse Reverse relation, default false |
||
|
|||
671 | * @param int $contentVersionNo |
||
672 | * @param int $relationType |
||
673 | * |
||
674 | * @return mixed[][] Content data, array structured like {@see \eZ\Publish\Core\Persistence\Legacy\Content\Gateway::load()} |
||
675 | */ |
||
676 | public function loadReverseRelations($contentId, $relationType = null) |
||
686 | |||
687 | /** |
||
688 | * Deletes the relation with the given $relationId. |
||
689 | * |
||
690 | * @param int $relationId |
||
691 | * @param int $type {@see \eZ\Publish\API\Repository\Values\Content\Relation::COMMON, |
||
692 | * \eZ\Publish\API\Repository\Values\Content\Relation::EMBED, |
||
693 | * \eZ\Publish\API\Repository\Values\Content\Relation::LINK, |
||
694 | * \eZ\Publish\API\Repository\Values\Content\Relation::FIELD} |
||
695 | */ |
||
696 | public function deleteRelation($relationId, $type) |
||
706 | |||
707 | /** |
||
708 | * Inserts a new relation database record. |
||
709 | * |
||
710 | * @param \eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct $createStruct |
||
711 | * |
||
712 | * @return int ID the inserted ID |
||
713 | */ |
||
714 | public function insertRelation(RelationCreateStruct $struct) |
||
724 | |||
725 | /** |
||
726 | * Returns all Content IDs for a given $contentTypeId. |
||
727 | * |
||
728 | * @param int $contentTypeId |
||
729 | * |
||
730 | * @return int[] |
||
731 | */ |
||
732 | public function getContentIdsByContentTypeId($contentTypeId) |
||
742 | |||
743 | /** |
||
744 | * Load name data for set of content id's and corresponding version number. |
||
745 | * |
||
746 | * @param array[] $rows array of hashes with 'id' and 'version' to load names for |
||
747 | * |
||
748 | * @return array |
||
749 | */ |
||
750 | public function loadVersionedNameData($rows) |
||
760 | |||
761 | /** |
||
762 | * Batch method for copying all relation meta data for copied Content object. |
||
763 | * |
||
764 | * {@inheritdoc} |
||
765 | * |
||
766 | * @param int $originalContentId |
||
767 | * @param int $copiedContentId |
||
768 | * @param int|null $versionNo If specified only copy for a given version number, otherwise all. |
||
769 | */ |
||
770 | public function copyRelations($originalContentId, $copiedContentId, $versionNo = null) |
||
780 | |||
781 | /** |
||
782 | * Remove the specified translation from all the Versions of a Content Object. |
||
783 | * |
||
784 | * @param int $contentId |
||
785 | * @param string $languageCode language code of the translation |
||
786 | */ |
||
787 | public function deleteTranslationFromContent($contentId, $languageCode) |
||
797 | |||
798 | /** |
||
799 | * Delete Content fields (attributes) for the given Translation. |
||
800 | * If $versionNo is given, fields for that Version only will be deleted. |
||
801 | * |
||
802 | * @param string $languageCode |
||
803 | * @param int $contentId |
||
804 | * @param int $versionNo (optional) filter by versionNo |
||
805 | */ |
||
806 | public function deleteTranslatedFields($languageCode, $contentId, $versionNo = null) |
||
816 | |||
817 | /** |
||
818 | * Delete the specified Translation from the given Version. |
||
819 | * |
||
820 | * @param int $contentId |
||
821 | * @param int $versionNo |
||
822 | * @param string $languageCode |
||
823 | */ |
||
824 | public function deleteTranslationFromVersion($contentId, $versionNo, $languageCode) |
||
834 | } |
||
835 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.