Skip to content

Commit

Permalink
Change code for QA linters (not yet added to repo).
Browse files Browse the repository at this point in the history
  • Loading branch information
Potherca committed Jan 11, 2022
1 parent f2262d2 commit 6f82f10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Exception extends \Exception
{
public static function create(string $error, array $context, \Exception $previous = null): Exception
{
return new static(vsprintf($error, $context), 0, $previous);
return new self(vsprintf($error, $context), 0, $previous);
}
}
10 changes: 5 additions & 5 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
if ($method === 'HEAD') {
$response->getBody()->rewind();
$response->getBody()->write('');
$response = $response->withStatus("204"); // CHECKME: nextcloud will remove the updates-via header - any objections to give the 'HEAD' request a 'no content' response type?
$response = $response->withStatus(204); // CHECKME: nextcloud will remove the updates-via header - any objections to give the 'HEAD' request a 'no content' response type?
if ($this->pubsub) {
$response = $response->withHeader("updates-via", $this->pubsub);
}
Expand All @@ -177,7 +177,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
case 'OPTIONS':
$response = $response
->withHeader('Vary', 'Accept')
->withStatus('204')
->withStatus(204)
;
break;

Expand All @@ -204,7 +204,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
$mimetype = self::MIME_TYPE_DIRECTORY;
}
if ($pathExists === true) {
if ($mimetype === self::MIME_TYPE_DIRECTORY) {
if (isset($mimetype) && $mimetype === self::MIME_TYPE_DIRECTORY) {
$contentType= explode(";", $request->getHeaderLine("Content-Type"))[0];
$slug = $request->getHeaderLine("Slug");
if ($slug) {
Expand Down Expand Up @@ -360,7 +360,7 @@ private function handleCreateRequest(Response $response, string $path, $contents
} else {
$success = false;

set_error_handler(static function($severity, $message, $filename, $line) {
set_error_handler(static function ($severity, $message, $filename, $line) {
throw new \ErrorException($message, 0, $severity, $filename, $line);
});

Expand Down Expand Up @@ -538,7 +538,7 @@ private function handleReadRequest(Response $response, string $path, $contents,
$response->getBody()->write($contents);
$response = $response->withHeader("Content-type", "text/turtle");
$response = $response->withStatus(200);
} else if ($filesystem->has($path) === false) {
} elseif ($filesystem->has($path) === false) {
$message = vsprintf(self::ERROR_PATH_DOES_NOT_EXIST, [$path]);
$response->getBody()->write($message);
$response = $response->withStatus(404);
Expand Down
16 changes: 5 additions & 11 deletions src/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@

$response = $server->respondToRequest($request);
} elseif ($target === 'GET/') {
$response->getBody()->write(getHomepage());
$fileHandle = fopen(__FILE__, 'rb');
fseek($fileHandle, __COMPILER_HALT_OFFSET__);
$homepage = stream_get_contents($fileHandle);
$response->getBody()->write($homepage);
} else {
$response = $response->withStatus(404);
$response->getBody()->write("<h1>404</h1><p>Path '$path' does not exist.</p>");
Expand All @@ -85,18 +88,9 @@
}
}

echo (string) $response->getBody();
echo (string) $response->getBody();
exit;

function getHomepage() : string
{
$fileHandle = fopen(__FILE__, 'rb');

fseek($fileHandle, __COMPILER_HALT_OFFSET__);

return stream_get_contents($fileHandle);
}

__halt_compiler();<!doctype html>
<html lang="en">
<meta charset="UTF-8">
Expand Down

0 comments on commit 6f82f10

Please sign in to comment.