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 |
||
13 | class Route implements RouteInterface |
||
14 | { |
||
15 | use \PHPDaemon\Traits\StaticObjectWatchdog; |
||
16 | use \PHPDaemon\Traits\Sessions; |
||
17 | use \PHPDaemon\Traits\DeferredEventHandlers; |
||
18 | |||
19 | public $attrs; |
||
20 | |||
21 | /** |
||
22 | * @var \PHPDaemon\Servers\WebSocket\Connection |
||
23 | */ |
||
24 | public $client; // Remote client |
||
25 | /** |
||
26 | * @var \PHPDaemon\Core\AppInstance |
||
27 | */ |
||
28 | public $appInstance; |
||
29 | |||
30 | protected $running = true; |
||
31 | |||
32 | /** |
||
33 | * Called when client connected. |
||
34 | * @param \PHPDaemon\Servers\WebSocket\Connection $client Remote client |
||
35 | * @param \PHPDaemon\Core\AppInstance $appInstance |
||
|
|||
36 | */ |
||
37 | public function __construct($client, $appInstance = null) |
||
51 | |||
52 | /** |
||
53 | * Set the cookie |
||
54 | * @param string $name Name of cookie |
||
55 | * @param string $value Value |
||
56 | * @param integer $maxage Optional. Max-Age. Default is 0. |
||
57 | * @param string $path Optional. Path. Default is empty string. |
||
58 | * @param string $domain Optional. Domain. Default is empty string. |
||
59 | * @param boolean $secure Optional. Secure. Default is false. |
||
60 | * @param boolean $HTTPOnly Optional. HTTPOnly. Default is false. |
||
61 | * @return void |
||
62 | */ |
||
63 | View Code Duplication | public function setcookie( |
|
82 | |||
83 | /** |
||
84 | * Called when the request wakes up |
||
85 | * @return void |
||
86 | */ |
||
87 | public function onWakeup() |
||
97 | |||
98 | /** |
||
99 | * Called when the request starts sleep |
||
100 | * @return void |
||
101 | */ |
||
102 | public function onSleep() |
||
109 | |||
110 | /** |
||
111 | * Called when the connection is handshaked. |
||
112 | * @return void |
||
113 | */ |
||
114 | public function onHandshake() |
||
117 | |||
118 | /** |
||
119 | * Called when new frame is received |
||
120 | * @param string $data Frame's contents |
||
121 | * @param integer $type Frame's type |
||
122 | * @return void |
||
123 | */ |
||
124 | public function onFrame($data, $type) |
||
127 | |||
128 | /** |
||
129 | * Uncaught exception handler |
||
130 | * @param $e |
||
131 | * @return boolean Handled? |
||
132 | */ |
||
133 | public function handleException($e) |
||
137 | |||
138 | /** |
||
139 | * Called when session finished. |
||
140 | * @return void |
||
141 | */ |
||
142 | public function onFinish() |
||
146 | |||
147 | /** |
||
148 | * Called when the worker is going to shutdown. |
||
149 | * @return boolean Ready to shutdown? |
||
150 | */ |
||
151 | public function gracefulShutdown() |
||
155 | |||
156 | /** |
||
157 | * Get cookie by name |
||
158 | * @param string $name Name of cookie |
||
159 | * @return string Contents |
||
160 | */ |
||
161 | protected function getCookieStr($name) |
||
165 | |||
166 | /** |
||
167 | * Set session state |
||
168 | * @param mixed $var |
||
169 | * @return void |
||
170 | */ |
||
171 | protected function setSessionState($var) |
||
175 | |||
176 | /** |
||
177 | * Get session state |
||
178 | * @return mixed |
||
179 | */ |
||
180 | protected function getSessionState() |
||
184 | } |
||
185 |
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.