Skip to content

Commit b102ff5

Browse files
Static analysis fixes (#203)
* Fixed bug in the cookie plugin * Fixed typo in phpdoc * Clarified plugin client factory type information * Added extra type information to help phpstan * Don't temprarily violate property types in the flexible http client * Removed redundent information * Cast null to string for date parsing * Added additional type to help phpstan * Run phpstan on actions
1 parent 788697e commit b102ff5

17 files changed

+111
-47
lines changed

.gitattributes

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
.editorconfig export-ignore
2-
.gitattributes export-ignore
3-
/.github/ export-ignore
4-
.gitignore export-ignore
5-
/.php_cs export-ignore
6-
/.scrutinizer.yml export-ignore
7-
/.styleci.yml export-ignore
8-
/behat.yml.dist export-ignore
9-
/features/ export-ignore
10-
/phpspec.ci.yml export-ignore
11-
/phpspec.yml.dist export-ignore
12-
/phpunit.xml.dist export-ignore
13-
/spec/ export-ignore
14-
/tests/ export-ignore
1+
.editorconfig export-ignore
2+
.gitattributes export-ignore
3+
/.github/ export-ignore
4+
.gitignore export-ignore
5+
/.php_cs export-ignore
6+
/.scrutinizer.yml export-ignore
7+
/.styleci.yml export-ignore
8+
/behat.yml.dist export-ignore
9+
/features/ export-ignore
10+
/phpspec.ci.yml export-ignore
11+
/phpspec.yml.dist export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/phpstan.neon.dist export-ignore
14+
/spec/ export-ignore
15+
/tests/ export-ignore

.github/workflows/static.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: static
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
phpstan:
9+
name: PHPStan
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: PHPStan
17+
uses: OskarStark/[email protected]
18+
env:
19+
REQUIRE_DEV: false
20+
with:
21+
args: analyze --no-progress

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/composer.lock
66
/phpspec.yml
77
/phpunit.xml
8+
/phpstan.neon
89
/vendor/

.php_cs.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ return PhpCsFixer\Config::create()
1818
'syntax' => 'short',
1919
],
2020
'no_empty_phpdoc' => true,
21-
'no_superfluous_phpdoc_tags' => true,
21+
'phpdoc_to_comment' => false,
2222
'single_line_throw' => false,
2323
])
2424
->setFinder($finder);

phpstan.neon.dist

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
parameters:
2+
level: max
3+
checkMissingIterableValueType: false
4+
treatPhpDocTypesAsCertain: false
5+
paths:
6+
- src
7+
ignoreErrors:
8+
-
9+
message: "#^Strict comparison using \\!\\=\\= between null and null will always evaluate to false\\.$#"
10+
count: 1
11+
path: src/HttpMethodsClient.php
12+
13+
-
14+
message: "#^Cannot call method createStream\\(\\) on Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\|null\\.$#"
15+
count: 1
16+
path: src/HttpMethodsClient.php
17+
18+
-
19+
message: "#^Method Http\\\\Client\\\\Common\\\\Plugin\\\\Journal\\:\\:addSuccess\\(\\) has no return typehint specified\\.$#"
20+
count: 1
21+
path: src/Plugin/Journal.php
22+
23+
-
24+
message: "#^Method Http\\\\Client\\\\Common\\\\Plugin\\\\Journal\\:\\:addFailure\\(\\) has no return typehint specified\\.$#"
25+
count: 1
26+
path: src/Plugin/Journal.php
27+
28+
-
29+
message: "#^Call to an undefined method Http\\\\Client\\\\HttpAsyncClient\\:\\:sendRequest\\(\\)\\.$#"
30+
count: 1
31+
path: src/PluginClient.php

src/Deferred.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function wait($unwrap = true)
146146
return $this->value;
147147
}
148148

149+
/** @var ClientExceptionInterface */
149150
throw $this->failure;
150151
}
151152
}

src/Exception/HttpClientNoMatchException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
final class HttpClientNoMatchException extends TransferException
1616
{
17+
/**
18+
* @var RequestInterface
19+
*/
1720
private $request;
1821

1922
public function __construct(string $message, RequestInterface $request, \Exception $previous = null)

src/FlexibleHttpClient.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ public function __construct($client)
3030
);
3131
}
3232

33-
$this->httpClient = $client;
34-
$this->httpAsyncClient = $client;
35-
36-
if (!($this->httpClient instanceof ClientInterface)) {
37-
$this->httpClient = new EmulatedHttpClient($this->httpClient);
38-
}
39-
40-
if (!($this->httpAsyncClient instanceof HttpAsyncClient)) {
41-
$this->httpAsyncClient = new EmulatedHttpAsyncClient($this->httpAsyncClient);
42-
}
33+
$this->httpClient = $client instanceof ClientInterface ? $client : new EmulatedHttpClient($client);
34+
$this->httpAsyncClient = $client instanceof HttpAsyncClient ? $client : new EmulatedHttpAsyncClient($client);
4335
}
4436
}

src/HttpClientPool/HttpClientPool.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ abstract class HttpClientPool implements HttpClientPoolInterface
2525
/**
2626
* Add a client to the pool.
2727
*
28-
* @param ClientInterface|HttpAsyncClient|HttpClientPoolItem $client
28+
* @param ClientInterface|HttpAsyncClient $client
2929
*/
3030
public function addHttpClient($client): void
3131
{
32-
if (!$client instanceof ClientInterface && !$client instanceof HttpAsyncClient && !$client instanceof HttpClientPoolItem) {
32+
// no need to check for HttpClientPoolItem here, since it extends the other interfaces
33+
if (!$client instanceof ClientInterface && !$client instanceof HttpAsyncClient) {
3334
throw new \TypeError(
34-
sprintf('%s::addHttpClient(): Argument #1 ($client) must be of type %s|%s|%s, %s given', self::class, ClientInterface::class, HttpAsyncClient::class, HttpClientPoolItem::class, get_debug_type($client))
35+
sprintf('%s::addHttpClient(): Argument #1 ($client) must be of type %s|%s, %s given', self::class, ClientInterface::class, HttpAsyncClient::class, get_debug_type($client))
3536
);
3637
}
3738

src/HttpClientRouter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
final class HttpClientRouter implements HttpClientRouterInterface
2020
{
2121
/**
22-
* @var array
22+
* @var (array{matcher: RequestMatcher, client: FlexibleHttpClient})[]
2323
*/
2424
private $clients = [];
2525

@@ -60,10 +60,8 @@ public function addClient($client, RequestMatcher $requestMatcher): void
6060

6161
/**
6262
* Choose an HTTP client given a specific request.
63-
*
64-
* @return ClientInterface|HttpAsyncClient
6563
*/
66-
private function chooseHttpClient(RequestInterface $request)
64+
private function chooseHttpClient(RequestInterface $request): FlexibleHttpClient
6765
{
6866
foreach ($this->clients as $client) {
6967
if ($client['matcher']->matches($request)) {

0 commit comments

Comments
 (0)