| Conditions | 6 |
| Paths | 6 |
| Total Lines | 52 |
| Code Lines | 24 |
| 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 |
||
| 69 | public function buildIndexObject(string $basePath, string $relativePath): ?IndexObject |
||
| 70 | { |
||
| 71 | $absolutePath = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $relativePath; |
||
| 72 | |||
| 73 | clearstatcache(null, $absolutePath); |
||
| 74 | |||
| 75 | if (!($stat = @lstat($absolutePath))) |
||
| 76 | { |
||
| 77 | throw new Exception("lstat() failed for {$absolutePath}"); |
||
| 78 | } |
||
| 79 | |||
| 80 | $size = $linkTarget = $hashContainer = null; |
||
| 81 | |||
| 82 | switch ($stat['mode'] & 0xF000) |
||
| 83 | { |
||
| 84 | case 0x4000: |
||
| 85 | |||
| 86 | $type = IndexObject::TYPE_DIR; |
||
| 87 | |||
| 88 | break; |
||
| 89 | |||
| 90 | case 0x8000: |
||
| 91 | |||
| 92 | $type = IndexObject::TYPE_FILE; |
||
| 93 | $size = $stat['size']; |
||
| 94 | $hashContainer = new HashContainer(); |
||
| 95 | |||
| 96 | break; |
||
| 97 | |||
| 98 | case 0xA000: |
||
| 99 | |||
| 100 | $type = IndexObject::TYPE_LINK; |
||
| 101 | $linkTarget = readlink($absolutePath); |
||
| 102 | |||
| 103 | if ($linkTarget === false) |
||
| 104 | { |
||
| 105 | // todo: log |
||
| 106 | |||
| 107 | // silently ignore broken links |
||
| 108 | return null; |
||
| 109 | } |
||
| 110 | |||
| 111 | break; |
||
| 112 | |||
| 113 | default: |
||
| 114 | |||
| 115 | // sockets, pipes, etc. |
||
| 116 | return null; |
||
| 117 | } |
||
| 118 | |||
| 119 | return new IndexObject($relativePath, $type, $stat['mtime'], $stat['ctime'], $stat['mode'], $size, $stat['ino'], $linkTarget, null, $hashContainer); |
||
| 120 | } |
||
| 121 | } |
||
| 122 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.