Skip to content

Commit 8582e9d

Browse files
pl-githubtemp
authored andcommitted
fix: Raise phpstan level to 6
1 parent 94e9f35 commit 8582e9d

30 files changed

+76
-80
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
push:
88
branches:
99
- "master"
10-
- "fix/composer-devtools"
1110

1211
jobs:
1312
tests:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"jangregor/phpstan-prophecy": "^1.0",
2222
"mikey179/vfsstream": "^1.6.11",
2323
"monolog/monolog": "^2.3|^3.0",
24-
"phpstan/phpstan": "^1.2",
24+
"phpstan/phpstan": "^1.10",
2525
"phpstan/phpstan-phpunit": "^1.0",
2626
"phpstan/phpstan-symfony": "^1.0",
2727
"phpunit/phpunit": "^10.5",

phpstan.neon.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 6
33
paths:
44
- src
55
- tests
@@ -18,6 +18,7 @@ parameters:
1818
- '#Method Brainbits\\FunctionalTestHelpers\\Tests\\Uuid\\UuidTraitTest::.*\(\) is protected, but since the containing class is final, it can be private#'
1919
- '#Method Brainbits\\FunctionalTestHelpers\\Tests\\ZipContents\\ZipContentsTraitTest::.*\(\) is protected, but since the containing class is final, it can be private#'
2020
- '#Safe\\DateTimeImmutable#'
21+
- '#SchemaBuilder::foo\(\)#'
2122
ergebnis:
2223
noNullableReturnTypeDeclaration:
2324
enabled: false

src/HttpClientMock/MockRequestBuilder.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ final class MockRequestBuilder
5454
/** @var array<string,string> */
5555
private array $uriParams = [];
5656

57-
/** @var mixed[] */
57+
/** @var mixed[]|null */
5858
private array|null $headers = null;
5959

60-
/** @var mixed[] */
60+
/** @var mixed[]|null */
6161
private array|null $queryParams = null;
6262

6363
private string|null $content = null;
6464

65-
/** @var mixed[] */
65+
/** @var mixed[]|null */
6666
private array|null $multiparts = null;
6767

68-
/** @var callable(MockRequestBuilder $expectation, MockRequestBuilder $realRequest): ?string */
68+
/** @var callable(MockRequestBuilder $expectation, MockRequestBuilder $realRequest): ?string|null */
6969
private mixed $that = null;
7070

7171
private MockResponseCollection $responses;
7272

7373
/** @var self[] */
7474
private array $calls = [];
7575

76-
/** @var callable */
77-
public $onMatch;
76+
/** @var callable|null */
77+
public mixed $onMatch = null;
7878

7979
public function __construct()
8080
{
@@ -127,13 +127,12 @@ public function hasHeaders(): bool
127127
return $this->headers !== null;
128128
}
129129

130-
/** @return mixed[] */
130+
/** @return mixed[]|null */
131131
public function getHeaders(): array|null
132132
{
133133
return $this->headers;
134134
}
135135

136-
/** @return mixed */
137136
public function hasHeader(string $key): bool
138137
{
139138
return array_key_exists($key, $this->headers);
@@ -201,7 +200,6 @@ public function getJson(): array|null
201200
return json_decode($this->content, true);
202201
}
203202

