| Conditions | 11 |
| Paths | 25 |
| Total Lines | 26 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 52 | protected function print_cli_structure_internal ($dir, $module_name, $basename, $structure, &$result) { |
||
| 53 | /** @noinspection NestedTernaryOperatorInspection */ |
||
| 54 | foreach ($structure ?: (!$basename ? ['index'] : []) as $path => $nested_structure) { |
||
| 55 | if (!is_array($nested_structure)) { |
||
| 56 | $path = $nested_structure; |
||
| 57 | $nested_structure = []; |
||
| 58 | } |
||
| 59 | $key = $path == '_' ? 0 : $path; |
||
| 60 | if (file_exists("$dir/Controller.php")) { |
||
| 61 | $result[$key] = $this->controller_router_available_methods( |
||
|
1 ignored issue
–
show
|
|||
| 62 | $dir, |
||
| 63 | "\\cs\\modules\\$module_name\\cli\\Controller", |
||
| 64 | $basename ? $basename.'_'.$path : $path |
||
| 65 | ); |
||
| 66 | $new_dir = $dir; |
||
| 67 | $new_basename = $basename ? $basename.'_'.$path : $path; |
||
| 68 | } else { |
||
| 69 | $result[$key] = $this->files_router_available_methods($dir, $path); |
||
|
1 ignored issue
–
show
|
|||
| 70 | $new_dir = "$dir/$path"; |
||
| 71 | $new_basename = $basename; |
||
| 72 | } |
||
| 73 | if ($structure && $nested_structure) { |
||
| 74 | $this->print_cli_structure_internal($new_dir, $module_name, $new_basename, $nested_structure, $result[$key]); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | /** |
||
| 105 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.