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 |
||
| 13 | class Application |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @const ERR_CALL_UNKNOWN_METHOD Exception code if __call is called with |
||
| 17 | * an unmanaged method |
||
| 18 | */ |
||
| 19 | const ERR_CALL_UNKNOWN_METHOD = 1301001; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @const ERR_CALL_UNKNOWN_PROPERTY Exception code if __call is called with |
||
| 23 | * an unmanaged property |
||
| 24 | */ |
||
| 25 | const ERR_CALL_UNKNOWN_PROPERTY = 1301002; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var \BFW\Application|null $instance Application instance (Singleton) |
||
| 29 | */ |
||
| 30 | protected static $instance = null; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \BFW\Core\AppSystems\SystemInterface[] $coreSystemList A list of |
||
| 34 | * all core system to init and run |
||
| 35 | */ |
||
| 36 | protected $coreSystemList = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var array $declaredOptions All options passed to initSystems method |
||
| 40 | */ |
||
| 41 | protected $declaredOptions = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var \BFW\RunTasks|null All method tu exec during run |
||
| 45 | */ |
||
| 46 | protected $runTasks; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Constructor |
||
| 50 | * Init output buffering |
||
| 51 | * Declare core systems |
||
| 52 | * Set UTF-8 header |
||
| 53 | * |
||
| 54 | * protected for Singleton pattern |
||
| 55 | */ |
||
| 56 | protected function __construct() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Get the Application instance (Singleton pattern) |
||
| 72 | * |
||
| 73 | * @return \BFW\Application The current instance of this class |
||
| 74 | */ |
||
| 75 | View Code Duplication | public static function getInstance() |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Getter accessor to property coreSystemList |
||
| 87 | * |
||
| 88 | * @return \BFW\Core\AppSystems\SystemInterface[] |
||
| 89 | */ |
||
| 90 | public function getCoreSystemList() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Getter accessor to property declaredOptions |
||
| 97 | * |
||
| 98 | * @return array |
||
| 99 | */ |
||
| 100 | public function getDeclaredOptions() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Getter accessor to property runTasks |
||
| 107 | * |
||
| 108 | * @return \BFW\RunTasks|null |
||
| 109 | */ |
||
| 110 | public function getRunTasks() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * PHP Magic method, called when we call an unexisting method |
||
| 117 | * Only method getXXX are allowed. |
||
| 118 | * The property should be a key (ucfirst for camelcase) of the array |
||
| 119 | * coreSystemList. |
||
| 120 | * Ex: getConfig() or getModuleList() |
||
| 121 | * The value returned will be the returned value of the __invoke method |
||
| 122 | * into the core system class called. |
||
| 123 | * |
||
| 124 | * @param string $name The method name |
||
| 125 | * @param array $arguments The argument passed to the method |
||
| 126 | * |
||
| 127 | * @return mixed |
||
| 128 | * |
||
| 129 | * @throws \Exception If the method is not allowed or if the property |
||
| 130 | * not exist. |
||
| 131 | */ |
||
| 132 | public function __call($name, $arguments) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Define the list of coreSystem to init and/or run. |
||
| 156 | * |
||
| 157 | * @return void |
||
| 158 | */ |
||
| 159 | protected function defineCoreSystemList() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Initialize all components |
||
| 180 | * |
||
| 181 | * @param array $options Options passed to application |
||
| 182 | * |
||
| 183 | * @return void |
||
| 184 | */ |
||
| 185 | public function initSystems($options) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Init all core system declared, only if they have not been already init. |
||
| 211 | * If the system should be run, we add him to the runTasks object. |
||
| 212 | * |
||
| 213 | * @param string $name The core system name |
||
| 214 | * @param \BFW\Core\AppSystems\SystemInterface $coreSystem The core system |
||
| 215 | * instance. |
||
| 216 | * |
||
| 217 | * @return void |
||
| 218 | */ |
||
| 219 | protected function initCoreSystem($name, SystemInterface $coreSystem) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Run the application |
||
| 239 | * |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | public function run() |
||
| 249 | } |
||
| 250 |
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..