204-
/** @param mixed[] $data */
205203
public function xml(string $data): self
206204
{
207205
if (!$this->isXmlString($data)) {
@@ -299,7 +297,7 @@ public function multipartFileFromFile(string $name, File $file): self
299297
return $this;
300298
}
301299

302-
/** @return mixed[] */
300+
/** @return mixed[]|null */
303301
public function getMultiparts(): array|null
304302
{
305303
return $this->multiparts;

src/HttpClientMock/MockRequestBuilderCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __invoke(string $method, string $url, array $options): ResponseI
3333
$requestBuilder = ($this->requestResolver)($this, $realRequest);
3434
$requestBuilder->called($realRequest);
3535

36-
if ($requestBuilder->onMatch && is_callable($requestBuilder->onMatch)) {
36+
if ($requestBuilder->onMatch && is_callable($requestBuilder->onMatch)) { // @phpstan-ignore-line
3737
($requestBuilder->onMatch)($realRequest);
3838
}
3939

src/HttpClientMock/MockRequestBuilderFactory.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use function array_key_exists;
1111
use function assert;
1212
use function explode;
13+
use function is_array;
1314
use function is_callable;
1415
use function is_string;
1516
use function Safe\fopen;
@@ -60,22 +61,31 @@ private function processBody(
6061

6162
// application/json; charset=utf-8
6263
if (strpos($contentType, 'application/json') === 0) {
63-
$mockRequestBuilder->json(json_decode($body, true));
64+
if (is_string($body)) {
65+
$mockRequestBuilder->json(json_decode($body, true));
66+
} elseif (is_callable($body)) {
67+
$mockRequestBuilder->json(json_decode((string) $body(), true));
68+
} elseif (is_array($body)) {
69+
$mockRequestBuilder->json($body);
70+
} else {
71+
throw UnprocessableBody::create();
72+
}
6473

6574
return;
6675
}
6776

68-
if (
69-
strpos($contentType, 'application/x-www-form-urlencoded') === 0
70-
&& preg_match('/[^=]+=[^=]*(&[^=]+=[^=]*)*/', (string) $body)
71-
) {
72-
foreach (explode('&', $body) as $keyValue) {
73-
[$key, $value] = explode('=', $keyValue);
77+
if (strpos($contentType, 'application/x-www-form-urlencoded') === 0) {
78+
assert(is_string($body));
7479

75-
$mockRequestBuilder->requestParam(urldecode($key), urldecode($value));
76-
}
80+
if (preg_match('/[^=]+=[^=]*(&[^=]+=[^=]*)*/', $body)) {
81+
foreach (explode('&', $body) as $keyValue) {
82+
[$key, $value] = explode('=', $keyValue);
7783

78-
return;
84+
$mockRequestBuilder->requestParam(urldecode($key), urldecode($value));
85+
}
86+
87+
return;
88+
}
7989
}
8090

8191
// multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__
@@ -114,6 +124,18 @@ private function processBody(
114124
return;
115125
}
116126

117-
$mockRequestBuilder->content($body);
127+
if (is_string($body)) {
128+
$mockRequestBuilder->content($body);
129+
130+
return;
131+
}
132+
133+
if (is_callable($body)) {
134+
$mockRequestBuilder->content((string) $body());
135+
136+
return;
137+
}
138+
139+
throw UnprocessableBody::create();
118140
}
119141
}

src/HttpClientMock/MockRequestMatch.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public static function mismatchingMultiparts(array $multiparts, array|null $othe
130130
);
131131
}
132132

133-
/** @param mixed $value */
134133
public static function missingHeader(string $key, string $value): self
135134
{
136135
return new self(

src/HttpClientMock/MockRequestMatcher.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ public function __invoke(MockRequestBuilder $expectation, MockRequestBuilder $re
150150
$match->matchesContent($expectation->getContent());
151151
}
152152

153-
if (
154-
$expectation->getMultiparts() !== null
155-
&& ($this->compare)($expectation->getMultiparts(), $realRequest->getMultiparts())
156-
) {
153+
if ($expectation->getMultiparts() !== null) {
157154
$match->matchesMultiparts($expectation->getMultiparts());
158155
}
159156

src/HttpClientMock/MockRequestResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public function __construct()
1818
$this->matcher = new MockRequestMatcher();
1919
}
2020

21-
/** @param mixed[] $options */
2221
public function __invoke(
2322
MockRequestBuilderCollection $requestBuilders,
2423
MockRequestBuilder $realRequest,

src/HttpClientMock/MockResponseFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88

99
interface MockResponseFactory
1010
{
11-
/** @return mixed */
1211
public function fromRequestBuilder(MockRequestBuilder $requestBuilder): MockResponse;
1312
}

0 commit comments

Comments
 (0)