Skip to content

Commit e7f32c4

Browse files
authored
Merge pull request php-vcr#393 from php-vcr/392-apply-changed-codestyle-review-found-phpstan-recommendationsissues
392 apply changed codestyle review found phpstan recommendationsissues
2 parents 5c9417b + 6e1b61c commit e7f32c4

File tree

15 files changed

+27
-106
lines changed

15 files changed

+27
-106
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ parameters:
55
count: 1
66
path: src/VCR/Util/HttpUtil.php
77

8+
-
9+
message: "#^Method VCR\\\\Util\\\\HttpUtil\\:\\:parseHeaders\\(\\) should return array\\<string, string\\> but returns array\\<array\\<int, string\\>\\|string\\>\\.$#"
10+
count: 1
11+
path: src/VCR/Util/HttpUtil.php
12+
813
-
914
message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|false given\\.$#"
1015
count: 1

src/VCR/CodeTransform/CurlCodeTransform.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class CurlCodeTransform extends AbstractCodeTransform
2929
'/(?<!::|->|\w_)\\\?curl_errno\s*\(/i' => '\VCR\LibraryHooks\CurlHook::curl_errno(',
3030
];
3131

32-
/**
33-
* {@inheritdoc}
34-
*/
3532
protected function transformCode(string $code): string
3633
{
3734
$transformedCode = preg_replace(array_keys(self::$patterns), array_values(self::$patterns), $code);

src/VCR/CodeTransform/SoapCodeTransform.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class SoapCodeTransform extends AbstractCodeTransform
2626
'@extends\s+\\\?SoapClient\b@i',
2727
];
2828

