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 IPCManager extends AppInstance |
||
| 10 | { |
||
| 11 | /** @var */ |
||
| 12 | public $pool; |
||
| 13 | /** @var */ |
||
| 14 | public $conn; |
||
| 15 | /** @var */ |
||
| 16 | public $socketurl; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Setting default config options |
||
| 20 | * Overriden from AppInstance::getConfigDefaults |
||
| 21 | * @return array|bool |
||
| 22 | */ |
||
| 23 | protected function getConfigDefaults() |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Constructor. |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | public function init() |
||
| 45 | |||
| 46 | public function getSocketUrl() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @TODO DESCR |
||
| 53 | */ |
||
| 54 | public function updatedWorkers() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Called when application instance is going to shutdown. |
||
| 95 | * @param bool $graceful |
||
| 96 | * @return boolean Ready to shutdown? |
||
| 97 | */ |
||
| 98 | public function onShutdown($graceful = false) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @TODO DESCR |
||
| 108 | * @param $workerId |
||
| 109 | * @param $path |
||
| 110 | * @return bool |
||
| 111 | */ |
||
| 112 | public function importFile($workerId, $path) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @TODO DESCR |
||
| 124 | */ |
||
| 125 | public function ensureConnection() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @TODO DESCR |
||
| 132 | * @param $packet |
||
| 133 | */ |
||
| 134 | public function sendPacket($packet = null) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @TODO DESCR |
||
| 153 | * @param $appInstance |
||
| 154 | * @param $method |
||
| 155 | * @param array $args |
||
| 156 | * @param callable $cb |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function sendBroadcastCall($appInstance, $method, $args = [], $cb = null) |
|
| 167 | |||
| 168 | /** |
||
| 169 | * @TODO DESCR |
||
| 170 | * @param $appInstance |
||
| 171 | * @param $method |
||
| 172 | * @param array $args |
||
| 173 | * @param callable $cb |
||
| 174 | */ |
||
| 175 | View Code Duplication | public function sendSingleCall($appInstance, $method, $args = [], $cb = null) |
|
| 184 | |||
| 185 | /** |
||
| 186 | * @TODO DESCR |
||
| 187 | * @param $workerId |
||
| 188 | * @param $appInstance |
||
| 189 | * @param $method |
||
| 190 | * @param array $args |
||
| 191 | * @param callable $cb |
||
| 192 | */ |
||
| 193 | public function sendDirectCall($workerId, $appInstance, $method, $args = [], $cb = null) |
||
| 203 | } |
||
| 204 |
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: