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 |
||
34 | class Github |
||
35 | { |
||
36 | /** |
||
37 | * @var array Options for the GitHub object. |
||
38 | * @since 1.0 |
||
39 | */ |
||
40 | protected $options; |
||
41 | |||
42 | /** |
||
43 | * @var Http The HTTP client object to use in sending HTTP requests. |
||
44 | * @since 1.0 |
||
45 | */ |
||
46 | protected $client; |
||
47 | |||
48 | /** |
||
49 | * Constructor. |
||
50 | * |
||
51 | * @param Registry $options GitHub options object. |
||
52 | * @param Http $client The HTTP client object. |
||
53 | * |
||
54 | * @since 1.0 |
||
55 | */ |
||
56 | public function __construct(Registry $options = null, Http $client = null) |
||
67 | |||
68 | /** |
||
69 | * Magic method to lazily create API objects |
||
70 | * |
||
71 | * @param string $name Name of property to retrieve |
||
72 | * |
||
73 | * @return Object GitHub API object (gists, issues, pulls, etc). |
||
74 | * |
||
75 | * @since 1.0 |
||
76 | * @throws \InvalidArgumentException If $name is not a valid sub class. |
||
77 | */ |
||
78 | public function __get($name) |
||
94 | |||
95 | /** |
||
96 | * Get an option from the GitHub instance. |
||
97 | * |
||
98 | * @param string $key The name of the option to get. |
||
99 | * |
||
100 | * @return mixed The option value. |
||
101 | * |
||
102 | * @since 1.0 |
||
103 | */ |
||
104 | public function getOption($key) |
||
108 | |||
109 | /** |
||
110 | * Set an option for the GitHub instance. |
||
111 | * |
||
112 | * @param string $key The name of the option to set. |
||
113 | * @param mixed $value The option value to set. |
||
114 | * |
||
115 | * @return GitHub This object for method chaining. |
||
116 | * |
||
117 | * @since 1.0 |
||
118 | */ |
||
119 | public function setOption($key, $value) |
||
125 | } |
||
126 |
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..