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 |
||
| 11 | abstract class DriverFieldBase implements DriverFieldInterface { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Human-readable text intended to identify the field instance. |
||
| 15 | * |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $identifier; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Field instance's machine name. |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $name; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Entity type. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $entityType; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Entity bundle. |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $bundle; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Raw field values before processing by DriverField plugins. |
||
| 43 | * |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | protected $rawValues; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Field values after processing by DriverField plugins. |
||
| 50 | * |
||
| 51 | * @var array |
||
| 52 | */ |
||
| 53 | protected $processedValues; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * A driver field plugin manager object. |
||
| 57 | * |
||
| 58 | * @var \Drupal\Driver\Plugin\DriverPluginManagerInterface |
||
| 59 | */ |
||
| 60 | protected $fieldPluginManager; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Directory to search for additional project-specific driver plugins. |
||
| 64 | * |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $projectPluginRoot; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Construct a DriverField object. |
||
| 71 | * |
||
| 72 | * @param mixed $rawValues |
||
| 73 | * Raw values for the field. Typically an array, one for each value of a |
||
| 74 | * multivalue field, but can be single. Values are typically string. |
||
| 75 | * @param string $identifier |
||
| 76 | * The machine name of the field or property. |
||
| 77 | * @param string $entityType |
||
| 78 | * The machine name of the entity type the field is attached to. |
||
| 79 | * @param string $bundle |
||
| 80 | * (optional) Machine name of the entity bundle the field is attached to. |
||
| 81 | * @param string $projectPluginRoot |
||
| 82 | * The directory to search for additional project-specific driver plugins. |
||
| 83 | * @param null|\Drupal\Driver\Plugin\DriverPluginManagerInterface $fieldPluginManager |
||
| 84 | * (optional) A driver field plugin manager. |
||
| 85 | */ |
||
| 86 | public function __construct( |
||
| 112 | |||
| 113 | /** |
||
| 114 | * {@inheritdoc} |
||
| 115 | */ |
||
| 116 | public function getBundle() { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | public function getEntityType() { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc} |
||
| 129 | */ |
||
| 130 | public function getName() { |
||
| 133 | |||
| 134 | /** |
||
| 135 | * {@inheritdoc} |
||
| 136 | */ |
||
| 137 | public function getProcessedValues() { |
||
| 168 | |||
| 169 | /** |
||
| 170 | * {@inheritdoc} |
||
| 171 | */ |
||
| 172 | public function getProjectPluginRoot() { |
||
| 175 | |||
| 176 | /** |
||
| 177 | * {@inheritdoc} |
||
| 178 | */ |
||
| 179 | public function getRawValues() { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Sets the processed values. |
||
| 185 | * |
||
| 186 | * @return \Drupal\Driver\Plugin\DriverPluginManagerInterface |
||
| 187 | * The field plugin manager. |
||
| 188 | */ |
||
| 189 | protected function getFieldPluginManager() { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * {@inheritdoc} |
||
| 195 | */ |
||
| 196 | public function isConfigProperty() { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Sets the processed values. |
||
| 202 | * |
||
| 203 | * @param array $values |
||
| 204 | * An array of processed field value sets. |
||
| 205 | */ |
||
| 206 | protected function setProcessedValues(array $values) { |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Set the driver field plugin manager. |
||
| 212 | * |
||
| 213 | * @param mixed $manager |
||
| 214 | * The driver entity plugin manager. |
||
| 215 | * @param string $projectPluginRoot |
||
| 216 | * The directory to search for additional project-specific driver plugins. |
||
| 217 | */ |
||
| 218 | protected function setFieldPluginManager($manager, $projectPluginRoot) { |
||
| 224 | |||
| 225 | } |
||
| 226 |