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 |
||
| 39 | class Jaxon |
||
| 40 | { |
||
| 41 | use \Jaxon\Utils\Traits\Config; |
||
| 42 | use \Jaxon\Utils\Traits\Manager; |
||
| 43 | use \Jaxon\Utils\Traits\Translator; |
||
| 44 | use \Jaxon\Utils\Traits\Paginator; |
||
| 45 | |||
| 46 | use Traits\Autoload; |
||
| 47 | use Traits\Plugin; |
||
| 48 | use Traits\Upload; |
||
| 49 | use Traits\Sentry; |
||
| 50 | use Traits\Template; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Package version number |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $sVersion = 'Jaxon 3.0.0'; |
||
| 58 | |||
| 59 | /* |
||
| 60 | * Processing events |
||
| 61 | */ |
||
| 62 | const PROCESSING_EVENT = 'ProcessingEvent'; |
||
| 63 | const PROCESSING_EVENT_BEFORE = 'BeforeProcessing'; |
||
| 64 | const PROCESSING_EVENT_AFTER = 'AfterProcessing'; |
||
| 65 | const PROCESSING_EVENT_INVALID = 'InvalidRequest'; |
||
| 66 | const PROCESSING_EVENT_ERROR = 'ProcessingError'; |
||
| 67 | |||
| 68 | /* |
||
| 69 | * Request methods |
||
| 70 | */ |
||
| 71 | const METHOD_UNKNOWN = 0; |
||
| 72 | const METHOD_GET = 1; |
||
| 73 | const METHOD_POST = 2; |
||
| 74 | |||
| 75 | /* |
||
| 76 | * Request plugins |
||
| 77 | */ |
||
| 78 | // For objects who's methods will be callable from the browser. |
||
| 79 | const CALLABLE_CLASS = 'CallableClass'; |
||
| 80 | const CALLABLE_DIR = 'CallableDir'; |
||
| 81 | const CALLABLE_OBJECT = 'CallableClass'; // Same as CALLABLE_CLASS |
||
| 82 | // For functions available at global scope, or from an instance of an object. |
||
| 83 | const USER_FUNCTION = 'UserFunction'; |
||
| 84 | // For uploaded files. |
||
| 85 | const FILE_UPLOAD = 'FileUpload'; |
||
| 86 | |||
| 87 | /* |
||
| 88 | * Request parameters |
||
| 89 | */ |
||
| 90 | // Specifies that the parameter will consist of an array of form values. |
||
| 91 | const FORM_VALUES = 'FormValues'; |
||
| 92 | // Specifies that the parameter will contain the value of an input control. |
||
| 93 | const INPUT_VALUE = 'InputValue'; |
||
| 94 | // Specifies that the parameter will consist of a boolean value of a checkbox. |
||
| 95 | const CHECKED_VALUE = 'CheckedValue'; |
||
| 96 | // Specifies that the parameter value will be the innerHTML value of the element. |
||
| 97 | const ELEMENT_INNERHTML = 'ElementInnerHTML'; |
||
| 98 | // Specifies that the parameter will be a quoted value (string). |
||
| 99 | const QUOTED_VALUE = 'QuotedValue'; |
||
| 100 | // Specifies that the parameter will be a boolean value (true or false). |
||
| 101 | const BOOL_VALUE = 'BoolValue'; |
||
| 102 | // Specifies that the parameter will be a numeric, non-quoted value. |
||
| 103 | const NUMERIC_VALUE = 'NumericValue'; |
||
| 104 | // Specifies that the parameter will be a non-quoted value |
||
| 105 | // (evaluated by the browsers javascript engine at run time). |
||
| 106 | const JS_VALUE = 'UnquotedValue'; |
||
| 107 | // Specifies that the parameter will be an integer used to generate pagination links. |
||
| 108 | const PAGE_NUMBER = 'PageNumber'; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Processing event handlers that have been assigned during this run of the script |
||
| 112 | * |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | private $aProcessingEvents = []; |
||
| 116 | |||
| 117 | public function __construct() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The current Jaxon version |
||
| 124 | * |
||
| 125 | * @return string |
||
| 126 | */ |
||
| 127 | public function getVersion() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Get the config reader |
||
| 134 | * |
||
| 135 | * @return Jaxon\Config\Reader |
||
| 136 | */ |
||
| 137 | public function config() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Set the default options of all components of the library |
||
| 144 | * |
||
| 145 | * @return void |
||
| 146 | */ |
||
| 147 | private function setDefaultOptions() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Register request handlers, including functions, callable classes and directories. |
||
| 183 | * |
||
| 184 | * @param string $sType The type of request handler being registered |
||
| 185 | * Options include: |
||
| 186 | * - Jaxon::USER_FUNCTION: a function declared at global scope |
||
| 187 | * - Jaxon::CALLABLE_CLASS: a class who's methods are to be registered |
||
| 188 | * - Jaxon::CALLABLE_DIR: a directory containing classes to be registered |
||
| 189 | * @param string $sCallable |
||
| 190 | * When registering a function, this is the name of the function |
||
| 191 | * When registering a callable class, this is the class name |
||
| 192 | * When registering a callable directory, this is the full path to the directory |
||
| 193 | * @param array|string $aOptions | $sIncludeFile | $sNamespace |
||
| 194 | * When registering a function, this is an (optional) array |
||
| 195 | * of call options, or the (optional) include file |
||
| 196 | * When registering a callable class, this is an (optional) array |
||
| 197 | * of call options for the class methods |
||
| 198 | * When registering a callable directory, this is an (optional) array |
||
| 199 | * of call options for the class methods, or the (optional) namespace |
||
| 200 | * |
||
| 201 | * @return mixed |
||
| 202 | */ |
||
| 203 | public function register($sType, $sCallable, $aOptions = []) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Read config options from a config file and setup the library |
||
| 210 | * |
||
| 211 | * @param string $sConfigFile The full path to the config file |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function setup($sConfigFile) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Returns the Jaxon Javascript header and wrapper code to be printed into the page |
||
| 234 | * |
||
| 235 | * The javascript code returned by this function is dependent on the plugins |
||
| 236 | * that are included and the functions and classes that are registered. |
||
| 237 | * |
||
| 238 | * @param boolean $bIncludeJs Also get the JS files |
||
| 239 | * @param boolean $bIncludeCss Also get the CSS files |
||
| 240 | * |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function getScript($bIncludeJs = false, $bIncludeCss = false) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Print the jaxon Javascript header and wrapper code into your page |
||
| 264 | * |
||
| 265 | * The javascript code returned by this function is dependent on the plugins |
||
| 266 | * that are included and the functions and classes that are registered. |
||
| 267 | * |
||
| 268 | * @param boolean $bIncludeJs Also print the JS files |
||
| 269 | * @param boolean $bIncludeCss Also print the CSS files |
||
| 270 | * |
||
| 271 | * @return void |
||
| 272 | */ |
||
| 273 | public function printScript($bIncludeJs = false, $bIncludeCss = false) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Return the javascript header code and file includes |
||
| 280 | * |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function getJs() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Return the CSS header code and file includes |
||
| 290 | * |
||
| 291 | * @return string |
||
| 292 | */ |
||
| 293 | public function getCss() |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Determine if a call is a jaxon request or a page load request |
||
| 300 | * |
||
| 301 | * @return boolean |
||
| 302 | */ |
||
| 303 | public function canProcessRequest() |
||
| 307 | |||
| 308 | /** |
||
| 309 | * If this is a jaxon request, call the requested PHP function, build the response and send it back to the browser |
||
| 310 | * |
||
| 311 | * This is the main server side engine for Jaxon. |
||
| 312 | * It handles all the incoming requests, including the firing of events and handling of the response. |
||
| 313 | * If your RequestURI is the same as your web page, then this function should be called before ANY |
||
| 314 | * headers or HTML is output from your script. |
||
| 315 | * |
||
| 316 | * This function may exit after the request is processed, if the 'core.process.exit' option is set to true. |
||
| 317 | * |
||
| 318 | * @return void |
||
| 319 | * |
||
| 320 | * @see <Jaxon\Jaxon->canProcessRequest> |
||
| 321 | */ |
||
| 322 | public function processRequest() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Send the response output back to the browser |
||
| 427 | * |
||
| 428 | * @return void |
||
| 429 | */ |
||
| 430 | public function sendResponse() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Send the HTTP headers back to the browser |
||
| 437 | * |
||
| 438 | * @return void |
||
| 439 | */ |
||
| 440 | public function sendHeaders() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Get the response output |
||
| 447 | * |
||
| 448 | * @return string |
||
| 449 | */ |
||
| 450 | public function getOutput() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Get the DI container |
||
| 457 | * |
||
| 458 | * @return Jaxon\DI\Container |
||
| 459 | */ |
||
| 460 | public function di() |
||
| 464 | } |
||
| 465 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.