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 | 1 | class Resource extends Nette\Object implements IResource |
|
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $id; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var IResource|NULL |
||
| 30 | */ |
||
| 31 | protected $parent; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var IResource[] |
||
| 35 | */ |
||
| 36 | protected $children; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string|NULL |
||
| 40 | */ |
||
| 41 | protected $name; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string|NULL |
||
| 45 | */ |
||
| 46 | protected $comment; |
||
| 47 | |||
| 48 | public function __construct(string $id) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | public function setParent(IResource $parent = NULL) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | public function getParent() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | public function setChildren(array $resources) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | public function addChild(IResource $resource) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function getChildren() |
|
| 112 | |||
| 113 | /** |
||
| 114 | * {@inheritdoc} |
||
| 115 | */ |
||
| 116 | public function getResourceId() : string |
||
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | public function setName(string $name) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | public function getName() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | */ |
||
| 140 | public function setComment(string $comment) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * {@inheritdoc} |
||
| 147 | */ |
||
| 148 | public function getComment() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Convert resource object to string |
||
| 155 | * |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | public function __toString() |
||
| 162 | } |
||
| 163 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..