| Conditions | 5 |
| Paths | 5 |
| Total Lines | 82 |
| Code Lines | 60 |
| 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 |
||
| 106 | public function httpGet(RequestInterface $request, ResponseInterface $response):bool { |
||
| 107 | if ($request->getPath() !== 'provisioning/' . AppleProvisioningNode::FILENAME) { |
||
| 108 | return true; |
||
| 109 | } |
||
| 110 | |||
| 111 | $user = $this->userSession->getUser(); |
||
| 112 | if (!$user) { |
||
| 113 | return true; |
||
| 114 | } |
||
| 115 | |||
| 116 | $serverProtocol = $this->request->getServerProtocol(); |
||
| 117 | $useSSL = ($serverProtocol === 'https'); |
||
| 118 | |||
| 119 | if (!$useSSL) { |
||
| 120 | $response->setStatus(200); |
||
| 121 | $response->setHeader('Content-Type', 'text/plain; charset=utf-8'); |
||
| 122 | $response->setBody($this->l10n->t('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', [$this->themingDefaults->getName()])); |
||
| 123 | |||
| 124 | return false; |
||
| 125 | } |
||
| 126 | |||
| 127 | $absoluteURL = $request->getAbsoluteUrl(); |
||
| 128 | $parsedUrl = parse_url($absoluteURL); |
||
| 129 | if (isset($parsedUrl['port'])) { |
||
| 130 | $serverPort = (int) $parsedUrl['port']; |
||
| 131 | } else { |
||
| 132 | $serverPort = 443; |
||
| 133 | } |
||
| 134 | $server_url = $parsedUrl['host']; |
||
| 135 | |||
| 136 | $description = $this->themingDefaults->getName(); |
||
| 137 | $userId = $user->getUID(); |
||
| 138 | |||
| 139 | $reverseDomain = implode('.', array_reverse(explode('.', $parsedUrl['host']))); |
||
| 140 | |||
| 141 | $caldavUUID = call_user_func($this->uuidClosure); |
||
| 142 | $carddavUUID = call_user_func($this->uuidClosure); |
||
| 143 | $profileUUID = call_user_func($this->uuidClosure); |
||
| 144 | |||
| 145 | $caldavIdentifier = $reverseDomain . '.' . $caldavUUID; |
||
| 146 | $carddavIdentifier = $reverseDomain . '.' . $carddavUUID; |
||
| 147 | $profileIdentifier = $reverseDomain . '.' . $profileUUID; |
||
| 148 | |||
| 149 | $caldavDescription = $this->l10n->t('Configures a CalDAV account'); |
||
| 150 | $caldavDisplayname = $description . ' CalDAV'; |
||
| 151 | $carddavDescription = $this->l10n->t('Configures a CardDAV account'); |
||
| 152 | $carddavDisplayname = $description . ' CardDAV'; |
||
| 153 | |||
| 154 | $filename = $userId . '-' . AppleProvisioningNode::FILENAME; |
||
| 155 | |||
| 156 | $xmlSkeleton = $this->getTemplate(); |
||
| 157 | $body = vsprintf($xmlSkeleton, array_map(function($v) { |
||
| 158 | return \htmlspecialchars($v, ENT_XML1, 'UTF-8'); |
||
| 159 | }, [ |
||
| 160 | $description, |
||
| 161 | $server_url, |
||
| 162 | $userId, |
||
| 163 | $serverPort, |
||
| 164 | $caldavDescription, |
||
| 165 | $caldavDisplayname, |
||
| 166 | $caldavIdentifier, |
||
| 167 | $caldavUUID, |
||
| 168 | $description, |
||
| 169 | $server_url, |
||
| 170 | $userId, |
||
| 171 | $serverPort, |
||
| 172 | $carddavDescription, |
||
| 173 | $carddavDisplayname, |
||
| 174 | $carddavIdentifier, |
||
| 175 | $carddavUUID, |
||
| 176 | $description, |
||
| 177 | $profileIdentifier, |
||
| 178 | $profileUUID |
||
| 179 | ] |
||
| 180 | )); |
||
| 181 | |||
| 182 | $response->setStatus(200); |
||
| 183 | $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); |
||
| 184 | $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
||
| 185 | $response->setBody($body); |
||
| 186 | |||
| 187 | return false; |
||
| 188 | } |
||
| 268 |