29-
/**
30-
* {@inheritdoc}
31-
*/
3229
protected function transformCode(string $code): string
3330
{
3431
$transformedCode = preg_replace(self::$patterns, self::$replacements, $code);

src/VCR/LibraryHooks/CurlHook.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public function __construct(
6060
) {
6161
}
6262

63-
/**
64-
* {@inheritdoc}
65-
*/
6663
public function enable(\Closure $requestCallback): void
6764
{
6865
if (self::ENABLED == static::$status) {
@@ -78,19 +75,13 @@ public function enable(\Closure $requestCallback): void
7875
static::$status = self::ENABLED;
7976
}
8077

81-
/**
82-
* {@inheritdoc}
83-
*/
8478
public function disable(): void
8579
{
8680
self::$requestCallback = null;
8781

8882
static::$status = self::DISABLED;
8983
}
9084

91-
/**
92-
* {@inheritdoc}
93-
*/
9485
public function isEnabled(): bool
9586
{
9687
return self::ENABLED == self::$status;
@@ -135,7 +126,7 @@ public static function __callStatic($method, array $args)
135126
/**
136127
* @see http://www.php.net/manual/en/function.curl-init.php
137128
*/
138-
public static function curlInit(?string $url = null): \CurlHandle|false
129+
public static function curlInit(string $url = null): \CurlHandle|false
139130
{
140131
$curlHandle = curl_init($url);
141132
if (false !== $curlHandle) {
@@ -271,10 +262,8 @@ public static function curlMultiGetcontent(\CurlHandle $curlHandle): ?string
271262
* Get information regarding a specific transfer.
272263
*
273264
* @see http://www.php.net/manual/en/function.curl-getinfo.php
274-
*
275-
* @return mixed
276265
*/
277-
public static function curlGetinfo(\CurlHandle $curlHandle, int $option = 0)
266+
public static function curlGetinfo(\CurlHandle $curlHandle, int $option = 0): mixed
278267
{
279268
if (isset(self::$responses[(int) $curlHandle])) {
280269
return CurlHelper::getCurlOptionFromResponse(

src/VCR/LibraryHooks/SoapHook.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ public function doRequest(string $request, string $location, string $action, int
6767
return $response->getBody();
6868
}
6969

70-
/**
71-
* {@inheritdoc}
72-
*/
7370
public function enable(\Closure $requestCallback): void
7471
{
7572
self::$requestCallback = $requestCallback;
@@ -85,19 +82,13 @@ public function enable(\Closure $requestCallback): void
8582
$this->status = self::ENABLED;
8683
}
8784

88-
/**
89-
* {@inheritdoc}
90-
*/
9185
public function disable(): void
9286
{
9387
self::$requestCallback = null;
9488

9589
$this->status = self::DISABLED;
9690
}
9791

98-
/**
99-
* {@inheritdoc}
100-
*/
10192
public function isEnabled(): bool
10293
{
10394
return self::ENABLED == $this->status;

src/VCR/LibraryHooks/StreamWrapperHook.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@ class StreamWrapperHook implements LibraryHook
1717

1818
protected string $status = self::DISABLED;
1919

20-
/**
21-
* @var Response
22-
*/
23-
protected $response;
20+
protected Response $response;
2421

2522
/**
2623
* @var resource current stream context
2724
*/
2825
public $context;
2926

30-
/**
31-
* {@inheritdoc}
32-
*/
3327
public function enable(\Closure $requestCallback): void
3428
{
3529
self::$requestCallback = $requestCallback;
@@ -42,9 +36,6 @@ public function enable(\Closure $requestCallback): void
4236
$this->status = self::ENABLED;
4337
}
4438

45-
/**
46-
* {@inheritdoc}
47-
*/
4839
public function disable(): void
4940
{
5041
self::$requestCallback = null;
@@ -54,9 +45,6 @@ public function disable(): void
5445
$this->status = self::DISABLED;
5546
}
5647

57-
/**
58-
* {@inheritdoc}
59-
*/
6048
public function isEnabled(): bool
6149
{
6250
return self::ENABLED == $this->status;

src/VCR/Request.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,7 @@ public function getCurlOptions(): array
217217
return $this->curlOptions;
218218
}
219219

220-
/**
221-
* @return mixed
222-
*/
223-
public function getCurlOption(int $key)
220+
public function getCurlOption(int $key): mixed
224221
{
225222
if (empty($this->curlOptions[$key])) {
226223
return null;
@@ -278,18 +275,12 @@ public function removeHeader(string $key): void
278275
unset($this->headers[$key]);
279276
}
280277

281-
/**
282-
* @param mixed $value
283-
*/
284-
public function setPostField(string $key, $value): void
278+
public function setPostField(string $key, mixed $value): void
285279
{
286280
$this->postFields[$key] = $value;
287281
}
288282

289-
/**
290-
* @param mixed $value
291-
*/
292-
public function setCurlOption(int $key, $value): void
283+
public function setCurlOption(int $key, mixed $value): void
293284
{
294285
$this->curlOptions[$key] = $value;
295286
}

src/VCR/Response.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,21 @@ class Response
1818
/**
1919
* @var array<string,string>
2020
*/
21-
protected $headers = [];
22-
/**
23-
* @var string|null
24-
*/
25-
protected $body;
21+
protected array $headers = [];
22+
protected ?string $body;
2623
/**
2724
* @var array<string,mixed>
2825
*/
29-
protected $curlInfo = [];
26+
protected array $curlInfo = [];
3027

31-
/**
32-
* @var mixed
33-
*/
34-
protected $httpVersion;
28+
protected mixed $httpVersion;
3529

3630
/**
3731
* @param string|array<string, string> $status
3832
* @param array<string,string> $headers
3933
* @param array<string,mixed> $curlInfo
4034
*/
41-
final public function __construct($status, array $headers = [], ?string $body = null, array $curlInfo = [])
35+
final public function __construct($status, array $headers = [], string $body = null, array $curlInfo = [])
4236
{
4337
$this->setStatus($status);
4438
$this->headers = $headers;
@@ -57,11 +51,9 @@ public function toArray(): array
5751
// Base64 encode when binary
5852
if (
5953
null !== $this->getContentType()
60-
&&
61-
(
54+
&& (
6255
str_contains($this->getContentType(), 'application/x-gzip')
63-
||
64-
'binary' == $this->getHeader('Content-Transfer-Encoding')
56+
|| 'binary' == $this->getHeader('Content-Transfer-Encoding')
6557
)
6658
) {
6759
$body = base64_encode($body);
@@ -118,7 +110,7 @@ public function getBody(): string
118110
/**
119111
* @return array<string,mixed>|mixed|null
120112
*/
121-
public function getCurlInfo(?string $option = null)
113+
public function getCurlInfo(string $option = null): mixed
122114
{
123115
if (empty($option)) {
124116
return $this->curlInfo;
@@ -157,10 +149,7 @@ public function getHeader(string $key): ?string
157149
return $this->headers[$key];
158150
}
159151

160-
/**
161-
* @return mixed
162-
*/
163-
public function getHttpVersion()
152+
public function getHttpVersion(): mixed
164153
{
165154
return $this->httpVersion;
166155
}

src/VCR/Storage/Blackhole.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99
*/
1010
class Blackhole implements Storage
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
1512
public function storeRecording(array $recording): void
1613
{
1714
}
1815

19-
/**
20-
* {@inheritdoc}
21-
*/
2216
public function isNew(): bool
2317
{
2418
return true;

src/VCR/Storage/Json.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
*/
1313
class Json extends AbstractStorage
1414
{
15-
/**
16-
* {@inheritdoc}
17-
*/
1815
public function storeRecording(array $recording): void
1916
{
2017
fseek($this->handle, -1, \SEEK_END);

0 commit comments

Comments
 (0)