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 |
||
11 | class Pool extends \PHPDaemon\Network\Client |
||
12 | { |
||
13 | /** |
||
14 | * @var Connection[] |
||
15 | */ |
||
16 | public $servConnSub = []; |
||
17 | |||
18 | protected $currentMasterAddr; |
||
19 | |||
20 | /** |
||
21 | * @TODO |
||
22 | * @param string $key |
||
23 | * @param integer $timeout |
||
24 | * @return Lock |
||
25 | */ |
||
26 | public function lock($key, $timeout) |
||
30 | |||
31 | /** |
||
32 | * Easy wrapper for queue of eval's |
||
33 | * @param callable $cb |
||
|
|||
34 | * @return MultiEval |
||
35 | */ |
||
36 | public function meval($cb = null) |
||
40 | |||
41 | /** |
||
42 | * Wrapper for scans commands |
||
43 | * @param string $cmd Command |
||
44 | * @param array $args Arguments |
||
45 | * @param cllable $cbEnd Callback |
||
46 | * @param integer $limit Limit |
||
47 | * @return AutoScan |
||
48 | */ |
||
49 | public function autoscan($cmd, $args = [], $cbEnd = null, $limit = null) |
||
53 | |||
54 | /** |
||
55 | * @param string $chan |
||
56 | * @return integer |
||
57 | */ |
||
58 | public function getLocalSubscribersCount($chan) |
||
68 | |||
69 | /** |
||
70 | * Magic __call |
||
71 | * Example: |
||
72 | * $redis->lpush('mylist', microtime(true)); |
||
73 | * @param string $name Command name |
||
74 | * @param array $args Arguments |
||
75 | * @return void |
||
76 | */ |
||
77 | public function __call($cmd, $args) |
||
111 | |||
112 | /** |
||
113 | * @TODO |
||
114 | * @param string $cmd |
||
115 | * @param array $args |
||
116 | * @param callable $cb |
||
117 | * @callback $cb ( ) |
||
118 | * @return boolean |
||
119 | */ |
||
120 | protected function sendSubCommand($cmd, $args, $cb) |
||
130 | |||
131 | /** |
||
132 | * @TODO |
||
133 | * @param string $addr |
||
134 | * @param string $cmd |
||
135 | * @param array $args |
||
136 | * @param callable $cb |
||
137 | * @callback $cb ( ) |
||
138 | * @return void |
||
139 | */ |
||
140 | protected function sendCommand($addr, $cmd, $args, $cb) |
||
157 | |||
158 | /** |
||
159 | * Setting default config options |
||
160 | * Overriden from NetworkClient::getConfigDefaults |
||
161 | * @return array|bool |
||
162 | */ |
||
163 | protected function getConfigDefaults() |
||
188 | } |
||
189 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.