| Conditions | 4 |
| Paths | 16 |
| Total Lines | 57 |
| Code Lines | 35 |
| 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 |
||
| 186 | public function convert(ObjectId $slave, File $master): bool |
||
| 187 | { |
||
| 188 | $this->logger->info('create slave for master node ['.$master->getId().']', [ |
||
| 189 | 'category' => get_class($this), |
||
| 190 | ]); |
||
| 191 | |||
| 192 | $slave = $this->getSlave($slave); |
||
| 193 | $result = $this->converter->convert($master, $slave['format']); |
||
| 194 | $master->setFilesystem($this->server->getUserById($master->getOwner())->getFilesystem()); |
||
| 195 | |||
| 196 | try { |
||
| 197 | if (isset($slave['slave'])) { |
||
| 198 | $slave = $master->getFilesystem()->findNodeById($slave['slave']); |
||
| 199 | |||
| 200 | $slave->setReadonly(false); |
||
| 201 | $slave->put($result->getPath()); |
||
| 202 | $slave->setReadonly(); |
||
| 203 | |||
| 204 | return true; |
||
| 205 | } |
||
| 206 | } catch (NotFound $e) { |
||
| 207 | $this->logger->debug('referenced slave node ['.$slave['slave'].'] does not exists or is not accessible', [ |
||
| 208 | 'category' => get_class($this), |
||
| 209 | 'exception' => $e, |
||
| 210 | ]); |
||
| 211 | } |
||
| 212 | |||
| 213 | $this->logger->debug('create non existing slave ['.$slave['_id'].'] node for master ['.$master->getId().']', [ |
||
| 214 | 'category' => get_class($this), |
||
| 215 | ]); |
||
| 216 | |||
| 217 | try { |
||
| 218 | $name = substr($master->getName(), 0, (strlen($master->getExtension()) + 1) * -1); |
||
| 219 | $name .= '.'.$slave['format']; |
||
| 220 | } catch (\Exception $e) { |
||
| 221 | $name = $master->getName().'.'.$slave['format']; |
||
| 222 | } |
||
| 223 | |||
| 224 | $node = $master->getParent()->addFile($name, $result->getPath(), [ |
||
| 225 | 'owner' => $master->getOwner(), |
||
| 226 | 'app' => [ |
||
| 227 | __NAMESPACE__ => [ |
||
| 228 | 'master' => $master->getId(), |
||
| 229 | ], |
||
| 230 | ], |
||
| 231 | ], NodeInterface::CONFLICT_RENAME); |
||
| 232 | |||
| 233 | $node->setReadonly(); |
||
| 234 | |||
| 235 | $result = $this->db->{$this->collection_name}->updateOne(['_id' => $slave['_id']], [ |
||
| 236 | '$set' => [ |
||
| 237 | 'slave' => $node->getId(), |
||
| 238 | ], |
||
| 239 | ]); |
||
| 240 | |||
| 241 | return $result->isAcknowledged(); |
||
| 242 | } |
||
| 243 | } |
||
| 244 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.