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 | |||
| 34 | /** |
||
| 35 | * The plugin manager. |
||
| 36 | * |
||
| 37 | * @var PluginManager |
||
| 38 | */ |
||
| 39 | private $xPluginManager; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The response manager. |
||
| 43 | * |
||
| 44 | * @var ResponseManager |
||
| 45 | */ |
||
| 46 | private $xResponseManager; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The arguments handler. |
||
| 50 | * |
||
| 51 | * @var \Jaxon\Request\Handler\Argument |
||
| 52 | */ |
||
| 53 | private $xArgumentManager; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The callbacks to run while processing the request |
||
| 57 | * |
||
| 58 | * @var \Jaxon\Request\Handler\Callback |
||
| 59 | */ |
||
| 60 | private $xCallbackManager; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The request plugin that is able to process the current request |
||
| 64 | * |
||
| 65 | * @var \Jaxon\Plugin\Request |
||
| 66 | */ |
||
| 67 | private $xTargetRequestPlugin = null; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The file upload request plugin |
||
| 71 | * |
||
| 72 | * @var FileUpload |
||
| 73 | */ |
||
| 74 | private $xUploadRequestPlugin = null; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The constructor |
||
| 78 | * |
||
| 79 | * @param PluginManager $xPluginManager |
||
| 80 | * @param ResponseManager $xResponseManager |
||
| 81 | * @param FileUpload $xUploadRequestPlugin |
||
| 82 | */ |
||
| 83 | public function __construct(PluginManager $xPluginManager, |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Return the method that was used to send the arguments from the client |
||
| 96 | * |
||
| 97 | * The method is one of: Argument::METHOD_UNKNOWN, Argument::METHOD_GET, Argument::METHOD_POST. |
||
| 98 | * |
||
| 99 | * @return integer |
||
| 100 | */ |
||
| 101 | public function getRequestMethod() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Return true if the current request method is GET |
||
| 108 | * |
||
| 109 | * @return bool |
||
| 110 | */ |
||
| 111 | public function requestMethodIsGet() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Return the array of arguments that were extracted and parsed from the GET or POST data |
||
| 118 | * |
||
| 119 | * @return array |
||
| 120 | */ |
||
| 121 | public function processArguments() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Get the callback handler |
||
| 128 | * |
||
| 129 | * @return Callback |
||
| 130 | */ |
||
| 131 | public function getCallbackManager() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * This is the pre-request processing callback passed to the Jaxon library. |
||
| 138 | * |
||
| 139 | * @param boolean &$bEndRequest if set to true, the request processing is interrupted. |
||
| 140 | * |
||
| 141 | * @return Jaxon\Response\Response the Jaxon response |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function onBefore(&$bEndRequest) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * This is the post-request processing callback passed to the Jaxon library. |
||
| 154 | * |
||
| 155 | * @return Jaxon\Response\Response the Jaxon response |
||
| 156 | */ |
||
| 157 | View Code Duplication | public function onAfter($bEndRequest) |
|
| 164 | |||
| 165 | /** |
||
| 166 | * This callback is called whenever an invalid request is processed. |
||
| 167 | * |
||
| 168 | * @return Jaxon\Response\Response the Jaxon response |
||
| 169 | */ |
||
| 170 | public function onInvalid($sMessage) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * This callback is called whenever an invalid request is processed. |
||
| 180 | * |
||
| 181 | * @return Jaxon\Response\Response the Jaxon response |
||
| 182 | */ |
||
| 183 | public function onError(Exception $xException) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Check if the current request can be processed |
||
| 197 | * |
||
| 198 | * Calls each of the request plugins and determines if the current request can be processed by one of them. |
||
| 199 | * |
||
| 200 | * @return boolean |
||
| 201 | */ |
||
| 202 | public function canProcessRequest() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Process the current request and handle errors and exceptions. |
||
| 228 | * |
||
| 229 | * @return void |
||
| 230 | */ |
||
| 231 | private function _processRequest() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Clean output buffers. |
||
| 265 | * |
||
| 266 | * @return void |
||
| 267 | */ |
||
| 268 | private function _cleanOutputBuffers() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Process the current request. |
||
| 280 | * |
||
| 281 | * Calls each of the request plugins to request that they process the current request. |
||
| 282 | * If any plugin processes the request, it will return true. |
||
| 283 | * |
||
| 284 | * @return void |
||
| 285 | */ |
||
| 286 | public function processRequest() |
||
| 327 | } |
||
| 328 |