| Total Complexity | 51 |
| Total Lines | 421 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like StaticPathRepository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use StaticPathRepository, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class StaticPathRepository |
||
| 10 | {
|
||
| 11 | /** |
||
| 12 | * @param null $app |
||
|
|
|||
| 13 | * @return string |
||
| 14 | */ |
||
| 15 | public function app($app=null) |
||
| 16 | {
|
||
| 17 | $app=($app===null) ? $this->appDetector() : $app; |
||
| 18 | return StaticPathModel::appPath().''.DIRECTORY_SEPARATOR.''.Str::slashToBackSlash($app); |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return mixed |
||
| 23 | */ |
||
| 24 | public function autoloadNamespace() |
||
| 25 | {
|
||
| 26 | return root.''.DIRECTORY_SEPARATOR.''.StaticPathList::$appDefine.''.DIRECTORY_SEPARATOR.''.strtolower(StaticPathList::$autoloadNamespace); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | public function appBuilder() |
||
| 33 | {
|
||
| 34 | return path()->model().''.DIRECTORY_SEPARATOR.''.StaticPathList::$builder; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param null $app |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public function appCall($app=null) |
||
| 42 | {
|
||
| 43 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$controller; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param null $app |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | public function appCommand() |
||
| 51 | {
|
||
| 52 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$command.''; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param null $app |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function appConfig($app=null) |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param null $app |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | public function appHelpers($app=null) |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function appTests() |
||
| 80 | {
|
||
| 81 | return $this->app().''.DIRECTORY_SEPARATOR.''.StaticPathList::$test; |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | public function appWorkers() |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | public function appSchedule() |
||
| 96 | {
|
||
| 97 | return $this->appVersion(null).''.DIRECTORY_SEPARATOR.''.StaticPathList::$schedule; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return null|string |
||
| 102 | */ |
||
| 103 | private function appDetector() |
||
| 104 | {
|
||
| 105 | return (defined('app')) ? app : null;
|
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param null $app |
||
| 110 | * @return mixed |
||
| 111 | */ |
||
| 112 | public function appFactory($app=null) |
||
| 113 | {
|
||
| 114 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$factory; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return mixed|string |
||
| 119 | */ |
||
| 120 | public function appKernel() |
||
| 121 | {
|
||
| 122 | $kernel = $this->app().''.DIRECTORY_SEPARATOR.''.StaticPathList::$kernel; |
||
| 123 | |||
| 124 | return $kernel; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return mixed|string |
||
| 129 | */ |
||
| 130 | public function appProvider() |
||
| 131 | {
|
||
| 132 | $kernel = $this->app().''.DIRECTORY_SEPARATOR.''.StaticPathList::$kernel.''.DIRECTORY_SEPARATOR.''.StaticPathList::$provider; |
||
| 133 | |||
| 134 | return $kernel; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function appLanguage() |
||
| 141 | {
|
||
| 142 | return self::appStorage().''.DIRECTORY_SEPARATOR.''.StaticPathList::$language; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | public function appLog() |
||
| 149 | {
|
||
| 150 | return self::appStorage().''.DIRECTORY_SEPARATOR.''.StaticPathList::$log; |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param null $app |
||
| 155 | * @return mixed |
||
| 156 | */ |
||
| 157 | public function appLogger($app=null) |
||
| 158 | {
|
||
| 159 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.'ServiceLogManager'; |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param null $app |
||
| 164 | * @return mixed |
||
| 165 | */ |
||
| 166 | public function appMiddleware($app=null) |
||
| 167 | {
|
||
| 168 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$middleware; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param null $app |
||
| 173 | * @return mixed |
||
| 174 | */ |
||
| 175 | public function appMigration($app=null) |
||
| 176 | {
|
||
| 177 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$migration; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param null $app |
||
| 182 | * @return mixed |
||
| 183 | */ |
||
| 184 | public function appModel($app=null) |
||
| 185 | {
|
||
| 186 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$model; |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param null $app |
||
| 191 | * @return mixed |
||
| 192 | */ |
||
| 193 | public function appException($app=null) |
||
| 194 | {
|
||
| 195 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$exception; |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param null $app |
||
| 200 | * @return mixed |
||
| 201 | */ |
||
| 202 | public function appOptionalEvents($app=null) |
||
| 203 | {
|
||
| 204 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$events; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param null $app |
||
| 209 | * @return mixed |
||
| 210 | */ |
||
| 211 | public function appOptionalJob($app=null) |
||
| 212 | {
|
||
| 213 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$optional.''.DIRECTORY_SEPARATOR.''.StaticPathList::$job; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param null $app |
||
| 218 | * @return mixed |
||
| 219 | */ |
||
| 220 | public function appOptionalListeners($app=null) |
||
| 221 | {
|
||
| 222 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$listeners; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @param null $app |
||
| 227 | * @return mixed |
||
| 228 | */ |
||
| 229 | public function appOptionalSubscribers($app=null) |
||
| 230 | {
|
||
| 231 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$listeners.''.DIRECTORY_SEPARATOR.''.StaticPathList::$subscribers; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return mixed |
||
| 236 | */ |
||
| 237 | public function appRequest() |
||
| 238 | {
|
||
| 239 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$request; |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return mixed |
||
| 244 | */ |
||
| 245 | public function appRepository() |
||
| 246 | {
|
||
| 247 | $repository = $this->app().''.DIRECTORY_SEPARATOR.''.StaticPathList::$repository; |
||
| 248 | |||
| 249 | return $repository; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @return mixed |
||
| 254 | */ |
||
| 255 | public function appRoute() |
||
| 256 | {
|
||
| 257 | return $this->appVersion().''.DIRECTORY_SEPARATOR.''.StaticPathList::$route; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @param null $app |
||
| 262 | * @return mixed |
||
| 263 | */ |
||
| 264 | public function appOptionalSource($app=null) |
||
| 265 | {
|
||
| 266 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$optional.''.DIRECTORY_SEPARATOR.''.StaticPathList::$sourcePath; |
||
| 267 | } |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param null $app |
||
| 271 | * @return mixed |
||
| 272 | */ |
||
| 273 | public function appOptionalWebservice($app=null) |
||
| 274 | {
|
||
| 275 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$optional.''.DIRECTORY_SEPARATOR.''.StaticPathList::$webservice; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return mixed |
||
| 280 | */ |
||
| 281 | public function appResourche() |
||
| 282 | {
|
||
| 283 | return self::appStorage().''.DIRECTORY_SEPARATOR.''.StaticPathList::$resource; |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param null $app |
||
| 288 | * @return mixed |
||
| 289 | */ |
||
| 290 | public function appServiceAnnotations($app=null) |
||
| 291 | {
|
||
| 292 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$serviceAnnotations; |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param null $app |
||
| 297 | * @return mixed |
||
| 298 | */ |
||
| 299 | public function appServiceContainer($app=null) |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @param null $app |
||
| 306 | * @return mixed |
||
| 307 | */ |
||
| 308 | public function appServiceEventDispatcher($app=null) |
||
| 309 | {
|
||
| 310 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.'ServiceEventDispatcherManager'; |
||
| 311 | } |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @param null $app |
||
| 315 | * @return mixed |
||
| 316 | */ |
||
| 317 | public function appServiceMiddleware($app=null) |
||
| 318 | {
|
||
| 319 | return $this->appVersion($app).''.DIRECTORY_SEPARATOR.''.StaticPathList::$serviceMiddleware; |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return mixed |
||
| 324 | */ |
||
| 325 | public function appStorage() |
||
| 326 | {
|
||
| 327 | $storage = $this->app().''.DIRECTORY_SEPARATOR.''.StaticPathList::$storage; |
||
| 328 | |||
| 329 | return $storage; |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return mixed |
||
| 334 | */ |
||
| 335 | public function appStubs() |
||
| 336 | {
|
||
| 337 | return $this->appKernel().''.DIRECTORY_SEPARATOR.''.StaticPathList::$stub; |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @param null $app |
||
| 342 | * @return mixed |
||
| 343 | */ |
||
| 344 | public function appVersion($app=null) |
||
| 345 | {
|
||
| 346 | if(defined('app')){
|
||
| 347 | |||
| 348 | $prefixGroup = Str::slashToBackSlash(StaticPathList::$projectPrefixGroup); |
||
| 349 | |||
| 350 | $app = $this->app($app).''.DIRECTORY_SEPARATOR.''.$prefixGroup.''.DIRECTORY_SEPARATOR.''.UrlVersionIdentifier::version(); |
||
| 351 | |||
| 352 | return $app; |
||
| 353 | |||
| 354 | } |
||
| 355 | return null; |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @return string |
||
| 360 | */ |
||
| 361 | public function bootDir() |
||
| 362 | {
|
||
| 363 | //get boot directory for application |
||
| 364 | return root.''.DIRECTORY_SEPARATOR.''.StaticPathList::$appDefine.''.DIRECTORY_SEPARATOR.''.strtolower(StaticPathList::$boot); |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @return string |
||
| 369 | */ |
||
| 370 | public function storeConfigDir() |
||
| 371 | {
|
||
| 372 | //get store config directory for application |
||
| 373 | return $this->storeDir().'/Config'; |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | public function storeDir() |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param null $controller |
||
| 387 | * @param bool $bool |
||
| 388 | * @return mixed |
||
| 389 | */ |
||
| 390 | public function controller($controller=null,$bool=false) |
||
| 391 | {
|
||
| 392 | $namespaceController = ($controller===null) ? app()->namespace()->controller() |
||
| 393 | : app()->namespace()->controller($controller,true); |
||
| 394 | |||
| 395 | if($bool){
|
||
| 396 | $namespaceControllerExplode = explode("\\",$namespaceController);
|
||
| 397 | array_pop($namespaceControllerExplode); |
||
| 398 | |||
| 399 | $namespaceController = implode("\\",$namespaceControllerExplode);
|
||
| 400 | } |
||
| 401 | |||
| 402 | return Utils::getPathFromNamespace($namespaceController,false); |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return mixed |
||
| 407 | */ |
||
| 408 | public function encrypterFile() |
||
| 409 | {
|
||
| 410 | return StaticPathModel::getEncrypter(); |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @return mixed |
||
| 415 | */ |
||
| 416 | public function environmentFile() |
||
| 419 | } |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param $name |
||
| 423 | * @param $arg |
||
| 424 | * @return mixed |
||
| 425 | */ |
||
| 426 | public function __call($name,$arg) |
||
| 427 | {
|
||
| 428 | $appCall='app'.ucfirst($name); |
||
| 429 | return $this->{$appCall}();
|
||
| 430 | } |
||
| 431 | |||
| 432 | } |