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 Argument |
||
| 53 | */ |
||
| 54 | private $xArgumentManager; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The callbacks to run while processing the request |
||
| 58 | * |
||
| 59 | * @var 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 FileUpload |
||
| 74 | */ |
||
| 75 | private $xUploadRequestPlugin = null; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The constructor |
||
| 79 | * |
||
| 80 | * @param PluginManager $xPluginManager |
||
| 81 | * @param ResponseManager $xResponseManager |
||
| 82 | * @param FileUpload $xUploadRequestPlugin |
||
| 83 | */ |
||
| 84 | public function __construct(PluginManager $xPluginManager, |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Return the method that was used to send the arguments from the client |
||
| 97 | * |
||
| 98 | * The method is one of: Argument::METHOD_UNKNOWN, Argument::METHOD_GET, Argument::METHOD_POST. |
||
| 99 | * |
||
| 100 | * @return integer |
||
| 101 | */ |
||
| 102 | public function getRequestMethod() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Return true if the current request method is GET |
||
| 109 | * |
||
| 110 | * @return bool |
||
| 111 | */ |
||
| 112 | public function requestMethodIsGet() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Return the array of arguments that were extracted and parsed from the GET or POST data |
||
| 119 | * |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | public function processArguments() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Get the callback handler |
||
| 129 | * |
||
| 130 | * @return Callback |
||
| 131 | */ |
||
| 132 | public function getCallbackManager() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * This is the pre-request processing callback passed to the Jaxon library. |
||
| 139 | * |
||
| 140 | * @param boolean &$bEndRequest if set to true, the request processing is interrupted. |
||
| 141 | * |
||
| 142 | * @return Jaxon\Response\Response the Jaxon response |
||
| 143 | */ |
||
| 144 | View Code Duplication | public function onBefore(&$bEndRequest) |
|
| 152 | |||
| 153 | /** |
||
| 154 | * This is the post-request processing callback passed to the Jaxon library. |
||
| 155 | * |
||
| 156 | * @return Jaxon\Response\Response the Jaxon response |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function onAfter($bEndRequest) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * This callback is called whenever an invalid request is processed. |
||
| 168 | * |
||
| 169 | * @return Jaxon\Response\Response the Jaxon response |
||
| 170 | */ |
||
| 171 | public function onInvalid($sMessage) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * This callback is called whenever an invalid request is processed. |
||
| 181 | * |
||
| 182 | * @return Jaxon\Response\Response the Jaxon response |
||
| 183 | */ |
||
| 184 | public function onError(Exception $xException) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Check if the current request can be processed |
||
| 198 | * |
||
| 199 | * Calls each of the request plugins and determines if the current request can be processed by one of them. |
||
| 200 | * |
||
| 201 | * @return boolean |
||
| 202 | */ |
||
| 203 | public function canProcessRequest() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Process the current request |
||
| 229 | * |
||
| 230 | * Calls each of the request plugins to request that they process the current request. |
||
| 231 | * If any plugin processes the request, it will return true. |
||
| 232 | * |
||
| 233 | * @return boolean |
||
| 234 | */ |
||
| 235 | public function processRequest() |
||
| 327 | } |
||
| 328 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.