Skip to content

Commit 259685f

Browse files
committed
Fix phpstan
1 parent 9401423 commit 259685f

9 files changed

Lines changed: 180 additions & 211 deletions

File tree

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ parameters:
99
bootstrapFiles:
1010
- tools/bootstrap.php
1111
ignoreErrors:
12+
-
13+
identifier: method.alreadyNarrowedType
1214
-
1315
message: '#^Offset ''input'' does not exist on array\{\}\.$#'
1416
path: tests/integration/Http/Transport/CurlTransportTest.php

src/Http/SetCookie.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class SetCookie implements \Stringable
5050
/**
5151
* @var array<string,string|bool|int|null> Cookie data
5252
*/
53-
private ?array $data;
53+
private array $data;
5454

5555
/**
5656
* Create a new SetCookie object from a string.
@@ -96,7 +96,7 @@ public static function fromString(string $cookie): self
9696
}
9797

9898
/**
99-
* @param array<string,string|int> $data Array of cookie data provided by a Cookie parser
99+
* @param array<string,string|bool|int|null> $data Array of cookie data provided by a Cookie parser
100100
*/
101101
public function __construct(array $data = [])
102102
{
@@ -128,19 +128,17 @@ public function __toString(): string
128128
}
129129

130130
/**
131-
* @return (bool|int|string|null)[]|null
132-
*
133-
* @psalm-return array<string, bool|int|null|string>|null
131+
* @return array<string, bool|int|string|null>
134132
*/
135-
public function toArray(): ?array
133+
public function toArray(): array
136134
{
137135
return $this->data;
138136
}
139137

140138
/**
141139
* Get the cookie name.
142140
*/
143-
public function getName(): string|bool|int|null
141+
public function getName(): string
144142
{
145143
return $this->data['Name'];
146144
}
@@ -158,25 +156,25 @@ public function setName(string $name): void
158156
/**
159157
* Get the cookie value.
160158
*/
161-
public function getValue(): string|bool|int|null
159+
public function getValue(): ?string
162160
{
163161
return $this->data['Value'];
164162
}
165163

166164
/**
167165
* Set the cookie value.
168166
*
169-
* @param string|bool|int|null $value Cookie value
167+
* @param string $value Cookie value
170168
*/
171-
public function setValue(string|bool|int|null $value): void
169+
public function setValue(string $value): void
172170
{
173171
$this->data['Value'] = $value;
174172
}
175173

176174
/**
177175
* Get the domain.
178176
*/
179-
public function getDomain(): string|bool|int|null
177+
public function getDomain(): ?string
180178
{
181179
return $this->data['Domain'];
182180
}
@@ -192,7 +190,7 @@ public function setDomain(string $domain): void
192190
/**
193191
* Get the path.
194192
*/
195-
public function getPath(): string|bool|int|null
193+
public function getPath(): string
196194
{
197195
return $this->data['Path'];
198196
}
@@ -228,7 +226,7 @@ public function setMaxAge(int $maxAge): void
228226
/**
229227
* The UNIX timestamp when the cookie Expires.
230228
*/
231-
public function getExpires(): bool|int|string|null
229+
public function getExpires(): ?int
232230
{
233231
return $this->data['Expires'];
234232
}
@@ -246,9 +244,9 @@ public function setExpires(int|string $timestamp): void
246244
}
247245

248246
/**
249-
* Get whether or not this is a secure cookie.
247+
* Get whether this is a secure cookie.
250248
*/
251-
public function getSecure(): string|bool|int|null
249+
public function getSecure(): ?bool
252250
{
253251
return $this->data['Secure'];
254252
}
@@ -266,7 +264,7 @@ public function setSecure(bool $secure): void
266264
/**
267265
* Get whether or not this is a session cookie.
268266
*/
269-
public function getDiscard(): string|bool|int|null
267+
public function getDiscard(): ?bool
270268
{
271269
return $this->data['Discard'];
272270
}

