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 |
||
| 20 | class AttributeDecorator |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Server. |
||
| 24 | * |
||
| 25 | * @var Server |
||
| 26 | */ |
||
| 27 | protected $server; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Filesystem. |
||
| 31 | * |
||
| 32 | * @var Filesystem |
||
| 33 | */ |
||
| 34 | protected $fs; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Acl. |
||
| 38 | * |
||
| 39 | * @var Acl |
||
| 40 | */ |
||
| 41 | protected $acl; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Role decorator. |
||
| 45 | * |
||
| 46 | * @var RoleAttributeDecorator |
||
| 47 | */ |
||
| 48 | protected $role_decorator; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Custom attributes. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $custom = []; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Init. |
||
| 59 | * |
||
| 60 | * @param Server $server |
||
| 61 | * @param Acl $acl |
||
| 62 | * @param Decorator $role_decorator |
||
| 63 | */ |
||
| 64 | public function __construct(Server $server, Acl $acl, RoleAttributeDecorator $role_decorator) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Decorate attributes. |
||
| 73 | * |
||
| 74 | * @param NodeInterface $node |
||
| 75 | * @param array $attributes |
||
| 76 | * |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | public function decorate(NodeInterface $node, array $attributes = []): array |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Add decorator. |
||
| 100 | * |
||
| 101 | * @param string $attribute |
||
| 102 | * @param Closure $decorator |
||
| 103 | * |
||
| 104 | * @return AttributeDecorator |
||
| 105 | */ |
||
| 106 | public function addDecorator(string $attribute, Closure $decorator): self |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Get Attributes. |
||
| 115 | * |
||
| 116 | * @param NodeInterface |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | protected function getAttributes(NodeInterface $node, array $attributes): array |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get Attributes. |
||
| 209 | * |
||
| 210 | * @param NodeInterface |
||
| 211 | * @param array $attributes |
||
| 212 | * |
||
| 213 | * @return array |
||
| 214 | */ |
||
| 215 | protected function getTimeAttributes(NodeInterface $node, array $attributes): array |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Get Attributes. |
||
| 243 | * |
||
| 244 | * @param NodeInterface |
||
| 245 | * @param array $attributes |
||
| 246 | * |
||
| 247 | * @return array |
||
| 248 | */ |
||
| 249 | protected function getTypeAttributes(NodeInterface $node, array $attributes): array |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Execute closures. |
||
| 276 | * |
||
| 277 | * @param NodeInterface |
||
| 278 | * @param array $attributes |
||
| 279 | * |
||
| 280 | * @return array |
||
| 281 | */ |
||
| 282 | View Code Duplication | protected function translateAttributes(NodeInterface $node, array $attributes): array |
|
| 300 | } |
||
| 301 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.