| Conditions | 16 |
| Paths | 144 |
| Total Lines | 61 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 20 | public function parsePath($path) { |
||
| 21 | $path = Tools::parsePath($path); |
||
| 22 | |||
| 23 | if (strpos($path, '/') === 0) { |
||
| 24 | $path = substr($path, 1); |
||
| 25 | } |
||
| 26 | $app = substr($path, 0, strpos($path, '/')); |
||
| 27 | |||
| 28 | if ($app && file_exists(INJI_SYSTEM_DIR . '/program/' . $app)) { |
||
| 29 | $path = substr($path, strpos($path, '/') + 1); |
||
| 30 | if (App::$cur->name != $app) { |
||
| 31 | $scriptApp = new App(); |
||
| 32 | $scriptApp->name = $app; |
||
| 33 | $scriptApp->system = true; |
||
| 34 | $scriptApp->staticPath = "/" . $scriptApp->name . "/static"; |
||
| 35 | $scriptApp->templatesPath = "/" . $scriptApp->name . "/static/templates"; |
||
| 36 | $scriptApp->path = INJI_SYSTEM_DIR . '/program/' . $scriptApp->name; |
||
| 37 | $scriptApp->type = 'app' . ucfirst(strtolower($scriptApp->name)); |
||
| 38 | $scriptApp->installed = true; |
||
| 39 | $scriptApp->params = []; |
||
| 40 | $scriptApp->config = Config::app($scriptApp); |
||
| 41 | } else { |
||
| 42 | $scriptApp = App::$cur; |
||
| 43 | } |
||
| 44 | } else { |
||
| 45 | $scriptApp = App::$cur->system ? App::$primary : App::$cur; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (strpos($path, 'static/') !== false && strpos($path, 'static/') <= 1) { |
||
| 49 | $path = substr($path, strpos($path, 'static') + 7); |
||
| 50 | } |
||
| 51 | |||
| 52 | $type = substr($path, 0, strpos($path, '/')); |
||
| 53 | switch ($type) { |
||
| 54 | case 'cache': |
||
| 55 | return INJI_BASE_DIR . $path; |
||
| 56 | case 'libs': |
||
| 57 | return App::$cur->Libs->getPath(array_slice(explode('/', $path), 2)); |
||
| 58 | case 'templates': |
||
| 59 | $path = substr($path, strpos($path, '/') + 1); |
||
| 60 | return $scriptApp->view->templatesPath . '/' . $path; |
||
| 61 | case 'system': |
||
| 62 | $path = substr($path, strpos($path, '/') + 1); |
||
| 63 | return INJI_SYSTEM_DIR . '/static/' . $path; |
||
| 64 | case 'moduleAsset': |
||
| 65 | $path = substr($path, strpos($path, '/') + 1); |
||
| 66 | if (!strpos($path, '/')) { |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | $module = substr($path, 0, strpos($path, '/')); |
||
| 70 | |||
| 71 | if (!$scriptApp->$module) { |
||
| 72 | return false; |
||
| 73 | } |
||
| 74 | $path = substr($path, strpos($path, '/') + 1); |
||
| 75 | if (is_callable([$module, 'staticCalled'])) { |
||
| 76 | return $scriptApp->$module->staticCalled($path, $scriptApp->$module->path . '/static/'); |
||
| 77 | } |
||
| 78 | return $scriptApp->$module->path . '/static/' . $path; |
||
| 79 | default: |
||
| 80 | return $scriptApp->path . '/static/' . $path; |
||
| 81 | } |
||
| 194 | } |