Skip to content

Commit f4f7972

Browse files
authored
Add missing types in Core (#1475)
* Add missing types in Core * Regenerate the Psalm baseline Those errors are false positives due to a type declaration in symfony/http-client that is not precise enough.
1 parent 1de8592 commit f4f7972

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+370
-57
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ parameters:
1111
- src/*/tests/*
1212
- src/**/tests/*
1313
- src/CodeGenerator/src/Generator/TestGenerator.php
14-
- src/Core/src/AbstractApi.php # requires symfony/http-client: 5.2
15-
- src/Core/src/HttpClient/AwsRetryStrategy.php # requires symfony/http-client: 5.2
1614
- src/Core/src/Test/TestCase.php
1715
- src/Integration/Laravel/Filesystem/src/AsyncAwsFilesystemManager.php
1816
- src/Integration/Laravel/Filesystem/src/AsyncAwsFilesystemAdapter.php

psalm.baseline.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
}]]></code>
3636
</InvalidCatch>
3737
</file>
38+
<file src="src/Core/src/Response.php">
39+
<LessSpecificReturnStatement>
40+
<code><![CDATA[$this->httpResponse->getHeaders(false)]]></code>
41+
</LessSpecificReturnStatement>
42+
<MoreSpecificReturnType>
43+
<code><![CDATA[array<string, list<string>>]]></code>
44+
</MoreSpecificReturnType>
45+
</file>
3846
<file src="src/Core/src/Waiter.php">
3947
<PossiblyUndefinedVariable>
4048
<code>$exception</code>

src/Core/src/AbstractApi.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use AsyncAws\Core\Credentials\ChainProvider;
1111
use AsyncAws\Core\Credentials\CredentialProvider;
1212
use AsyncAws\Core\EndpointDiscovery\EndpointCache;
13+
use AsyncAws\Core\EndpointDiscovery\EndpointInterface;
1314
use AsyncAws\Core\Exception\InvalidArgument;
1415
use AsyncAws\Core\Exception\LogicException;
1516
use AsyncAws\Core\Exception\RuntimeException;
@@ -47,7 +48,7 @@ abstract class AbstractApi
4748
private $credentialProvider;
4849

4950
/**
50-
* @var Signer[]
51+
* @var array<string, Signer>
5152
*/
5253
private $signers;
5354

@@ -67,7 +68,7 @@ abstract class AbstractApi
6768
private $endpointCache;
6869

6970
/**
70-
* @param Configuration|array $configuration
71+
* @param Configuration|array<Configuration::OPTION_*, string|null> $configuration
7172
*/
7273
public function __construct($configuration = [], ?CredentialProvider $credentialProvider = null, ?HttpClientInterface $httpClient = null, ?LoggerInterface $logger = null)
7374
{
@@ -151,7 +152,7 @@ final protected function getResponse(Request $request, ?RequestContext $context
151152
$request->setHeader('content-length', (string) $length);
152153
}
153154

154-
// Some servers (like testing Docker Images) does not supports `Transfer-Encoding: chunked` requests.
155+
// Some servers (like testing Docker Images) does not support `Transfer-Encoding: chunked` requests.
155156
// The body is converted into string to prevent curl using `Transfer-Encoding: chunked` unless it really has to.
156157
if (($requestBody = $request->getBody()) instanceof StringStream) {
157158
$requestBody = $requestBody->stringify();
@@ -178,7 +179,7 @@ final protected function getResponse(Request $request, ?RequestContext $context
178179
}
179180

180181
/**
181-
* @return callable[]
182+
* @return array<string, callable(string, string): Signer>
182183
*/
183184
protected function getSignerFactories(): array
184185
{
@@ -229,9 +230,9 @@ protected function getEndpointMetadata(?string $region): array
229230
/**
230231
* Build the endpoint full uri.
231232
*
232-
* @param string $uri or path
233-
* @param array $query parameters that should go in the query string
234-
* @param ?string $region region provided by the user in the `@region` parameter of the Input
233+
* @param string $uri or path
234+
* @param array<string, string> $query parameters that should go in the query string
235+
* @param ?string $region region provided by the user in the `@region` parameter of the Input
235236
*/
236237
protected function getEndpoint(string $uri, array $query, ?string $region): string
237238
{
@@ -263,11 +264,19 @@ protected function getEndpoint(string $uri, array $query, ?string $region): stri
263264
return $endpoint . (false === strpos($endpoint, '?') ? '?' : '&') . http_build_query($query, '', '&', \PHP_QUERY_RFC3986);
264265
}
265266

267+
/**
268+
* @return EndpointInterface[]
269+
*/
266270
protected function discoverEndpoints(?string $region): array
267271
{
268272
throw new LogicException(sprintf('The Client "%s" must implement the "%s" method.', \get_class($this), 'discoverEndpoints'));
269273
}
270274

275+
/**
276+
* @param array<string, string> $query
277+
*
278+
* @return string
279+
*/
271280
private function getDiscoveredEndpoint(string $uri, array $query, ?string $region, bool $usesEndpointDiscovery, bool $requiresEndpointDiscovery)
272281
{
273282
if (!$this->configuration->isDefault('endpoint')) {
@@ -314,7 +323,7 @@ private function getDiscoveredEndpoint(string $uri, array $query, ?string $regio
314323
/**
315324
* @param ?string $region region provided by the user in the `@region` parameter of the Input
316325
*/
317-
private function getSigner(?string $region)
326+
private function getSigner(?string $region): Signer
318327
{
319328
/** @var string $region */
320329
$region = $region ?? ($this->configuration->isDefault('region') ? null : $this->configuration->get('region'));

src/Core/src/AwsClientFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
class AwsClientFactory
6262
{
6363
/**
64-
* @var array
64+
* @var array<string, mixed>
6565
*/
6666
private $serviceCache;
6767

@@ -86,7 +86,7 @@ class AwsClientFactory
8686
private $logger;
8787

8888
/**
89-
* @param Configuration|array $configuration
89+
* @param Configuration|array<Configuration::OPTION_*, string|null> $configuration
9090
*/
9191
public function __construct($configuration = [], ?CredentialProvider $credentialProvider = null, ?HttpClientInterface $httpClient = null, ?LoggerInterface $logger = null)
9292
{

src/Core/src/AwsError/AwsError.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@
77
*/
88
final class AwsError
99
{
10+
/**
11+
* @var string|null
12+
*/
1013
private $code;
1114

15+
/**
16+
* @var string|null
17+
*/
1218
private $message;
1319

20+
/**
21+
* @var string|null
22+
*/
1423
private $type;
1524

25+
/**
26+
* @var string|null
27+
*/
1628
private $detail;
1729

1830
public function __construct(?string $code, ?string $message, ?string $type, ?string $detail)

src/Core/src/AwsError/AwsErrorFactoryInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ interface AwsErrorFactoryInterface
1111
{
1212
public function createFromResponse(ResponseInterface $response): AwsError;
1313

14+
/**
15+
* @param array<string, list<string>> $headers
16+
*/
1417
public function createFromContent(string $content, array $headers): AwsError;
1518
}

src/Core/src/AwsError/ChainAwsErrorFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class ChainAwsErrorFactory implements AwsErrorFactoryInterface
1111
{
1212
use AwsErrorFactoryFromResponseTrait;
1313

14+
/**
15+
* @var AwsErrorFactoryInterface[]
16+
*/
1417
private $factories;
1518

1619
/**

src/Core/src/AwsError/JsonRestAwsErrorFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public function createFromContent(string $content, array $headers): AwsError
2323
}
2424
}
2525

26+
/**
27+
* @param array<string, mixed> $body
28+
* @param array<string, list<string>> $headers
29+
*/
2630
private static function parseJson(array $body, array $headers): AwsError
2731
{
2832
$code = null;

src/Core/src/AwsError/JsonRpcAwsErrorFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public function createFromContent(string $content, array $headers): AwsError
2323
}
2424
}
2525

26+
/**
27+
* @param array<string, mixed> $body
28+
* @param array<string, list<string>> $headers
29+
*/
2630
private static function parseJson(array $body, array $headers): AwsError
2731
{
2832
$code = null;

src/Core/src/Configuration.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,20 @@ final class Configuration
8888
self::OPTION_ENDPOINT_DISCOVERY_ENABLED => 'false',
8989
];
9090

91+
/**
92+
* @var array<self::OPTION_*, string|null>
93+
*/
9194
private $data = [];
9295

96+
/**
97+
* @var array<self::OPTION_*, bool>
98+
*/
9399
private $userData = [];
94100

95-
public static function create(array $options)
101+
/**
102+
* @param array<self::OPTION_*, string|null> $options
103+
*/
104+
public static function create(array $options): self
96105
{
97106
if (0 < \count($invalidOptions = array_diff_key($options, self::AVAILABLE_OPTIONS))) {
98107
throw new InvalidArgument(sprintf('Invalid option(s) "%s" passed to "%s::%s". ', implode('", "', array_keys($invalidOptions)), __CLASS__, __METHOD__));
@@ -118,6 +127,8 @@ public static function optionExists(string $optionName): bool
118127
}
119128

120129
/**
130+
* @param self::OPTION_* $name
131+
*
121132
* @psalm-return (
122133
* $name is
123134
* self::OPTION_REGION
@@ -141,6 +152,9 @@ public function get(string $name): ?string
141152
return $this->data[$name] ?? null;
142153
}
143154

155+
/**
156+
* @param self::OPTION_* $name
157+
*/
144158
public function has(string $name): bool
145159
{
146160
if (!isset(self::AVAILABLE_OPTIONS[$name])) {
@@ -150,6 +164,9 @@ public function has(string $name): bool
150164
return isset($this->data[$name]);
151165
}
152166

167+
/**
168+
* @param self::OPTION_* $name
169+
*/
153170
public function isDefault(string $name): bool
154171
{
155172
if (!isset(self::AVAILABLE_OPTIONS[$name])) {
@@ -159,6 +176,11 @@ public function isDefault(string $name): bool
159176
return empty($this->userData[$name]);
160177
}
161178

179+
/**
180+
* @param array<self::OPTION_*, string|null> $options
181+
*
182+
* @return array<self::OPTION_*, string|null>
183+
*/
162184
private static function parseEnvironmentVariables(array $options): array
163185
{
164186
foreach (self::FALLBACK_OPTIONS as $fallbackGroup) {
@@ -187,6 +209,8 @@ private static function parseEnvironmentVariables(array $options): array
187209

188210
/**
189211
* Look for "region" in the configured ini files.
212+
*
213+
* @return array<self::OPTION_*, string|null>
190214
*/
191215
private static function parseIniFiles(Configuration $configuration): array
192216
{
@@ -215,6 +239,8 @@ private static function parseIniFiles(Configuration $configuration): array
215239

216240
/**
217241
* Add array options to the configuration object.
242+
*
243+
* @param array<self::OPTION_*, string|null> $options
218244
*/
219245
private static function populateConfiguration(Configuration $configuration, array $options): void
220246
{

src/Core/src/Credentials/CacheProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
final class CacheProvider implements CredentialProvider, ResetInterface
1818
{
1919
/**
20-
* @var (Credentials|null)[]
20+
* @var array<string, Credentials|null>
2121
*/
2222
private $cache = [];
2323

24+
/**
25+
* @var CredentialProvider
26+
*/
2427
private $decorated;
2528

2629
public function __construct(CredentialProvider $decorated)

src/Core/src/Credentials/ChainProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
*/
2222
final class ChainProvider implements CredentialProvider, ResetInterface
2323
{
24+
/**
25+
* @var iterable<CredentialProvider>
26+
*/
2427
private $providers;
2528

2629
/**
27-
* @var (CredentialProvider|null)[]
30+
* @var array<string, CredentialProvider|null>
2831
*/
2932
private $lastSuccessfulProvider = [];
3033

3134
/**
32-
* @param CredentialProvider[] $providers
35+
* @param iterable<CredentialProvider> $providers
3336
*/
3437
public function __construct(iterable $providers)
3538
{

src/Core/src/Credentials/ConfigurationProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ final class ConfigurationProvider implements CredentialProvider
2020
{
2121
use DateFromResult;
2222

23+
/**
24+
* @var LoggerInterface
25+
*/
2326
private $logger;
2427

28+
/**
29+
* @var HttpClientInterface|null
30+
*/
2531
private $httpClient;
2632

2733
public function __construct(?HttpClientInterface $httpClient = null, ?LoggerInterface $logger = null)

src/Core/src/Credentials/ContainerProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ final class ContainerProvider implements CredentialProvider
2222
{
2323
private const ENDPOINT = 'http://169.254.170.2';
2424

25+
/**
26+
* @var LoggerInterface
27+
*/
2528
private $logger;
2629

30+
/**
31+
* @var HttpClientInterface
32+
*/
2733
private $httpClient;
2834

35+
/**
36+
* @var float
37+
*/
2938
private $timeout;
3039

3140
public function __construct(?HttpClientInterface $httpClient = null, ?LoggerInterface $logger = null, float $timeout = 1.0)

src/Core/src/Credentials/Credentials.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,24 @@ final class Credentials implements CredentialProvider
1515
{
1616
private const EXPIRATION_DRIFT = 30;
1717

18+
/**
19+
* @var string
20+
*/
1821
private $accessKeyId;
1922

23+
/**
24+
* @var string
25+
*/
2026
private $secretKey;
2127

28+
/**
29+
* @var string|null
30+
*/
2231
private $sessionToken;
2332

33+
/**
34+
* @var \DateTimeImmutable|null
35+
*/
2436
private $expireDate;
2537

2638
public function __construct(

src/Core/src/Credentials/IniFileLoader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ final class IniFileLoader
2424
public const KEY_SOURCE_PROFILE = 'source_profile';
2525
public const KEY_WEB_IDENTITY_TOKEN_FILE = 'web_identity_token_file';
2626

27+
/**
28+
* @var LoggerInterface
29+
*/
2730
private $logger;
2831

2932
public function __construct(?LoggerInterface $logger = null)
@@ -34,7 +37,7 @@ public function __construct(?LoggerInterface $logger = null)
3437
/**
3538
* @param string[] $filepaths
3639
*
37-
* @return string[][]
40+
* @return array<string, array<string, string>>
3841
*/
3942
public function loadProfiles(array $filepaths): array
4043
{
@@ -83,6 +86,9 @@ private function getHomeDir(): string
8386
return ($homeDrive && $homePath) ? $homeDrive . $homePath : '/';
8487
}
8588

89+
/**
90+
* @return array<string, string[]>
91+
*/
8692
private function parseIniFile(string $filepath): array
8793
{
8894
if (false === $data = parse_ini_string(

0 commit comments

Comments
 (0)