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 |
||
| 30 | class Handler |
||
| 31 | { |
||
| 32 | use \Jaxon\Features\Config; |
||
| 33 | use \Jaxon\Features\Translator; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The plugin manager. |
||
| 37 | * |
||
| 38 | * @var PluginManager |
||
| 39 | */ |
||
| 40 | private $xPluginManager; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The response manager. |
||
| 44 | * |
||
| 45 | * @var ResponseManager |
||
| 46 | */ |
||
| 47 | private $xResponseManager; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The arguments handler. |
||
| 51 | * |
||
| 52 | * @var Handler\Argument |
||
| 53 | */ |
||
| 54 | private $xArgumentManager; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The callbacks to run while processing the request |
||
| 58 | * |
||
| 59 | * @var Handler\Callback |
||
| 60 | */ |
||
| 61 | private $xCallbackManager; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The request plugin that is able to process the current request |
||
| 65 | * |
||
| 66 | * @var \Jaxon\Plugin\Request |
||
| 67 | */ |
||
| 68 | private $xTargetRequestPlugin = null; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * The file upload request plugin |
||
| 72 | * |
||
| 73 | * @var \Jaxon\Request\Plugin\Upload |
||
| 74 | */ |
||
| 75 | private $xUploadRequestPlugin = null; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The constructor |
||
| 79 | * |
||
| 80 | * Get and decode the arguments of the HTTP request |
||
| 81 | * |
||
| 82 | * @param PluginManager $xPluginManager |
||
| 83 | * @param ResponseManager $xResponseManager |
||
| 84 | * @param FileUpload $xUploadRequestPlugin |
||
| 85 | */ |
||
| 86 | public function __construct(PluginManager $xPluginManager, |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Return the method that was used to send the arguments from the client |
||
| 99 | * |
||
| 100 | * The method is one of: Handler\Argument::METHOD_UNKNOWN, Handler\Argument::METHOD_GET, Handler\Argument::METHOD_POST. |
||
| 101 | * |
||
| 102 | * @return integer |
||
| 103 | */ |
||
| 104 | public function getRequestMethod() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Return true if the current request method is GET |
||
| 111 | * |
||
| 112 | * @return bool |
||
| 113 | */ |
||
| 114 | public function requestMethodIsGet() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Return the array of arguments that were extracted and parsed from the GET or POST data |
||
| 121 | * |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | public function processArguments() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Get the callback handler |
||
| 131 | * |
||
| 132 | * @return Handler\Callback |
||
| 133 | */ |
||
| 134 | public function getCallbackManager() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * This is the pre-request processing callback passed to the Jaxon library. |
||
| 141 | * |
||
| 142 | * @param boolean &$bEndRequest if set to true, the request processing is interrupted. |
||
| 143 | * |
||
| 144 | * @return Jaxon\Response\Response the Jaxon response |
||
| 145 | */ |
||
| 146 | View Code Duplication | public function onBefore(&$bEndRequest) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * This is the post-request processing callback passed to the Jaxon library. |
||
| 158 | * |
||
| 159 | * @return Jaxon\Response\Response the Jaxon response |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function onAfter($bEndRequest) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * This callback is called whenever an invalid request is processed. |
||
| 172 | * |
||
| 173 | * @return Jaxon\Response\Response the Jaxon response |
||
| 174 | */ |
||
| 175 | public function onInvalid($sMessage) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * This callback is called whenever an invalid request is processed. |
||
| 186 | * |
||
| 187 | * @return Jaxon\Response\Response the Jaxon response |
||
| 188 | */ |
||
| 189 | public function onError(Exception $xException) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Check if the current request can be processed |
||
| 204 | * |
||
| 205 | * Calls each of the request plugins and determines if the current request can be processed by one of them. |
||
| 206 | * |
||
| 207 | * @return boolean |
||
| 208 | */ |
||
| 209 | public function canProcessRequest() |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Process the current request |
||
| 235 | * |
||
| 236 | * Calls each of the request plugins to request that they process the current request. |
||
| 237 | * If any plugin processes the request, it will return true. |
||
| 238 | * |
||
| 239 | * @return boolean |
||
| 240 | */ |
||
| 241 | public function processRequest() |
||
| 333 | } |
||
| 334 |
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..