Skip to content

Add more precise types for the Symfony bundle #1490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

class AsyncAwsExtension extends Extension
{
/**
* @param mixed[] $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand All @@ -33,6 +36,33 @@ public function load(array $configs, ContainerBuilder $container): void
$this->autowireServices($container, $usedServices);
}

/**
* @param array{
* register_service: bool,
* logger?: string|null,
* http_client?: string|null,
* credential_provider: string|null,
* credential_provider_cache: string|null,
* config: array<string, mixed>,
* secrets: array{
* enabled: bool,
* client: string|null,
* path: string|null,
* recursive: bool,
* cache: array{enabled: bool, pool: string, ttl: int},
* },
* clients: array<string, array{
* type: string,
* register_service: bool,
* logger?: string|null,
* http_client?: string|null,
* credential_provider: string|null,
* config: array<string, mixed>,
* }>,
* } $config
*
* @return array<string, string|null>
*/
private function registerConfiguredServices(ContainerBuilder $container, array $config): array
{
$availableServices = AwsPackagesProvider::getAllServices();
Expand All @@ -59,6 +89,20 @@ private function registerConfiguredServices(ContainerBuilder $container, array $
return $usedServices;
}

/**
* @param array{
* register_service: bool,
* clients: array<string, mixed>,
* logger?: string|null,
* http_client?: string|null,
* credential_provider: string|null,
* credential_provider_cache: string|null,
* config: array<string, mixed>,
* } $config
* @param array<string, string|null> $usedServices
*
* @return array<string, string|null>
*/
private function registerInstalledServices(ContainerBuilder $container, array $config, array $usedServices): array
{
if (!$config['register_service']) {
Expand All @@ -84,6 +128,17 @@ private function registerInstalledServices(ContainerBuilder $container, array $c
return $usedServices;
}

/**
* @param array{
* register_service: bool,
* logger?: string|null,
* http_client?: string|null,
* credential_provider: string|null,
* credential_provider_cache: string|null,
* config: array<string, mixed>,
* ...
* } $config
*/
private function addServiceDefinition(ContainerBuilder $container, string $name, array $config, string $clientClass): void
{
if (\array_key_exists('logger', $config)) {
Expand Down Expand Up @@ -147,6 +202,24 @@ private function addServiceDefinition(ContainerBuilder $container, string $name,
$container->setDefinition(sprintf('async_aws.client.%s', $name), $definition);
}

/**
* @param array{
* register_service: bool,
* logger?: string|null,
* http_client?: string|null,
* credential_provider: string|null,
* credential_provider_cache: string|null,
* config: array<string, mixed>,
* secrets: array{
* enabled: bool,
* client: string|null,
* path: string|null,
* recursive: bool,
* cache: array{enabled: bool, pool: string, ttl: int},
* },
* clients: array<string, array{type: string, ...}>,
* } $config
*/
private function registerEnvLoader(ContainerBuilder $container, array $config): void
{
if (!$config['secrets']['enabled']) {
Expand Down Expand Up @@ -201,6 +274,9 @@ private function registerEnvLoader(ContainerBuilder $container, array $config):
}
}

/**
* @param array<string, string|null> $usedServices
*/
private function autowireServices(ContainerBuilder $container, array $usedServices): void
{
$awsServices = AwsPackagesProvider::getAllServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

namespace AsyncAws\Symfony\Bundle\DependencyInjection;

use AsyncAws\Core\AbstractApi;

class AwsPackagesProvider
{
/**
* @return array<string, array{class: class-string<AbstractApi>, package: string}>
*/
public static function getAllServices(): array
{
return [
Expand Down Expand Up @@ -172,6 +177,9 @@ public static function getAllServices(): array
];
}

/**
* @return list<string>
*/
public static function getServiceNames(): array
{
$services = self::getAllServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public function getConfigTreeBuilder(): TreeBuilder
return $treeBuilder;
}

private static function validateType(?array $clients)
/**
* @param null|array<string, array{type?: string, ...}> $clients
*
* @return array<string, array{type?: string, ...}>
*/
private static function validateType(?array $clients): array
{
if (null === $clients) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@

class CachedEnvVarLoader implements EnvVarLoaderInterface
{
/**
* @var EnvVarLoaderInterface
*/
private $decorated;

/**
* @var CacheInterface
*/
private $cache;

/**
* @var int
*/
private $ttl;

public function __construct(EnvVarLoaderInterface $decorated, CacheInterface $cache, int $ttl)
Expand Down
9 changes: 9 additions & 0 deletions src/Integration/Symfony/Bundle/src/Secrets/SsmVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@

class SsmVault implements EnvVarLoaderInterface
{
/**
* @var SsmClient
*/
private $client;

/**
* @var string
*/
private $path;

/**
* @var bool
*/
private $recursive;

public function __construct(SsmClient $client, ?string $path, bool $recursive)
Expand Down
14 changes: 12 additions & 2 deletions src/Integration/Symfony/Bundle/src/VarDumper/ResultCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

class ResultCaster
{
public static function castResult(Result $result, array $a, Stub $stub, bool $isNested)
/**
* @param array<string, mixed> $a
*
* @return array<string, mixed>
*/
public static function castResult(Result $result, array $a, Stub $stub, bool $isNested): array
{
foreach (["\0AsyncAws\\Core\\Result\0httpClient", "\0AsyncAws\\Core\\Result\0response", "\0AsyncAws\\Core\\Result\0prefetchResults", Caster::PREFIX_PROTECTED . 'awsClient', Caster::PREFIX_PROTECTED . 'input'] as $k) {
if (\array_key_exists($k, $a)) {
Expand All @@ -21,7 +26,12 @@ public static function castResult(Result $result, array $a, Stub $stub, bool $is
return $a;
}

public static function castWaiter(Waiter $waiter, array $a, Stub $stub, bool $isNested)
/**
* @param array<string, mixed> $a
*
* @return array<string, mixed>
*/
public static function castWaiter(Waiter $waiter, array $a, Stub $stub, bool $isNested): array
{
foreach (["\0AsyncAws\\Core\\Waiter\0httpClient", "\0AsyncAws\\Core\\Waiter\0response", Caster::PREFIX_PROTECTED . 'awsClient', Caster::PREFIX_PROTECTED . 'input'] as $k) {
if (\array_key_exists($k, $a)) {
Expand Down