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 |
||
| 12 | abstract class DriverFieldBase implements DriverFieldInterface |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Human-readable text intended to identify the field instance. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $identifier; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Field instance's machine name. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $name; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Entity type. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $entityType; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Entity bundle. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $bundle; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Raw field values before processing by DriverField plugins. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $rawValues; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Field values after processing by DriverField plugins. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $processedValues; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * A driver field plugin manager object. |
||
| 59 | * |
||
| 60 | * @var \Drupal\Driver\Plugin\DriverPluginManagerInterface |
||
| 61 | */ |
||
| 62 | protected $fieldPluginManager; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Directory to search for additional project-specific driver plugins. |
||
| 66 | * |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | protected $projectPluginRoot; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Construct a DriverField object. |
||
| 73 | * |
||
| 74 | * @param mixed |
||
| 75 | * Raw values for the field. Typically an array, one for each value of a |
||
| 76 | * multivalue field, but can be single. Values are typically string. |
||
| 77 | * @param string $fieldName |
||
|
|
|||
| 78 | * The machine name of the field. |
||
| 79 | * @param string $entityType |
||
| 80 | * The machine name of the entity type the field is attached to. |
||
| 81 | * @param string $bundle |
||
| 82 | * (optional) The machine name of the entity bundle the field is attached to. |
||
| 83 | * @param string $projectPluginRoot |
||
| 84 | * The directory to search for additional project-specific driver plugins. |
||
| 85 | * @param NULL|\Drupal\Driver\Plugin\DriverPluginManagerInterface $fieldPluginManager |
||
| 86 | * (optional) A driver field plugin manager. |
||
| 87 | * |
||
| 88 | */ |
||
| 89 | public function __construct( |
||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | public function getBundle() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * {@inheritdoc} |
||
| 127 | */ |
||
| 128 | public function getEntityType() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | public function getName() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * {@inheritdoc} |
||
| 143 | */ |
||
| 144 | public function getProcessedValues() |
||
| 176 | |||
| 177 | /** |
||
| 178 | * {@inheritdoc} |
||
| 179 | */ |
||
| 180 | public function getProjectPluginRoot() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritdoc} |
||
| 187 | */ |
||
| 188 | public function getRawValues() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Sets the processed values. |
||
| 195 | * |
||
| 196 | * @return \Drupal\Driver\Plugin\DriverPluginManagerInterface |
||
| 197 | * The field plugin manager. |
||
| 198 | */ |
||
| 199 | protected function getFieldPluginManager() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | public function isConfigProperty() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Sets the processed values. |
||
| 214 | * |
||
| 215 | * @param array $values |
||
| 216 | * An array of processed field value sets. |
||
| 217 | */ |
||
| 218 | protected function setProcessedValues(array $values) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set the driver field plugin manager. |
||
| 225 | * |
||
| 226 | * @param \Drupal\Driver\Plugin\DriverPluginManagerInterface $manager |
||
| 227 | * The driver entity plugin manager. |
||
| 228 | * @param string $projectPluginRoot |
||
| 229 | * The directory to search for additional project-specific driver plugins. |
||
| 230 | */ |
||
| 231 | View Code Duplication | protected function setFieldPluginManager($manager, $projectPluginRoot) |
|
| 238 | } |
||
| 239 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.