Skip to content

Commit 512e3f8

Browse files
authored
Add more precise types for the Symfony bundle (#1490)
1 parent 40e9ae7 commit 512e3f8

File tree

6 files changed

+120
-3
lines changed

6 files changed

+120
-3
lines changed

src/DependencyInjection/AsyncAwsExtension.php

+76
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
class AsyncAwsExtension extends Extension
2424
{
25+
/**
26+
* @param mixed[] $configs
27+
*/
2528
public function load(array $configs, ContainerBuilder $container): void
2629
{
2730
$configuration = new Configuration();
@@ -33,6 +36,33 @@ public function load(array $configs, ContainerBuilder $container): void
3336
$this->autowireServices($container, $usedServices);
3437
}
3538

39+
/**
40+
* @param array{
41+
* register_service: bool,
42+
* logger?: string|null,
43+
* http_client?: string|null,
44+
* credential_provider: string|null,
45+
* credential_provider_cache: string|null,
46+
* config: array<string, mixed>,
47+
* secrets: array{
48+
* enabled: bool,
49+
* client: string|null,
50+
* path: string|null,
51+
* recursive: bool,
52+
* cache: array{enabled: bool, pool: string, ttl: int},
53+
* },
54+
* clients: array<string, array{
55+
* type: string,
56+
* register_service: bool,
57+
* logger?: string|null,
58+
* http_client?: string|null,
59+
* credential_provider: string|null,
60+
* config: array<string, mixed>,
61+
* }>,
62+
* } $config
63+
*
64+
* @return array<string, string|null>
65+
*/
3666
private function registerConfiguredServices(ContainerBuilder $container, array $config): array
3767
{
3868
$availableServices = AwsPackagesProvider::getAllServices();
@@ -59,6 +89,20 @@ private function registerConfiguredServices(ContainerBuilder $container, array $
5989
return $usedServices;
6090
}
6191

92+
/**
93+
* @param array{
94+
* register_service: bool,
95+
* clients: array<string, mixed>,
96+
* logger?: string|null,
97+
* http_client?: string|null,
98+
* credential_provider: string|null,
99+
* credential_provider_cache: string|null,
100+
* config: array<string, mixed>,
101+
* } $config
102+
* @param array<string, string|null> $usedServices
103+
*
104+
* @return array<string, string|null>
105+
*/
62106
private function registerInstalledServices(ContainerBuilder $container, array $config, array $usedServices): array
63107
{
64108
if (!$config['register_service']) {
@@ -84,6 +128,17 @@ private function registerInstalledServices(ContainerBuilder $container, array $c
84128
return $usedServices;
85129
}
86130

131+
/**
132+
* @param array{
133+
* register_service: bool,
134+
* logger?: string|null,
135+
* http_client?: string|null,
136+
* credential_provider: string|null,
137+
* credential_provider_cache: string|null,
138+
* config: array<string, mixed>,
139+
* ...
140+
* } $config
141+
*/
87142
private function addServiceDefinition(ContainerBuilder $container, string $name, array $config, string $clientClass): void
88143
{
89144
if (\array_key_exists('logger', $config)) {
@@ -147,6 +202,24 @@ private function addServiceDefinition(ContainerBuilder $container, string $name,
147202
$container->setDefinition(sprintf('async_aws.client.%s', $name), $definition);
148203
}
149204

205+
/**
206+
* @param array{
207+
* register_service: bool,
208+
* logger?: string|null,
209+
* http_client?: string|null,
210+
* credential_provider: string|null,
211+
* credential_provider_cache: string|null,
212+
* config: array<string, mixed>,
213+
* secrets: array{
214+
* enabled: bool,
215+
* client: string|null,
216+
* path: string|null,
217+
* recursive: bool,
218+
* cache: array{enabled: bool, pool: string, ttl: int},
219+
* },
220+
* clients: array<string, array{type: string, ...}>,
221+
* } $config
222+
*/
150223
private function registerEnvLoader(ContainerBuilder $container, array $config): void
151224
{
152225
if (!$config['secrets']['enabled']) {
@@ -201,6 +274,9 @@ private function registerEnvLoader(ContainerBuilder $container, array $config):
201274
}
202275
}
203276

277+
/**
278+
* @param array<string, string|null> $usedServices
279+
*/
204280
private function autowireServices(ContainerBuilder $container, array $usedServices): void
205281
{
206282
$awsServices = AwsPackagesProvider::getAllServices();

src/DependencyInjection/AwsPackagesProvider.php

+8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
namespace AsyncAws\Symfony\Bundle\DependencyInjection;
66

7+
use AsyncAws\Core\AbstractApi;
8+
79
class AwsPackagesProvider
810
{
11+
/**
12+
* @return array<string, array{class: class-string<AbstractApi>, package: string}>
13+
*/
914
public static function getAllServices(): array
1015
{
1116
return [
@@ -172,6 +177,9 @@ public static function getAllServices(): array
172177
];
173178
}
174179

180+
/**
181+
* @return list<string>
182+
*/
175183
public static function getServiceNames(): array
176184
{
177185
$services = self::getAllServices();

src/DependencyInjection/Configuration.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ public function getConfigTreeBuilder(): TreeBuilder
6363
return $treeBuilder;
6464
}
6565

66-
private static function validateType(?array $clients)
66+
/**
67+
* @param null|array<string, array{type?: string, ...}> $clients
68+
*
69+
* @return array<string, array{type?: string, ...}>
70+
*/
71+
private static function validateType(?array $clients): array
6772
{
6873
if (null === $clients) {
6974
return [];

src/Secrets/CachedEnvVarLoader.php

+9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@
88

99
class CachedEnvVarLoader implements EnvVarLoaderInterface
1010
{
11+
/**
12+
* @var EnvVarLoaderInterface
13+
*/
1114
private $decorated;
1215

16+
/**
17+
* @var CacheInterface
18+
*/
1319
private $cache;
1420

21+
/**
22+
* @var int
23+
*/
1524
private $ttl;
1625

1726
public function __construct(EnvVarLoaderInterface $decorated, CacheInterface $cache, int $ttl)

src/Secrets/SsmVault.php

+9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@
88

99
class SsmVault implements EnvVarLoaderInterface
1010
{
11+
/**
12+
* @var SsmClient
13+
*/
1114
private $client;
1215

16+
/**
17+
* @var string
18+
*/
1319
private $path;
1420

21+
/**
22+
* @var bool
23+
*/
1524
private $recursive;
1625

1726
public function __construct(SsmClient $client, ?string $path, bool $recursive)

src/VarDumper/ResultCaster.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
class ResultCaster
1111
{
12-
public static function castResult(Result $result, array $a, Stub $stub, bool $isNested)
12+
/**
13+
* @param array<string, mixed> $a
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public static function castResult(Result $result, array $a, Stub $stub, bool $isNested): array
1318
{
1419
foreach (["\0AsyncAws\\Core\\Result\0httpClient", "\0AsyncAws\\Core\\Result\0response", "\0AsyncAws\\Core\\Result\0prefetchResults", Caster::PREFIX_PROTECTED . 'awsClient', Caster::PREFIX_PROTECTED . 'input'] as $k) {
1520
if (\array_key_exists($k, $a)) {
@@ -21,7 +26,12 @@ public static function castResult(Result $result, array $a, Stub $stub, bool $is
2126
return $a;
2227
}
2328

24-
public static function castWaiter(Waiter $waiter, array $a, Stub $stub, bool $isNested)
29+
/**
30+
* @param array<string, mixed> $a
31+
*
32+
* @return array<string, mixed>
33+
*/
34+
public static function castWaiter(Waiter $waiter, array $a, Stub $stub, bool $isNested): array
2535
{
2636
foreach (["\0AsyncAws\\Core\\Waiter\0httpClient", "\0AsyncAws\\Core\\Waiter\0response", Caster::PREFIX_PROTECTED . 'awsClient', Caster::PREFIX_PROTECTED . 'input'] as $k) {
2737
if (\array_key_exists($k, $a)) {

0 commit comments

Comments
 (0)