| Conditions | 17 |
| Paths | 333 |
| Total Lines | 96 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 100 | protected function listDirectory( |
||
| 101 | string $disk, |
||
| 102 | string $directory, |
||
| 103 | bool $recursive, |
||
| 104 | bool $longFormat |
||
| 105 | ) { |
||
| 106 | $content = Storage::disk($disk)->listContents($directory); |
||
| 107 | |||
| 108 | // If we are recursing into subdirectories, then display the directory |
||
| 109 | // before listing the contents. |
||
| 110 | // Precede with a blank line after the first directory. |
||
| 111 | |||
| 112 | if ($recursive) { |
||
| 113 | if ($this->dirIndex) { |
||
| 114 | $this->line(''); |
||
| 115 | } |
||
| 116 | |||
| 117 | $this->dirIndex++; |
||
| 118 | |||
| 119 | $this->line($directory . ':'); |
||
| 120 | } |
||
| 121 | |||
| 122 | // To collect directories as we go through. |
||
| 123 | |||
| 124 | $subDirs = []; |
||
| 125 | |||
| 126 | $dt = new DateTimeImmutable(); |
||
| 127 | |||
| 128 | foreach ($content as $item) { |
||
| 129 | $basename = $item['basename'] ?? 'unknown'; |
||
| 130 | $dirname = $item['dirname'] ?? '/'; |
||
| 131 | |||
| 132 | $pathname = $dirname . '/' . $basename; |
||
| 133 | |||
| 134 | $size = $item['size'] ?? 0; |
||
| 135 | |||
| 136 | $type = $item['type'] ?? static::TYPE_FILE; |
||
| 137 | |||
| 138 | // Some drivers do not supply the file size by default, |
||
| 139 | // so make another call to get it. |
||
| 140 | |||
| 141 | if ($size === 0 && $type === static::TYPE_FILE && $longFormat) { |
||
| 142 | try { |
||
| 143 | $size = Storage::disk($disk)->getSize($pathname); |
||
| 144 | } catch (Throwable $e) { |
||
| 145 | // Some drivers throw exceptions in some circumstances. |
||
| 146 | // We just catch and ignore. |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | // Format the timestamp if present. |
||
| 151 | // Just going down the seconds for now, and UTC is implied. |
||
| 152 | |||
| 153 | $timestamp = $item['timestamp'] ?? null; |
||
| 154 | |||
| 155 | if ($timestamp !== null) { |
||
| 156 | $datetime = $dt |
||
| 157 | ->setTimezone(new DateTimeZone('UTC')) |
||
| 158 | ->setTimestamp($timestamp) |
||
| 159 | ->format('Y-m-d H:i:s'); |
||
| 160 | } else { |
||
| 161 | $datetime = ''; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Two output formats at present: long and not long. |
||
| 165 | |||
| 166 | if ($longFormat) { |
||
| 167 | $this->line(sprintf( |
||
| 168 | '%1s %10d %s %s', |
||
| 169 | $type === static::TYPE_DIR ? 'd' : '-', |
||
| 170 | $size, |
||
| 171 | $datetime, |
||
| 172 | $basename |
||
| 173 | )); |
||
| 174 | } else { |
||
| 175 | $message = sprintf('%s', $basename); |
||
| 176 | |||
| 177 | if ($type === static::TYPE_FILE) { |
||
| 178 | $this->info($message); |
||
| 179 | } else { |
||
| 180 | $this->warn($message); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | // Collect the list of sub-directories as we go through. |
||
| 185 | |||
| 186 | if ($recursive && $type === static::TYPE_DIR) { |
||
| 187 | $subDirs[] = $pathname; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | // If recursing, go through the sub-directories collected. |
||
| 192 | |||
| 193 | if ($recursive && $subDirs) { |
||
| 194 | foreach ($subDirs as $subDir) { |
||
| 195 | $this->listDirectory($disk, $subDir, $recursive, $longFormat); |
||
| 196 | } |
||
| 200 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths