Skip to content

Commit a44a5f7

Browse files
authored
Merge pull request #29: Maintenance
2 parents 8578a87 + fe8804e commit a44a5f7

22 files changed

+328
-305
lines changed

.editorconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ indent_style = space
88
indent_size = 4
99
trim_trailing_whitespace = true
1010

11-
[*.{yml, yaml, sh, conf, neon*}]
11+
[*.yaml]
12+
indent_size = 2
13+
14+
[*.yml]
1215
indent_size = 2
1316

1417
[*.md]
1518
trim_trailing_whitespace = false
19+
20+
[Makefile]
21+
indent_style = tab

.gitattributes

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
* text=auto
22

3-
/.github export-ignore
4-
/tests export-ignore
5-
/.* export-ignore
6-
/phpunit.xml* export-ignore
7-
/phpstan.* export-ignore
8-
/psalm.* export-ignore
9-
/infection.* export-ignore
10-
/codecov.* export-ignore
3+
/.* export-ignore
4+
/tests export-ignore
5+
/phpunit.xml* export-ignore
6+
/psalm.* export-ignore
7+
/psalm-baseline.xml export-ignore
8+
/infection.* export-ignore
9+
/rector.php export-ignore

.github/workflows/cs-fix.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
on:
2+
push:
3+
branches:
4+
- '*'
5+
6+
name: Fix Code Style
7+
8+
jobs:
9+
cs-fix:
10+
permissions:
11+
contents: write
12+
uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master

.gitignore

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
# Composer lock file
2-
composer.lock
3-
4-
# IDEs
5-
/.idea
6-
/.vscode
7-
8-
# Vendors
9-
/vendor
10-
**/vendor
11-
12-
# Temp dirs & trash
13-
/tests/server*
14-
clover*
15-
cover*
16-
.DS_Store
17-
*.cache
18-
19-
.phpunit.cache/
20-
.phpunit.result.cache
1+
/.*
2+
!/.github/
3+
!/.php-cs-fixer.dist.php
4+
!/.editorconfig
5+
!/.gitattributes
6+
/runtime/
7+
/vendor/
8+
/composer.lock
9+
*.log

.php-cs-fixer.dist.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once 'vendor/autoload.php';
6+
7+
return \Spiral\CodeStyle\Builder::create()
8+
->include(__DIR__ . '/src')
9+
->include(__DIR__ . '/tests')
10+
->include(__FILE__)
11+
->allowRisky(false)
12+
->build();

composer.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
"require-dev": {
5050
"jetbrains/phpstorm-attributes": "^1.0",
5151
"nyholm/psr7": "^1.3",
52-
"phpunit/phpunit": "^10.0",
52+
"phpunit/phpunit": "^10.5",
53+
"spiral/code-style": "^2.3",
5354
"spiral/dumper": "^3.3",
5455
"symfony/process": "^6.2 || ^7.0",
55-
"vimeo/psalm": "^5.9"
56+
"vimeo/psalm": "^6.13"
5657
},
5758
"autoload": {
5859
"psr-4": {
@@ -70,9 +71,6 @@
7071
"url": "https://github.com/sponsors/roadrunner-server"
7172
}
7273
],
73-
"scripts": {
74-
"analyze": "psalm"
75-
},
7674
"suggest": {
7775
"spiral/roadrunner-cli": "Provides RoadRunner installation and management CLI tools",
7876
"ext-protobuf": "Provides Protocol Buffers support. Without it, performance will be lower."
@@ -81,5 +79,16 @@
8179
"sort-packages": true
8280
},
8381
"minimum-stability": "dev",
84-
"prefer-stable": true
82+
"prefer-stable": true,
83+
"scripts": {
84+
"cs:fix": "php-cs-fixer fix -v",
85+
"psalm": "psalm",
86+
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
87+
"psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
88+
"test": "phpunit --color=always --testdox",
89+
"test:cc": [
90+
"@putenv XDEBUG_MODE=coverage",
91+
"phpunit --coverage-clover=runtime/phpunit/logs/clover.xml --color=always"
92+
]
93+
}
8594
}

