Conditions | 11 |
Paths | 16 |
Total Lines | 29 |
Code Lines | 15 |
Lines | 23 |
Ratio | 79.31 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
86 | public function compileBootableClasses() |
||
87 | { |
||
88 | // list app root's |
||
89 | View Code Duplication | foreach ($this->appRoots as $app) { |
|
90 | $app .= '/Apps/Controller/' . env_name; |
||
91 | $files = File::listFiles($app, ['.php'], true); |
||
92 | foreach ($files as $file) { |
||
93 | // define full class name with namespace |
||
94 | $class = 'Apps\Controller\\' . env_name . '\\' . Str::cleanExtension($file); |
||
95 | // check if class exists (must be loaded over autoloader), boot method exist and this is controller instanceof |
||
96 | if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\Core\Arch\Controller', true)) { |
||
97 | $this->objects[] = $class; |
||
98 | } |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // list widget root's |
||
103 | View Code Duplication | foreach ($this->widgetRoots as $widget) { |
|
104 | $widget .= '/Widgets/' . env_name; |
||
105 | // widgets are packed in directory, classname should be the same with root directory name |
||
106 | $dirs = Directory::scan($widget, GLOB_ONLYDIR, true); |
||
107 | foreach ($dirs as $instance) { |
||
108 | $class = 'Widgets\\' . env_name . '\\' . $instance . '\\' . $instance; |
||
109 | if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\Core\Arch\Widget', true)) { |
||
110 | $this->objects[] = $class; |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | |||
131 | } |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.