| Conditions | 14 |
| Paths | 29 |
| Total Lines | 65 |
| Code Lines | 37 |
| 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 |
||
| 80 | public function getNodeForPath($path) { |
||
| 81 | if (!$this->fileView) { |
||
| 82 | throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); |
||
| 83 | } |
||
| 84 | |||
| 85 | $path = trim($path, '/'); |
||
| 86 | |||
| 87 | if (isset($this->cache[$path])) { |
||
| 88 | return $this->cache[$path]; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($path) { |
||
| 92 | try { |
||
| 93 | $this->fileView->verifyPath($path, basename($path)); |
||
| 94 | } catch (\OCP\Files\InvalidPathException $ex) { |
||
| 95 | throw new InvalidPath($ex->getMessage()); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // Is it the root node? |
||
| 100 | if (!strlen($path)) { |
||
| 101 | return $this->rootNode; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { |
||
| 105 | // read from storage |
||
| 106 | $absPath = $this->fileView->getAbsolutePath($path); |
||
| 107 | $mount = $this->fileView->getMount($path); |
||
| 108 | $storage = $mount->getStorage(); |
||
| 109 | $internalPath = $mount->getInternalPath($absPath); |
||
| 110 | if ($storage && $storage->file_exists($internalPath)) { |
||
| 111 | /** |
||
| 112 | * @var \OC\Files\Storage\Storage $storage |
||
| 113 | */ |
||
| 114 | // get data directly |
||
| 115 | $data = $storage->getMetaData($internalPath); |
||
| 116 | $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount); |
||
| 117 | } else { |
||
| 118 | $info = null; |
||
| 119 | } |
||
| 120 | } else { |
||
| 121 | // read from cache |
||
| 122 | try { |
||
| 123 | $info = $this->fileView->getFileInfo($path); |
||
| 124 | |||
| 125 | if ($info instanceof \OCP\Files\FileInfo && $info->getStorage()->instanceOfStorage(FailedStorage::class)) { |
||
| 126 | throw new StorageNotAvailableException(); |
||
| 127 | } |
||
| 128 | } catch (StorageNotAvailableException $e) { |
||
| 129 | throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage is temporarily not available', 0, $e); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | if (!$info) { |
||
| 134 | throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located'); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($info->getType() === 'dir') { |
||
| 138 | $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this); |
||
| 139 | } else { |
||
| 140 | $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); |
||
| 141 | } |
||
| 142 | |||
| 143 | $this->cache[$path] = $node; |
||
| 144 | return $node; |
||
| 145 | } |
||
| 205 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.