| Conditions | 7 |
| Paths | 4 |
| Total Lines | 100 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 99 | public function createServer($baseUri, |
||
| 100 | $requestUri, |
||
| 101 | BackendInterface $authBackend, |
||
| 102 | callable $viewCallBack) { |
||
| 103 | // Fire up server |
||
| 104 | $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
||
| 105 | $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
||
| 106 | // Set URL explicitly due to reverse-proxy situations |
||
| 107 | $server->httpRequest->setUrl($requestUri); |
||
| 108 | $server->setBaseUri($baseUri); |
||
| 109 | |||
| 110 | // Load plugins |
||
| 111 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
||
| 112 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
||
| 113 | $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
||
| 114 | // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
||
| 115 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
||
| 116 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
||
| 117 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
||
| 118 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
||
| 119 | // we do not provide locking we emulate it using a fake locking plugin. |
||
| 120 | if($this->request->isUserAgent([ |
||
| 121 | '/WebDAVFS/', |
||
| 122 | '/Microsoft Office OneNote 2013/', |
||
| 123 | '/Microsoft-WebDAV-MiniRedir/', |
||
| 124 | ])) { |
||
| 125 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
||
| 126 | } |
||
| 127 | |||
| 128 | if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
||
| 129 | $server->addPlugin(new BrowserErrorPagePlugin()); |
||
| 130 | } |
||
| 131 | |||
| 132 | // wait with registering these until auth is handled and the filesystem is setup |
||
| 133 | $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
||
| 134 | // ensure the skeleton is copied |
||
| 135 | $userFolder = \OC::$server->getUserFolder(); |
||
| 136 | |||
| 137 | /** @var \OC\Files\View $view */ |
||
| 138 | $view = $viewCallBack($server); |
||
| 139 | if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
||
| 140 | $rootInfo = $userFolder; |
||
| 141 | } else { |
||
| 142 | $rootInfo = $view->getFileInfo(''); |
||
| 143 | } |
||
| 144 | |||
| 145 | // Create ownCloud Dir |
||
| 146 | if ($rootInfo->getType() === 'dir') { |
||
| 147 | $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
||
| 148 | } else { |
||
| 149 | $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
||
| 150 | } |
||
| 151 | $objectTree->init($root, $view, $this->mountManager); |
||
| 152 | |||
| 153 | $server->addPlugin( |
||
| 154 | new \OCA\DAV\Connector\Sabre\FilesPlugin( |
||
| 155 | $objectTree, |
||
| 156 | $view, |
||
| 157 | $this->config, |
||
| 158 | $this->request, |
||
| 159 | $this->previewManager, |
||
| 160 | false, |
||
| 161 | !$this->config->getSystemValue('debug', false) |
||
| 162 | ) |
||
| 163 | ); |
||
| 164 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
||
| 165 | |||
| 166 | if($this->userSession->isLoggedIn()) { |
||
| 167 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
||
| 168 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
||
| 169 | $objectTree, |
||
| 170 | $this->userSession, |
||
| 171 | $userFolder, |
||
| 172 | \OC::$server->getShareManager() |
||
| 173 | )); |
||
| 174 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
||
| 175 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
||
| 176 | $objectTree, |
||
| 177 | $view, |
||
| 178 | \OC::$server->getSystemTagManager(), |
||
| 179 | \OC::$server->getSystemTagObjectMapper(), |
||
| 180 | $this->userSession, |
||
| 181 | \OC::$server->getGroupManager(), |
||
| 182 | $userFolder |
||
| 183 | )); |
||
| 184 | // custom properties plugin must be the last one |
||
| 185 | $server->addPlugin( |
||
| 186 | new \Sabre\DAV\PropertyStorage\Plugin( |
||
| 187 | new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
||
| 188 | $objectTree, |
||
| 189 | $this->databaseConnection, |
||
| 190 | $this->userSession->getUser() |
||
| 191 | ) |
||
| 192 | ) |
||
| 193 | ); |
||
| 194 | } |
||
| 195 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
||
| 196 | }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
||
| 197 | return $server; |
||
| 198 | } |
||
| 199 | } |
||
| 200 |