From 529f9621cd6e74088fbede8358b6b59981ad8cea Mon Sep 17 00:00:00 2001 From: Pavel Buchnev Date: Thu, 13 Apr 2023 15:13:49 +0400 Subject: [PATCH] Cleanup --- .github/FUNDING.yml | 3 ++ .github/workflows/phpunit.yml | 4 +- .github/workflows/psalm.yml | 2 +- .gitignore | 3 ++ composer.json | 6 +-- src/HttpWorker.php | 15 ++----- src/HttpWorkerInterface.php | 9 ---- src/PSR7Worker.php | 67 +++------------------------- src/PSR7WorkerInterface.php | 7 --- src/Request.php | 11 ----- tests/Feature/StreamResponseTest.php | 4 +- 11 files changed, 23 insertions(+), 108 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..38798a2 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: roadrunner-server diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 854efaa..504edfd 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -1,9 +1,9 @@ on: + pull_request: null push: branches: - master - '*.*' - pull_request: null name: phpunit @@ -16,4 +16,4 @@ jobs: php: >- ['8.1', '8.2'] stability: >- - ['prefer-stable', 'prefer-lowest'] + ['prefer-lowest', 'prefer-stable'] diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index bdb570c..02a83d3 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -1,9 +1,9 @@ on: + pull_request: null push: branches: - master - '*.*' - pull_request: null name: static analysis diff --git a/.gitignore b/.gitignore index 4c64f4e..4059830 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ clover* cover* .DS_Store *.cache + +.phpunit.cache/ +.phpunit.result.cache diff --git a/composer.json b/composer.json index a78c314..6402581 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "license": "MIT", "authors": [ { - "name": "Anton Titov (Wolfy-J)", - "email": "wolfy.jd@gmail.com" + "name": "Anton Titov (wolfy-j)", + "email": "wolfy-j@spiralscout.com" }, { "name": "Valery Piashchynski", @@ -45,9 +45,9 @@ "spiral/roadrunner-worker": "^3.0" }, "require-dev": { + "jetbrains/phpstorm-attributes": "^1.0", "nyholm/psr7": "^1.3", "phpunit/phpunit": "^10.0", - "jetbrains/phpstorm-attributes": "^1.0", "symfony/process": "^6.2", "vimeo/psalm": "^5.9" }, diff --git a/src/HttpWorker.php b/src/HttpWorker.php index 384cf56..d07b0ea 100644 --- a/src/HttpWorker.php +++ b/src/HttpWorker.php @@ -1,12 +1,5 @@ $status, 'headers' => $headers ?: (object)[], ], \JSON_THROW_ON_ERROR); @@ -87,7 +80,7 @@ public function respond(int $status, string|Generator $body, array $headers = [] private function respondStream(int $status, Generator $body, array $headers = []): void { - $head = (string)\json_encode([ + $head = \json_encode([ 'status' => $status, 'headers' => $headers ?: (object)[], ], \JSON_THROW_ON_ERROR); @@ -124,11 +117,11 @@ private function createRequest(string $body, array $context): Request cookies: (array)($context['cookies'] ?? []), uploads: (array)($context['uploads'] ?? []), attributes: [ - Request::PARSED_BODY_ATTRIBUTE_NAME => (bool)$context['parsed'], + Request::PARSED_BODY_ATTRIBUTE_NAME => $context['parsed'], ] + (array)($context['attributes'] ?? []), query: $query, body: $body, - parsed: (bool)$context['parsed'], + parsed: $context['parsed'], ); } diff --git a/src/HttpWorkerInterface.php b/src/HttpWorkerInterface.php index 8eef4d1..9198e7b 100644 --- a/src/HttpWorkerInterface.php +++ b/src/HttpWorkerInterface.php @@ -1,12 +1,5 @@ httpWorker = new HttpWorker($worker); - $this->requestFactory = $requestFactory; - $this->streamFactory = $streamFactory; - $this->uploadsFactory = $uploadsFactory; $this->originalServer = $_SERVER; } - /** - * @return WorkerInterface - */ public function getWorker(): WorkerInterface { return $this->httpWorker->getWorker(); } /** - * @return ServerRequestInterface|null * @throws \JsonException */ public function waitRequest(): ?ServerRequestInterface @@ -113,7 +72,6 @@ public function waitRequest(): ?ServerRequestInterface /** * Send response to the application server. * - * @param ResponseInterface $response * @throws \JsonException */ public function respond(ResponseInterface $response): void @@ -158,7 +116,6 @@ private function streamToGenerator(StreamInterface $stream): Generator * Returns altered copy of _SERVER variable. Sets ip-address, * request-time and other values. * - * @param Request $request * @return non-empty-array */ protected function configureServer(Request $request): array @@ -173,7 +130,7 @@ protected function configureServer(Request $request): array $server['HTTP_USER_AGENT'] = ''; foreach ($request->headers as $key => $value) { - $key = \strtoupper(\str_replace('-', '_', (string)$key)); + $key = \strtoupper(\str_replace('-', '_', $key)); if (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { $server[$key] = \implode(', ', $value); } else { @@ -184,26 +141,17 @@ protected function configureServer(Request $request): array return $server; } - /** - * @return int - */ protected function timeInt(): int { return \time(); } - /** - * @return float - */ protected function timeFloat(): float { return \microtime(true); } /** - * @param Request $httpRequest - * @param array $server - * @return ServerRequestInterface * @throws \JsonException */ protected function mapRequest(Request $httpRequest, array $server): ServerRequestInterface @@ -278,9 +226,6 @@ protected function wrapUploads(array $files): array /** * Normalize HTTP protocol version to valid values - * - * @param string $version - * @return string */ private static function fetchProtocolVersion(string $version): string { diff --git a/src/PSR7WorkerInterface.php b/src/PSR7WorkerInterface.php index dbb710e..becbfb2 100644 --- a/src/PSR7WorkerInterface.php +++ b/src/PSR7WorkerInterface.php @@ -1,12 +1,5 @@ attributes['ipAddress'] ?? $this->remoteAddr); } /** - * @return array|null * @throws \JsonException */ public function getParsedBody(): ?array diff --git a/tests/Feature/StreamResponseTest.php b/tests/Feature/StreamResponseTest.php index 08fda84..ca8c370 100644 --- a/tests/Feature/StreamResponseTest.php +++ b/tests/Feature/StreamResponseTest.php @@ -113,8 +113,6 @@ public function testStopStreamAfterStreamEnd(): void $this->assertFalse($this->getWorker()->hasPayload(\Spiral\RoadRunner\Message\Command\StreamStop::class)); $this->sendCommand(new StreamStop()); - - \usleep(200_000); self::assertSame(\implode("\n", ['Hello', 'World!']), \trim(ServerRunner::getBuffer())); $this->assertTrue($this->getWorker()->hasPayload(\Spiral\RoadRunner\Message\Command\StreamStop::class)); @@ -128,7 +126,7 @@ private function getRelay(): SocketRelay private function getWorker(): Worker { - return $this->worker ??= new Worker($this->getRelay(), false); + return $this->worker ??= new Worker(relay: $this->getRelay(), interceptSideEffects: false); } private function makeHttpWorker(): HttpWorker