| Conditions | 6 |
| Paths | 6 |
| Total Lines | 52 |
| 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 |
||
| 81 | public function buildIndexObject(string $basePath, string $relativePath): ?IndexObject |
||
| 82 | { |
||
| 83 | $absolutePath = rtrim($basePath, '/') . '/' . $relativePath; |
||
| 84 | |||
| 85 | clearstatcache(null, $absolutePath); |
||
| 86 | |||
| 87 | if (!($stat = @lstat($absolutePath))) |
||
| 88 | { |
||
| 89 | throw new Exception("lstat() failed for {$absolutePath}"); |
||
| 90 | } |
||
| 91 | |||
| 92 | $size = $linkTarget = $hashContainer = null; |
||
| 93 | |||
| 94 | switch ($stat['mode'] & 0xF000) |
||
| 95 | { |
||
| 96 | case 0x4000: |
||
| 97 | |||
| 98 | $type = IndexObject::TYPE_DIR; |
||
| 99 | |||
| 100 | break; |
||
| 101 | |||
| 102 | case 0x8000: |
||
| 103 | |||
| 104 | $type = IndexObject::TYPE_FILE; |
||
| 105 | $size = $stat['size']; |
||
| 106 | $hashContainer = new HashContainer(); |
||
| 107 | |||
| 108 | break; |
||
| 109 | |||
| 110 | case 0xA000: |
||
| 111 | |||
| 112 | $type = IndexObject::TYPE_LINK; |
||
| 113 | $linkTarget = readlink($absolutePath); |
||
| 114 | |||
| 115 | if ($linkTarget === false) |
||
| 116 | { |
||
| 117 | $this->logger->notice("Found broken link: {$absolutePath}"); |
||
| 118 | |||
| 119 | // silently ignore broken links |
||
| 120 | return null; |
||
| 121 | } |
||
| 122 | |||
| 123 | break; |
||
| 124 | |||
| 125 | default: |
||
| 126 | |||
| 127 | // sockets, pipes, etc. |
||
| 128 | return null; |
||
| 129 | } |
||
| 130 | |||
| 131 | return new IndexObject($relativePath, $type, $stat['mtime'], $stat['ctime'], $stat['mode'] & 0777, $size, $stat['ino'], $linkTarget, null, $hashContainer); |
||
| 132 | } |
||
| 133 | } |
||
| 134 |
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.