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 |
||
| 24 | class TemplateProperty extends AbstractProperty implements SelectablePropertyInterface |
||
|
|
|||
| 25 | { |
||
| 26 | use SelectablePropertyTrait; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The available selectable templates. |
||
| 30 | * |
||
| 31 | * @var array|null |
||
| 32 | */ |
||
| 33 | private $availableTemplates; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return string |
||
| 37 | */ |
||
| 38 | public function type() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Inject dependencies from a DI Container. |
||
| 45 | * |
||
| 46 | * @param Container $container A dependencies container instance. |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | public function setDependencies(Container $container) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Set the available choices. |
||
| 61 | * |
||
| 62 | * @param array $choices One or more choice structures. |
||
| 63 | * @return TemplateProperty Chainable. |
||
| 64 | */ |
||
| 65 | public function setChoices(array $choices) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Merge the available choices. |
||
| 78 | * |
||
| 79 | * @param array $choices One or more choice structures. |
||
| 80 | * @return TemplateProperty Chainable. |
||
| 81 | */ |
||
| 82 | public function addChoices(array $choices) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Add a choice to the available choices. |
||
| 95 | * |
||
| 96 | * @param string $choiceIdent The choice identifier (will be key / default ident). |
||
| 97 | * @param string|array $choice A string representing the choice label or a structure. |
||
| 98 | * @return TemplateProperty Chainable. |
||
| 99 | */ |
||
| 100 | public function addChoice($choiceIdent, $choice) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Format the given value for display. |
||
| 113 | * |
||
| 114 | * @param mixed $val The value to to convert for display. |
||
| 115 | * @param array $options Optional display options. |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | public function displayVal($val, array $options = []) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Retrieve the selected template's FQCN. |
||
| 171 | * |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | public function __toString() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return string |
||
| 192 | */ |
||
| 193 | public function sqlExtra() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Get the SQL type (Storage format) |
||
| 200 | * |
||
| 201 | * @return string The SQL type |
||
| 202 | */ |
||
| 203 | public function sqlType() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return integer |
||
| 214 | */ |
||
| 215 | public function sqlPdoType() |
||
| 219 | } |
||
| 220 |