| Conditions | 12 |
| Paths | 5 |
| Total Lines | 64 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 56 | public function ls($path) { |
||
| 57 | $arpath = path::collapse($path); |
||
| 58 | |||
| 59 | if ( strpos($arpath, $this->path, 0) !== 0) { |
||
| 60 | return []; |
||
| 61 | } |
||
| 62 | $realpath = $this->config['path'] . substr($arpath,strlen($this->path)); |
||
| 63 | $realpath = realpath($realpath) .'/'; |
||
| 64 | $config = json_decode(file_get_contents($realpath . 'library.json'),true); |
||
| 65 | if(!isset($config['exports']) ) { |
||
| 66 | $config['exports'] = []; |
||
| 67 | } |
||
| 68 | if(!isset($config['local']) ) { |
||
| 69 | $config['local'] = []; |
||
| 70 | } |
||
| 71 | |||
| 72 | $result = []; |
||
| 73 | |||
| 74 | $traverseDir = function ($path, $type = 'pobject', $nls = 'any') use ($arpath, &$result, $config, &$traverseDir, $realpath) { |
||
| 75 | $path = path::collapse($path); |
||
| 76 | $index = scandir($path, SCANDIR_SORT_NONE); |
||
| 77 | if($index !== false) { |
||
| 78 | list($maintype, $subtype) = explode('.', $type,2); |
||
| 79 | foreach($index as $filename) { |
||
| 80 | if($filename[0] === "." ) { |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | $filepath = $path . $filename; |
||
| 84 | if ( is_dir($filepath) ) { |
||
| 85 | if (strlen($filename) == 2) { |
||
| 86 | $traverseDir(path::collapse($filename, $path), $type, $filename); |
||
| 87 | } else { |
||
| 88 | $traverseDir(path::collapse($filename, $path), $filename); |
||
| 89 | } |
||
| 90 | } else if ( is_file($filepath) ) { |
||
| 91 | $tempname = sprintf("%s.%s.%s",$type,$filename,$nls); |
||
| 92 | $confname = sprintf("%s::%s",$type,$filename); |
||
| 93 | $private = true; |
||
| 94 | if (isset( $config['exports'] ) ) { |
||
| 95 | $private = ! in_array($confname, $config['exports']); |
||
| 96 | } |
||
| 97 | $local = false; |
||
| 98 | if (isset( $config['local'] ) ) { |
||
| 99 | $local = in_array($confname, $config['local']); |
||
| 100 | } |
||
| 101 | $result[$filename][] = [ |
||
| 102 | 'id' => PHP_INT_MAX, |
||
| 103 | 'path' => $arpath, |
||
| 104 | 'type' => $maintype, |
||
| 105 | 'subtype' => $subtype, |
||
| 106 | 'name' => $tempname, |
||
| 107 | 'filename' => substr($filepath,strlen($realpath)), |
||
| 108 | 'language' => $nls, |
||
| 109 | 'private' => $private, |
||
| 110 | 'local' => $local, |
||
| 111 | ]; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | }; |
||
| 117 | $traverseDir($realpath . 'src/'); |
||
| 118 | return $result; |
||
| 119 | } |
||
| 120 | |||
| 160 |