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 |
||
| 35 | class Taxonomy |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * The Taxonomy identifier |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $id; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The taxonomy object |
||
| 45 | * @var object |
||
| 46 | */ |
||
| 47 | protected $taxonomy; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Taxonomy Constructor. |
||
| 51 | * |
||
| 52 | * @param object $taxonomy The taxonomy object |
||
| 53 | */ |
||
| 54 | public function __construct($taxonomy) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Create a new instance using the taxonomy identifier. |
||
| 66 | * |
||
| 67 | * @param string $identifier Taxonomy name/identifier |
||
| 68 | * |
||
| 69 | * @return static |
||
| 70 | */ |
||
| 71 | public static function make($identifier) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Check if the given taxonomy exists. |
||
| 78 | * |
||
| 79 | * @param string $identifier The taxonomy identifier |
||
| 80 | * |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | public static function exists($identifier) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Start a new query for terms of this taxonomy. |
||
| 90 | * |
||
| 91 | * @return TermQueryBuilder |
||
| 92 | */ |
||
| 93 | public function terms() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Get all post types associated with this taxonomy. |
||
| 100 | * |
||
| 101 | * @return Collection |
||
| 102 | */ |
||
| 103 | public function postTypes() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Unregister the taxonomy. |
||
| 113 | * |
||
| 114 | * @return $this |
||
| 115 | */ |
||
| 116 | View Code Duplication | public function unregister() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Magic Getter. |
||
| 131 | * |
||
| 132 | * @param string $property Accessed property |
||
| 133 | * |
||
| 134 | * @return mixed |
||
| 135 | */ |
||
| 136 | public function __get($property) |
||
| 146 | } |
||
| 147 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: