Conditions | 12 |
Paths | 12 |
Total Lines | 32 |
Code Lines | 17 |
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 |
||
96 | public function compileBootableClasses(): void |
||
97 | { |
||
98 | // list app root's |
||
99 | foreach ($this->appRoots as $app) { |
||
100 | $app .= '/Apps/Controller/' . env_name; |
||
101 | $files = File::listFiles($app, ['.php'], true); |
||
102 | foreach ($files as $file) { |
||
103 | // define full class name with namespace |
||
104 | $class = 'Apps\Controller\\' . env_name . '\\' . Str::cleanExtension($file); |
||
105 | // check if class exists (must be loaded over autoloader), boot method exist and this is controller instanceof |
||
106 | if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\Core\Arch\Controller', true)) { |
||
107 | $this->objects[] = $class; |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | // list widget root's |
||
113 | foreach ($this->widgetRoots as $widget) { |
||
114 | $widget .= '/Widgets/' . env_name; |
||
115 | // widgets are packed in directory, classname should be the same with root directory name |
||
116 | $dirs = Directory::scan($widget, GLOB_ONLYDIR, true); |
||
117 | if (!Obj::isArray($dirs)) { |
||
118 | continue; |
||
119 | } |
||
120 | foreach ($dirs as $instance) { |
||
|
|||
121 | $class = 'Widgets\\' . env_name . '\\' . $instance . '\\' . $instance; |
||
122 | if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\Core\Arch\Widget', true)) { |
||
123 | $this->objects[] = $class; |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
148 | } |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.