src/Http/Transport/CurlTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private static function getHeadersAndContentFromCurlHandle(\CurlHandle $curlHand
194194
{
195195
$headers = [];
196196

197-
curl_setopt($curlHandle, \CURLOPT_HEADER, 1);
197+
curl_setopt($curlHandle, \CURLOPT_HEADER, true);
198198
$responseContent = curl_exec($curlHandle);
199199

200200
// @codeCoverageIgnoreStart

src/Parameters/CreateMeetingParameters.php

Lines changed: 142 additions & 143 deletions
Large diffs are not rendered by default.

tests/bootstrap.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,5 @@
3030

3131
// Load environment
3232
$dotenv = new Dotenv();
33-
// usePutenv was not available in version 3.4 und early 4.x versions of symfony/dotenv, so make it optional here
34-
if (method_exists($dotenv, 'usePutenv')) {
35-
$dotenv->usePutenv(true);
36-
}
37-
38-
// loadEnv was not available in version 3.4 und early 4.x versions of symfony/dotenv, so make it optional here
39-
if (method_exists($dotenv, 'loadEnv')) {
40-
$dotenv->loadEnv(dirname(__DIR__).'/.env');
41-
} else {
42-
$files = [];
43-
foreach ([dirname(__DIR__).'/.env', dirname(__DIR__).'/.env.local'] as $file) {
44-
if (file_exists($file)) {
45-
$files[] = $file;
46-
}
47-
}
48-
49-
$dotenv->load(...$files);
50-
}
33+
$dotenv->usePutenv();
34+
$dotenv->loadEnv(dirname(__DIR__).'/.env');

tests/integration/Http/Transport/CurlTransportTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public static function setUpBeforeClass(): void
4141
TestHttpServer::start();
4242
}
4343

44-
/** @return array<string,array<int>> */
44+
/**
45+
* @return iterable<string,array<int>>
46+
*/
4547
public static function provideBadResponseCodes(): iterable
4648
{
4749
// cURL does not understand codes below 200 properly.

tests/unit/Http/SetCookieTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testMatchesPath(string $cookiePath, string $requestPath, bool $i
181181
self::assertSame($isMatch, $cookie->matchesPath($requestPath));
182182
}
183183

184-
/** @return array<array<string|bool>> */
184+
/** @return array<array<string|bool|null>> */
185185
public static function cookieValidateProvider(): array
186186
{
187187
return [

tests/unit/Http/Transport/Bridge/SymfonyHttpClient/SymfonyHttpClientTransportTest.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public function testRequestWithoutPayload(): void
6363

6464
$this->assertSame('Hi Marty!', $response->getBody(), 'body is OK');
6565
$this->assertSame('MartyMcFlySession', $response->getSessionId(), 'session ID is OK');
66-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
67-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
68-
}
66+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
6967
}
7068

7169
public function testRequestWithPayload(): void
@@ -87,9 +85,7 @@ public function testRequestWithPayload(): void
8785

8886
$this->assertSame('Hi Marty!', $response->getBody(), 'body is OK');
8987
$this->assertSame('MartyMcFlySession', $response->getSessionId(), 'session ID is OK');
90-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
91-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
92-
}
88+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
9389
}
9490

9591
public function testRequestWithoutCookie(): void
@@ -110,9 +106,7 @@ public function testRequestWithoutCookie(): void
110106

111107
$this->assertSame('Hi Marty!', $response->getBody(), 'body is OK');
112108
$this->assertNull($response->getSessionId(), 'session ID is OK');
113-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
114-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
115-
}
109+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
116110
}
117111

118112
public function testRequestWithEmptyCookie(): void
@@ -133,9 +127,7 @@ public function testRequestWithEmptyCookie(): void
133127

134128
$this->assertSame('Hi Marty!', $response->getBody(), 'body is OK');
135129
$this->assertNull($response->getSessionId(), 'session ID is OK');
136-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
137-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
138-
}
130+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
139131
}
140132

141133
public function testRequestWithDefaultHeaders(): void
@@ -163,9 +155,7 @@ public function testRequestWithDefaultHeaders(): void
163155

164156
$this->assertSame('Hi Marty!', $response->getBody(), 'body is OK');
165157
$this->assertSame('MartyMcFlySession', $response->getSessionId(), 'session ID is OK');
166-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
167-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
168-
}
158+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
169159
}
170160

171161
public function testRequestWithDefaultOptions(): void
@@ -196,9 +186,7 @@ public function testRequestWithDefaultOptions(): void
196186

197187
$this->assertSame('Hi Marty!', $response->getBody(), 'body is OK');
198188
$this->assertSame('MartyMcFlySession', $response->getSessionId(), 'session ID is OK');
199-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
200-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
201-
}
189+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
202190
}
203191

204192
/** @return iterable<string,array<int>> */
@@ -237,9 +225,7 @@ public function testRequestWithBadResponseCode(int $badCode): void
237225
try {
238226
$transport->request($request);
239227
} finally {
240-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
241-
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
242-
}
228+
$this->assertSame(1, $mockHttpClient->getRequestsCount(), 'one request was made');
243229
}
244230
}
245231

@@ -275,9 +261,7 @@ public function testRequestWithBadResponseException(HttpExceptionInterface $exce
275261
try {
276262
$transport->request($request);
277263
} finally {
278-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
279-
$this->assertSame(0, $mockHttpClient->getRequestsCount(), 'no full request was made');
280-
}
264+
$this->assertSame(0, $mockHttpClient->getRequestsCount(), 'no full request was made');
281265
}
282266
}
283267

@@ -302,9 +286,7 @@ public function testRequestWithTransportException(): void
302286
try {
303287
$transport->request($request);
304288
} finally {
305-
if (method_exists($mockHttpClient, 'getRequestsCount')) {
306-
$this->assertSame(0, $mockHttpClient->getRequestsCount(), 'no full request was made');
307-
}
289+
$this->assertSame(0, $mockHttpClient->getRequestsCount(), 'no full request was made');
308290
}
309291
}
310292
}

tests/unit/Util/ArrayHelperTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
*/
3030
final class ArrayHelperTest extends TestCase
3131
{
32-
/** @return iterable<string,array<string|array-key,string|bool>> */
32+
/**
33+
* @return iterable<array{0: array<mixed>, 1: array<mixed>, 2: bool, 3: array<mixed>}>
34+
*/
3335
public static function provideArrays(): iterable
3436
{
3537
yield 'simple flat arrays' => [
@@ -61,9 +63,9 @@ public static function provideArrays(): iterable
6163
/**
6264
* @dataProvider provideArrays
6365
*
64-
* @param array<string|array-key,string> $input1
65-
* @param array<string|array-key,string> $input2
66-
* @param array<string|array-key,string> $output
66+
* @param array<mixed> $input1
67+
* @param array<mixed> $input2
68+
* @param array<mixed> $output
6769
*/
6870
public function testMergeRecursive(array $input1, array $input2, bool $reorderNested, array $output): void
6971
{

0 commit comments

Comments
 (0)