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