Skip to content

Commit 1b48554

Browse files
committed
Add PHPStan static analysis setup
Add PHPStan as a Composer dev dependency, configure phpstan.neon at level 6, add the Composer analyse script, and fix reported iterable type issues across the SDK and tests. Integration tests requiring valid tokens remain skipped.
1 parent fc3c231 commit 1b48554

8 files changed

Lines changed: 45 additions & 5 deletions

File tree

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
},
5252
"require-dev": {
5353
"symfony/dotenv": "^5.3",
54-
"phpunit/phpunit": "^9.5"
54+
"phpunit/phpunit": "^9.5",
55+
"phpstan/phpstan": "^2.1"
5556
},
5657
"autoload": {
5758
"psr-4": {
@@ -67,6 +68,7 @@
6768
}
6869
},
6970
"scripts": {
71+
"analyse": "vendor/bin/phpstan analyse -c phpstan.neon",
7072
"test": "phpunit tests/",
7173
"test:unit": "phpunit tests/ --testsuite=unit",
7274
"example:token": "php examples/token_generation.php",

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
- tests

src/Cache/ArrayCache.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
class ArrayCache implements CacheInterface
66
{
7+
/**
8+
* @var array<string, mixed>
9+
*/
710
private array $cache = [];
11+
/**
12+
* @var array<string, int>
13+
*/
814
private array $expiry = [];
915

1016
public function get(string $key): mixed

src/Client.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ public function __construct(?string $token = null, HttpTransportInterface|PsrCli
2121
$this->transport = $transport ?? new CurlTransport($this->token);
2222
}
2323

24+
/**
25+
* Execute HTTP request
26+
*
27+
* @param string $method HTTP method (GET, POST, PUT, DELETE, PATCH)
28+
* @param string $url Target URL
29+
* @param mixed $payload Request body (for POST/PUT/PATCH)
30+
* @param array<string, scalar|null>|null $params Query parameters (for GET) or form data (for other methods)
31+
* @return string Response body
32+
*/
2433
public function request(
2534
string $method,
2635
string $url,
@@ -34,6 +43,11 @@ public function request(
3443
return $this->transport->request($method, $url, $payload, $params);
3544
}
3645

46+
/**
47+
* Execute GET request
48+
*
49+
* @param array<string, scalar|null>|null $params Query parameters
50+
*/
3751
public function get(string $url, ?array $params = null): string
3852
{
3953
return $this->request('GET', $url, null, $params);

src/Interfaces/HttpTransportInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
interface HttpTransportInterface
66
{
7+
/**
8+
* @param array<string, mixed>|string|null $params
9+
*/
710
public function request(
811
string $method,
912
string $url,
1013
mixed $payload = null,
11-
?array $params = null
14+
array|string|null $params = null
1215
): string;
1316
}

src/OauthClient.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function getScopes(bool $limit = false): string
2828
return $this->request('GET', $url);
2929
}
3030

31+
/**
32+
* @param list<string> $scopes
33+
*/
3134
public function createToken(array $scopes, int $ttl = 3600): string
3235
{
3336
$body = [
@@ -56,6 +59,10 @@ public function getCounters(string $period, string $date): string
5659
return $this->request('GET', $this->url . '/counters/' . $period . '/' . $date);
5760
}
5861

62+
63+
/**
64+
* @param array<string, mixed>|null $body
65+
*/
5966
private function request(string $method, string $url, ?array $body = null): string
6067
{
6168
$ch = curl_init();

src/Transports/CurlTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function request(
1414
string $method,
1515
string $url,
1616
mixed $payload = null,
17-
?array $params = null
17+
array|string|null $params = null
1818
): string {
1919
if ($params && $method === 'GET') {
2020
$url .= '?' . http_build_query($params);

tests/Transports/FakeTransport.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ final class FakeTransport implements HttpTransportInterface
99
public ?string $lastMethod = null;
1010
public ?string $lastUrl = null;
1111
public mixed $lastPayload = null;
12-
public ?array $lastParams = null;
12+
/**
13+
* @var array<string, mixed>|string|null
14+
*/
15+
public array|string|null $lastParams = null;
1316
public int $callCount = 0;
1417

1518
public function request(
1619
string $method,
1720
string $url,
1821
mixed $payload = null,
19-
?array $params = null
22+
array|string|null $params = null
2023
): string {
2124
$this->callCount++;
2225
$this->lastMethod = $method;

0 commit comments

Comments
 (0)