phpunit.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile="runtime/phpunit/result.cache"
46
backupGlobals="false" colors="true"
57
processIsolation="false"
68
executionOrder="random"
79
stopOnFailure="false"
810
stopOnError="false"
911
stderr="true"
10-
cacheDirectory=".phpunit.cache"
1112
>
1213
<testsuites>
1314
<testsuite name="RR Worker Tests">
1415
<directory>tests</directory>
1516
</testsuite>
1617
</testsuites>
1718
<coverage>
19+
<report>
20+
<html outputDirectory="runtime/coverage"/>
21+
<text outputFile="runtime/coverage.txt"/>
22+
<clover outputFile="runtime/logs/clover.xml"/>
23+
</report>
24+
</coverage>
25+
<logging>
26+
<junit outputFile="runtime/report.junit.xml"/>
27+
</logging>
28+
<source>
1829
<include>
1930
<directory>src</directory>
2031
</include>
21-
</coverage>
32+
<exclude>
33+
<directory>tests</directory>
34+
</exclude>
35+
</source>
2236
</phpunit>

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
resolveFromConfigFile="true"
88
findUnusedBaselineEntry="false"
99
findUnusedCode="false"
10+
ensureOverrideAttribute="false"
1011
>
1112
<issueHandlers>
1213
<RedundantConditionGivenDocblockType errorLevel="suppress" />

src/GlobalState.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
namespace Spiral\RoadRunner\Http;
66

