Skip to content

Commit 6f28a00

Browse files
committed
Add Psalm
1 parent e829db0 commit 6f28a00

File tree

8 files changed

+38
-15
lines changed

8 files changed

+38
-15
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
- "8.1"
5858

5959
dependencies:
60+
- "lowest"
6061
- "highest"
6162

6263
steps:
@@ -94,6 +95,7 @@ jobs:
9495
- "8.1"
9596

9697
dependencies:
98+
- "lowest"
9799
- "highest"
98100

99101
steps:
@@ -113,4 +115,4 @@ jobs:
113115
dependency-versions: "${{ matrix.dependencies }}"
114116

115117
- name: "Static analysis"
116-
run: "composer phpstan"
118+
run: "composer analyse"

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
},
2424
"require-dev": {
2525
"ergebnis/composer-normalize": "^2.28",
26-
"phpstan/phpstan": "^0.12.64",
2726
"phpunit/phpunit": "^9.4.3",
2827
"sylius-labs/coding-standard": "^4.2",
2928
"symfony/cache": "^6.0",
30-
"symfony/http-client": "^6.0"
29+
"symfony/http-client": "^6.0",
30+
"vimeo/psalm": "^4.26"
3131
},
3232
"provide": {
3333
"symfony/http-client-implementation": "^2.3.1"
@@ -44,8 +44,8 @@
4444
}
4545
},
4646
"scripts": {
47+
"analyse": "psalm",
4748
"check-style": "ecs check",
48-
"fix-style": "ecs check --fix",
49-
"phpstan": "vendor/bin/phpstan analyse --level max src tests"
49+
"fix-style": "ecs check --fix"
5050
}
5151
}

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
errorLevel="1"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
phpVersion="8.1"
8+
>
9+
<projectFiles>
10+
<directory name="src"/>
11+
<ignoreFiles>
12+
<directory name="vendor"/>
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/GrantType/TokensExtractor.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ private function extractTokens(ResponseInterface $response): Tokens
3131
throw new OAuthException('Error when calling token endpoint.', 0, $e);
3232
}
3333

34-
$token = json_decode($responseBody, true);
34+
try {
35+
$token = json_decode($responseBody, true, 512, \JSON_THROW_ON_ERROR);
36+
} catch (\JsonException $e) {
37+
throw new OAuthException(
38+
'Error when parsing token endpoint JSON response. JSON error was: ' . $e->getMessage(),
39+
0,
40+
$e,
41+
);
42+
}
3543

3644
if ($token === null && $responseBody !== 'null') {
3745
throw new OAuthException('Error when parsing token endpoint JSON response.');
@@ -41,6 +49,6 @@ private function extractTokens(ResponseInterface $response): Tokens
4149
throw new OAuthException('Access token not found in token endpoint response.');
4250
}
4351

44-
return new Tokens($token['access_token'], $token['refresh_token'] ?? null);
52+
return new Tokens($token['access_token'], isset($token['refresh_token']) && is_string($token['refresh_token']) ? $token['refresh_token'] : null);
4553
}
4654
}

src/OAuthHttpClient.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Contracts\HttpClient\ResponseInterface;
1818
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
1919

20-
class OAuthHttpClient implements HttpClientInterface
20+
final class OAuthHttpClient implements HttpClientInterface
2121
{
2222
private HttpClientInterface $client;
2323

@@ -61,9 +61,6 @@ public function setCache(TokensCacheInterface $cache): self
6161
return $this;
6262
}
6363

64-
/**
65-
* @param array<string, mixed> $options
66-
*/
6764
public function request(string $method, string $url, array $options = []): ResponseInterface
6865
{
6966
$grant = $this->grant;

src/RequestSigner/HeaderRequestSigner.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public function __construct(string $headerName, string $headerValueFormat)
1818

1919
public function modify(array &$options, string $token): void
2020
{
21+
if (!array_key_exists('headers', $options) || !is_array($options['headers'])) {
22+
return;
23+
}
24+
2125
$options['headers'][$this->headerName] = str_replace('{token}', $token, $this->headerValueFormat);
2226
}
2327
}

src/RequestSigner/RequestSignerInterface.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface RequestSignerInterface
88
{
9-
/**
10-
* @param array<string, mixed> $options
11-
*/
129
public function modify(array &$options, string $token): void;
1310
}

src/TokensCache/MemoryTokensCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class MemoryTokensCache implements TokensCacheInterface
1111
{
12-
private ?Tokens $tokens;
12+
private ?Tokens $tokens = null;
1313

1414
public function get(GrantTypeInterface $grant): Tokens
1515
{

0 commit comments

Comments
 (0)