Skip to content

Commit 6f82f10

Browse files
committed
Change code for QA linters (not yet added to repo).
1 parent f2262d2 commit 6f82f10

3 files changed

Lines changed: 11 additions & 17 deletions

File tree

src/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class Exception extends \Exception
66
{
77
public static function create(string $error, array $context, \Exception $previous = null): Exception
88
{
9-
return new static(vsprintf($error, $context), 0, $previous);
9+
return new self(vsprintf($error, $context), 0, $previous);
1010
}
1111
}

src/Server.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
167167
if ($method === 'HEAD') {
168168
$response->getBody()->rewind();
169169
$response->getBody()->write('');
170-
$response = $response->withStatus("204"); // CHECKME: nextcloud will remove the updates-via header - any objections to give the 'HEAD' request a 'no content' response type?
170+
$response = $response->withStatus(204); // CHECKME: nextcloud will remove the updates-via header - any objections to give the 'HEAD' request a 'no content' response type?
171171
if ($this->pubsub) {
172172
$response = $response->withHeader("updates-via", $this->pubsub);
173173
}
@@ -177,7 +177,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
177177
case 'OPTIONS':
178178
$response = $response
179179
->withHeader('Vary', 'Accept')
180-
->withStatus('204')
180+
->withStatus(204)
181181
;
182182
break;
183183

@@ -204,7 +204,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
204204
$mimetype = self::MIME_TYPE_DIRECTORY;
205205
}
206206
if ($pathExists === true) {
207-
if ($mimetype === self::MIME_TYPE_DIRECTORY) {
207+
if (isset($mimetype) && $mimetype === self::MIME_TYPE_DIRECTORY) {
208208
$contentType= explode(";", $request->getHeaderLine("Content-Type"))[0];
209209
$slug = $request->getHeaderLine("Slug");
210210
if ($slug) {
@@ -360,7 +360,7 @@ private function handleCreateRequest(Response $response, string $path, $contents
360360
} else {
361361
$success = false;
362362

363-
set_error_handler(static function($severity, $message, $filename, $line) {
363+
set_error_handler(static function ($severity, $message, $filename, $line) {
364364
throw new \ErrorException($message, 0, $severity, $filename, $line);
365365
});
366366

@@ -538,7 +538,7 @@ private function handleReadRequest(Response $response, string $path, $contents,
538538
$response->getBody()->write($contents);
539539
$response = $response->withHeader("Content-type", "text/turtle");
540540
$response = $response->withStatus(200);
541-
} else if ($filesystem->has($path) === false) {
541+
} elseif ($filesystem->has($path) === false) {
542542
$message = vsprintf(self::ERROR_PATH_DOES_NOT_EXIST, [$path]);
543543
$response->getBody()->write($message);
544544
$response = $response->withStatus(404);

src/example.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666

6767
$response = $server->respondToRequest($request);
6868
} elseif ($target === 'GET/') {
69-
$response->getBody()->write(getHomepage());
69+
$fileHandle = fopen(__FILE__, 'rb');
70+
fseek($fileHandle, __COMPILER_HALT_OFFSET__);
71+
$homepage = stream_get_contents($fileHandle);
72+
$response->getBody()->write($homepage);
7073
} else {
7174
$response = $response->withStatus(404);
7275
$response->getBody()->write("<h1>404</h1><p>Path '$path' does not exist.</p>");
@@ -85,18 +88,9 @@
8588
}
8689
}
8790

88-
echo (string) $response->getBody();
91+
echo (string) $response->getBody();
8992
exit;
9093

91-
function getHomepage() : string
92-
{
93-
$fileHandle = fopen(__FILE__, 'rb');
94-
95-
fseek($fileHandle, __COMPILER_HALT_OFFSET__);
96-
97-
return stream_get_contents($fileHandle);
98-
}
99-
10094
__halt_compiler();<!doctype html>
10195
<html lang="en">
10296
<meta charset="UTF-8">

0 commit comments

Comments
 (0)