7-
use function time;
8-
use function microtime;
9-
use function strtoupper;
10-
use function str_replace;
11-
use function implode;
12-
137
final class GlobalState
148
{
159
/**
@@ -35,22 +29,22 @@ public static function enrichServerVars(Request $request): array
3529
$server = self::$cachedServer;
3630

3731
$server['REQUEST_URI'] = $request->uri;
38-
$server['REQUEST_TIME'] = time();
39-
$server['REQUEST_TIME_FLOAT'] = microtime(true);
32+
$server['REQUEST_TIME'] = \time();
33+
$server['REQUEST_TIME_FLOAT'] = \microtime(true);
4034
$server['REMOTE_ADDR'] = $request->getRemoteAddr();
4135
$server['REQUEST_METHOD'] = $request->method;
4236
$server['HTTP_USER_AGENT'] = '';
4337

4438
foreach ($request->headers as $key => $value) {
45-
$key = strtoupper(str_replace('-', '_', $key));
39+
$key = \strtoupper(\str_replace('-', '_', $key));
4640

4741
if ($key == 'CONTENT_TYPE' || $key == 'CONTENT_LENGTH') {
48-
$server[$key] = implode(', ', $value);
42+
$server[$key] = \implode(', ', $value);
4943

5044
continue;
5145
}
5246

53-
$server['HTTP_' . $key] = implode(', ', $value);
47+
$server['HTTP_' . $key] = \implode(', ', $value);
5448
}
5549

5650
return $server;

src/HttpWorker.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@
3535
* }
3636
*
3737
* @see Request
38+
*
39+
* @api
3840
*/
3941
class HttpWorker implements HttpWorkerInterface
4042
{
4143
private static ?int $codec = null;
4244

4345
public function __construct(
4446
private readonly WorkerInterface $worker,
45-
) {
46-
}
47+
) {}
4748

4849
public function getWorker(): WorkerInterface
4950
{
@@ -83,13 +84,13 @@ public function waitRequest(): ?Request
8384
* @param array<array-key, array<array-key, string>> $headers
8485
* @throws \JsonException
8586
*/
86-
public function respond(int $status, string|Generator $body = '', array $headers = [], bool $endOfStream = true): void
87+
public function respond(int $status, string|\Generator $body = '', array $headers = [], bool $endOfStream = true): void
8788
{
8889
if ($status < 200 && $status >= 100 && $body !== '') {
8990
throw new \InvalidArgumentException('Unable to send a body with informational status code.');
9091
}
9192

92-
if ($body instanceof Generator) {
93+
if ($body instanceof \Generator) {
9394
$this->respondStream($status, $body, $headers, $endOfStream);
9495
return;
9596
}
@@ -101,7 +102,7 @@ public function respond(int $status, string|Generator $body = '', array $headers
101102
/**
102103
* @param array<array-key, array<array-key, string>> $headers
103104
*/
104-
private function respondStream(int $status, Generator $body, array $headers = [], bool $endOfStream = true): void
105+
private function respondStream(int $status, \Generator $body, array $headers = [], bool $endOfStream = true): void
105106
{
106107
$worker = $this->worker instanceof StreamWorkerInterface
107108
? $this->worker->withStreamMode()
@@ -110,20 +111,20 @@ private function respondStream(int $status, Generator $body, array $headers = []
110111
do {
111112
if (!$body->valid()) {
112113
// End of generator
113-
$content = (string)$body->getReturn();
114+
$content = (string) $body->getReturn();
114115
if ($endOfStream === false && $content === '') {
115116
// We don't need to send an empty frame if the stream is not ended
116117
return;
117118
}
118119
/** @psalm-suppress TooManyArguments */
119120
$worker->respond(
120121
$this->createRespondPayload($status, $content, $headers, $endOfStream),
121-
static::$codec
122+
static::$codec,
122123
);
123124
break;
124125
}
125126

126-
$content = (string)$body->current();
127+
$content = (string) $body->current();
127128
if ($worker->getPayload(StreamStop::class) !== null) {
128129
$body->throw(new StreamStoppedException());
129130

@@ -160,12 +161,12 @@ private function arrayToRequest(string $body, array $context): Request
160161
protocol: $context['protocol'],
161162
method: $context['method'],
162163
uri: $context['uri'],
163-
headers: $this->filterHeaders((array)($context['headers'] ?? [])),
164-
cookies: (array)($context['cookies'] ?? []),
165-
uploads: (array)($context['uploads'] ?? []),
164+
headers: $this->filterHeaders((array) ($context['headers'] ?? [])),
165+
cookies: (array) ($context['cookies'] ?? []),
166+
uploads: (array) ($context['uploads'] ?? []),
166167
attributes: [
167168
Request::PARSED_BODY_ATTRIBUTE_NAME => $context['parsed'],
168-
] + (array)($context['attributes'] ?? []),
169+
] + (array) ($context['attributes'] ?? []),
169170
query: $query,
170171
body: $body,
171172
parsed: $context['parsed'],
@@ -253,7 +254,7 @@ private function arrayToHeaderValue(array $headers = []): array
253254
*/
254255
foreach ($headers as $key => $value) {
255256
/** @psalm-suppress DocblockTypeContradiction */
256-
$value = \array_filter(\is_array($value) ? $value : [$value], static fn (mixed $v): bool => \is_string($v));
257+
$value = \array_filter(\is_array($value) ? $value : [$value], static fn(mixed $v): bool => \is_string($v));
257258
if ($value !== []) {
258259
$result[$key] = new HeaderValue(['value' => $value]);
259260
}
@@ -270,7 +271,7 @@ private function createRespondPayload(int $status, string $body, array $headers
270271
$head = static::$codec === Frame::CODEC_PROTO
271272
? (new Response(['status' => $status, 'headers' => $this->arrayToHeaderValue($headers)]))
272273
->serializeToString()
273-
: \json_encode(['status' => $status, 'headers' => $headers ?: (object)[]], \JSON_THROW_ON_ERROR);
274+
: \json_encode(['status' => $status, 'headers' => $headers ?: (object) []], \JSON_THROW_ON_ERROR);
274275

275276
return new Payload(body: $body, header: $head, eos: $eos);
276277
}

0 commit comments

Comments
 (0)