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