Complex classes like EmailActivityListProvider 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 EmailActivityListProvider, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 41 | class EmailActivityListProvider implements |
||
| 42 | ActivityListProviderInterface, |
||
| 43 | ActivityListDateProviderInterface, |
||
| 44 | ActivityListGroupProviderInterface, |
||
| 45 | CommentProviderInterface |
||
| 46 | { |
||
| 47 | const ACTIVITY_CLASS = 'Oro\Bundle\EmailBundle\Entity\Email'; |
||
| 48 | const ACL_CLASS = 'Oro\Bundle\EmailBundle\Entity\EmailUser'; |
||
| 49 | |||
| 50 | /** @var DoctrineHelper */ |
||
| 51 | protected $doctrineHelper; |
||
| 52 | |||
| 53 | /** @var ServiceLink */ |
||
| 54 | protected $doctrineRegistryLink; |
||
| 55 | |||
| 56 | /** @var EntityNameResolver */ |
||
| 57 | protected $entityNameResolver; |
||
| 58 | |||
| 59 | /** @var Router */ |
||
| 60 | protected $router; |
||
| 61 | |||
| 62 | /** @var ConfigManager */ |
||
| 63 | protected $configManager; |
||
| 64 | |||
| 65 | /** @var EmailThreadProvider */ |
||
| 66 | protected $emailThreadProvider; |
||
| 67 | |||
| 68 | /** @var HtmlTagHelper */ |
||
| 69 | protected $htmlTagHelper; |
||
| 70 | |||
| 71 | /** @var ServiceLink */ |
||
| 72 | protected $securityContextLink; |
||
| 73 | |||
| 74 | /** @var ServiceLink */ |
||
| 75 | protected $securityFacadeLink; |
||
| 76 | |||
| 77 | /** @var ServiceLink */ |
||
| 78 | protected $mailboxProcessStorageLink; |
||
| 79 | |||
| 80 | /** @var ActivityAssociationHelper */ |
||
| 81 | protected $activityAssociationHelper; |
||
| 82 | |||
| 83 | /** @var CommentAssociationHelper */ |
||
| 84 | protected $commentAssociationHelper; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param DoctrineHelper $doctrineHelper |
||
| 88 | * @param ServiceLink $doctrineRegistryLink |
||
| 89 | * @param EntityNameResolver $entityNameResolver |
||
| 90 | * @param Router $router |
||
| 91 | * @param ConfigManager $configManager |
||
| 92 | * @param EmailThreadProvider $emailThreadProvider |
||
| 93 | * @param HtmlTagHelper $htmlTagHelper |
||
| 94 | * @param ServiceLink $securityFacadeLink |
||
| 95 | * @param ServiceLink $mailboxProcessStorageLink |
||
| 96 | * @param ActivityAssociationHelper $activityAssociationHelper |
||
| 97 | * @param CommentAssociationHelper $commentAssociationHelper |
||
| 98 | * |
||
| 99 | * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
||
| 100 | */ |
||
| 101 | public function __construct( |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param ServiceLink $securityContextLink |
||
| 129 | */ |
||
| 130 | public function setSecurityContextLink(ServiceLink $securityContextLink) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | public function isApplicableTarget($entityClass, $accessible = true) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * {@inheritdoc} |
||
| 149 | */ |
||
| 150 | public function getRoutes() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * {@inheritdoc} |
||
| 160 | */ |
||
| 161 | public function getActivityClass() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * {@inheritdoc} |
||
| 168 | */ |
||
| 169 | public function getAclClass() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * {@inheritdoc} |
||
| 176 | */ |
||
| 177 | public function getSubject($entity) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * {@inheritdoc} |
||
| 185 | */ |
||
| 186 | public function getDescription($entity) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * {@inheritdoc} |
||
| 203 | */ |
||
| 204 | public function getOwner($entity) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * {@inheritdoc} |
||
| 211 | */ |
||
| 212 | public function getCreatedAt($entity) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritdoc} |
||
| 220 | */ |
||
| 221 | public function getUpdatedAt($entity) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * {@inheritdoc} |
||
| 229 | */ |
||
| 230 | public function isHead($entity) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * {@inheritdoc} |
||
| 238 | */ |
||
| 239 | public function getOrganization($activityEntity) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * {@inheritdoc} |
||
| 274 | */ |
||
| 275 | public function getData(ActivityList $activityListEntity) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * {@inheritdoc} |
||
| 311 | */ |
||
| 312 | public function getTemplate() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * {@inheritdoc} |
||
| 319 | */ |
||
| 320 | public function getGroupedTemplate() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * {@inheritdoc} |
||
| 327 | */ |
||
| 328 | public function getActivityId($entity) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * {@inheritdoc} |
||
| 338 | */ |
||
| 339 | public function isApplicable($entity) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * {@inheritdoc} |
||
| 346 | */ |
||
| 347 | public function getTargetEntities($entity) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * {@inheritdoc} |
||
| 354 | */ |
||
| 355 | public function isCommentsEnabled($entityClass) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * {@inheritdoc} |
||
| 362 | */ |
||
| 363 | public function getGroupedEntities($email) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * {@inheritdoc} |
||
| 384 | */ |
||
| 385 | public function getActivityOwners($entity, ActivityList $activityList) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param $entity |
||
| 434 | * @return mixed |
||
| 435 | */ |
||
| 436 | protected function getEmailEntity($entity) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @param Email $email |
||
| 447 | * @param $data |
||
| 448 | * |
||
| 449 | * @return mixed |
||
| 450 | */ |
||
| 451 | protected function setReplaedEmailId($email, $data) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @param EmailOwnerInterface $owner |
||
| 466 | * @param $data |
||
| 467 | * |
||
| 468 | * @return mixed |
||
| 469 | */ |
||
| 470 | protected function setOwnerLink($owner, $data) |
||
| 486 | } |
||
| 487 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: