Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 23 | class SocialProfilesFieldsetFactory implements FactoryInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Creates a {@link SocialProfilesFieldset} |
||
| 27 | * |
||
| 28 | * Uses config from the config key [form_element_config][attach_social_profiles_fieldset] |
||
| 29 | * to configure fetch_url, preview_url and name or uses the defaults: |
||
| 30 | * - fetch_url: Route named "auth-social-profiles" with the suffix "?network=%s" |
||
| 31 | * - preview_url: Route named "lang/applications/detail" with the suffix "?action=social-profile&network=%s" |
||
| 32 | * - name: "social_profiles" |
||
| 33 | * |
||
| 34 | * @param ContainerInterface $container |
||
| 35 | * @param string $requestedName |
||
| 36 | * @param null|array $options |
||
| 37 | * |
||
| 38 | * @return object |
||
| 39 | * @throws ServiceNotFoundException if unable to resolve the service. |
||
| 40 | * @throws ServiceNotCreatedException if an exception is raised when |
||
| 41 | * creating a service. |
||
| 42 | * @throws ContainerException if any other error occurs |
||
| 43 | */ |
||
| 44 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param ServiceLocatorInterface $serviceLocator |
||
| 80 | * @return SocialProfilesFieldset |
||
| 81 | * @see \Zend\ServiceManager\FactoryInterface::createService() |
||
| 82 | */ |
||
| 83 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
| 87 | } |
||
| 88 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.