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 |
||
21 | class EntityBrowserWizard extends EntityFormWizardBase { |
||
22 | |||
23 | /** |
||
24 | * @param \Drupal\user\SharedTempStoreFactory $tempstore |
||
25 | * Tempstore Factory for keeping track of values in each step of the |
||
26 | * wizard. |
||
27 | * @param \Drupal\Core\Form\FormBuilderInterface $builder |
||
28 | * The Form Builder. |
||
29 | * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver |
||
30 | * The class resolver. |
||
31 | * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher |
||
32 | * The event dispatcher. |
||
33 | * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager |
||
34 | * The entity manager. |
||
35 | * @param $tempstore_id |
||
36 | * The shared temp store factory collection name. |
||
37 | * @param null $machine_name |
||
|
|||
38 | * The SharedTempStore key for our current wizard values. |
||
39 | * @param null $step |
||
40 | * The current active step of the wizard. |
||
41 | */ |
||
42 | public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, EntityManagerInterface $entity_manager, RouteMatchInterface $route_match, $tempstore_id, $entity_browser = NULL, $step = 'general') { |
||
43 | parent::__construct($tempstore, $builder, $class_resolver, $event_dispatcher, $entity_manager, $route_match, $tempstore_id, $entity_browser, $step); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | View Code Duplication | public function getNextParameters($cached_values) { |
|
50 | $parameters = parent::getNextParameters($cached_values); |
||
51 | $parameters['entity_browser'] = $parameters['machine_name']; |
||
52 | unset($parameters['machine_name']); |
||
53 | return $parameters; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | View Code Duplication | public function getPreviousParameters($cached_values) { |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function getWizardLabel() { |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function getMachineLabel() { |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function getEntityType() { |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function exists() { |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function getOperations($cached_values) { |
||
121 | |||
122 | } |
||
123 |
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.