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 |
||
9 | class Pool extends \PHPDaemon\Network\Client |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Gets the key |
||
14 | * @param string $key Key |
||
15 | * @param callable $onResponse Callback called when response received |
||
16 | * @callback $onResponse ( ) |
||
17 | * @return void |
||
18 | */ |
||
19 | public function get($key, $onResponse) |
||
23 | |||
24 | /** |
||
25 | * Sets the key |
||
26 | * @param string $key Key |
||
27 | * @param string $value Value |
||
28 | * @param integer $exp Lifetime in seconds (0 - immortal) |
||
29 | * @param callable $onResponse Callback called when the request complete |
||
30 | * @callback $onResponse ( ) |
||
31 | * @return void |
||
32 | */ |
||
33 | View Code Duplication | public function set($key, $value, $exp = 0, $onResponse = null) |
|
50 | |||
51 | /** |
||
52 | * Adds the key |
||
53 | * @param string $key Key |
||
54 | * @param string $value Value |
||
55 | * @param integer $exp Lifetime in seconds (0 - immortal) |
||
56 | * @param callable $onResponse Callback called when the request complete |
||
57 | * @callback $onResponse ( ) |
||
58 | * @return void |
||
59 | */ |
||
60 | View Code Duplication | public function add($key, $value, $exp = 0, $onResponse = null) |
|
74 | |||
75 | /** |
||
76 | * Deletes the key |
||
77 | * @param string $key Key |
||
78 | * @param callable $onResponse Callback called when the request complete |
||
79 | * @param integer $time Time to block this key |
||
80 | * @callback $onResponse ( ) |
||
81 | * @return void |
||
82 | */ |
||
83 | public function delete($key, $onResponse = null, $time = 0) |
||
96 | |||
97 | /** |
||
98 | * Replaces the key |
||
99 | * @param string $key Key |
||
100 | * @param string $value Value |
||
101 | * @param integer $exp Lifetime in seconds (0 - immortal) |
||
102 | * @param callable $onResponse Callback called when the request complete |
||
103 | * @callback $onResponse ( ) |
||
104 | * @return void |
||
105 | */ |
||
106 | View Code Duplication | public function replace($key, $value, $exp = 0, $onResponse = null) |
|
120 | |||
121 | /** |
||
122 | * Appends a string to the key's value |
||
123 | * @param string $key Key |
||
124 | * @param string $value Value |
||
125 | * @param integer $exp Lifetime in seconds (0 - immortal) |
||
126 | * @param callable $onResponse Callback called when the request complete |
||
127 | * @callback $onResponse ( ) |
||
128 | * @return void |
||
129 | */ |
||
130 | View Code Duplication | public function append($key, $value, $exp = 0, $onResponse = null) |
|
144 | |||
145 | /** |
||
146 | * Prepends a string to the key's value |
||
147 | * @param string $key Key |
||
148 | * @param string $value Value |
||
149 | * @param integer $exp Lifetime in seconds (0 - immortal) |
||
150 | * @param callable $onResponse Callback called when the request complete |
||
151 | * @callback $onResponse ( ) |
||
152 | * @return void |
||
153 | */ |
||
154 | View Code Duplication | public function prepend($key, $value, $exp = 0, $onResponse = null) |
|
168 | |||
169 | /** |
||
170 | * Gets a statistics |
||
171 | * @param callable $onResponse Callback called when the request complete |
||
172 | * @param string $server Server |
||
173 | * @return void |
||
174 | */ |
||
175 | public function stats($onResponse, $server = null) |
||
179 | |||
180 | /** |
||
181 | * Setting default config options |
||
182 | * Overriden from NetworkClient::getConfigDefaults |
||
183 | * @return array|bool |
||
184 | */ |
||
185 | protected function getConfigDefaults() |
||
200 | } |
||
201 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.