Skip to content

Commit 1d4506a

Browse files
authored
Generate valid phpdoc param tags (#1457)
* Fix the phpdoc of the RequestContext * Generate valid phpdoc param tags When an array shape key starts with a `@` like `@region`, it must be quoted in the phpdoc as the unquoted one would be interpreted as the next phpdoc tag. * Use an unsealed shape for the type in Input This avoids reports about passing extra keys from child classes in Psalm. * Allow passing null as the region in the input The base input class already accept null values in addition to omitted values for the region. * Update the psalm baseline * Disallow invalid docblocks in Psalm as well
1 parent c826df1 commit 1d4506a

File tree

337 files changed

+633
-1194
lines changed

Some content is hidden

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

337 files changed

+633
-1194
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ parameters:
1717
- src/Integration/Laravel/Filesystem/src/AsyncAwsFilesystemAdapter.php
1818

1919
ignoreErrors:
20-
- '#^PHPDoc tag @param has invalid value#'
2120
- '#^Parameter \#1 \$input of class AsyncAws\\[^\\]+\\ValueObject\\[^ ]+ constructor expects (array\(\)\|)?array\([^\)]+\), array\([^\)]+\) given\.#'
21+
- '#^Parameter \#1 \$input of method AsyncAws\\DynamoDb\\DynamoDbClient::\w+\(\) expects array\{[^\)]+\}\|AsyncAws\\DynamoDb\\Input\\\w+Input, array\{[^\)]+\} given\.#'
2222
- '#Method AsyncAws\\[^:]+::[^(]+\(\) should return array<[^>]+> but returns array<int(\|string)?, string>\.$#'
2323
- '#PHPDoc tag @throws with type Psr\\Cache\\CacheException is not subtype of Throwable$#'
2424
- '#^Dead catch - JsonException is never thrown in the try block\.$#'

psalm.baseline.xml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="5.1.0@4defa177c89397c5e14737a80fe4896584130674">
3+
<file src="src/Core/src/AbstractApi.php">
4+
<UndefinedFunction occurrences="2">
5+
<code>trigger_deprecation('async-aws/core', '1.2', 'Extending "%s"" without overriding "%s" is deprecated. This method will be abstract in version 2.0.', __CLASS__, __FUNCTION__)</code>
6+
<code>trigger_deprecation('async-aws/core', '1.2', 'providing an endpoint with placeholder is deprecated and will be ignored in version 2.0. Provide full endpoint instead.')</code>
7+
</UndefinedFunction>
8+
</file>
39
<file src="src/Core/src/Credentials/PsrCacheProvider.php">
410
<InvalidCatch occurrences="1"/>
511
<InvalidThrow occurrences="1">
@@ -27,7 +33,22 @@
2733
<code>$exception</code>
2834
</PossiblyUndefinedVariable>
2935
</file>
36+
<file src="src/Integration/Aws/DynamoDbSession/src/SessionHandler.php">
37+
<ArgumentTypeCoercion occurrences="6">
38+
<code>['TableName' =&gt; $this-&gt;options['table_name']]</code>
39+
</ArgumentTypeCoercion>
40+
</file>
41+
<file src="src/Integration/Aws/SimpleS3/src/SimpleS3Client.php">
42+
<ArgumentTypeCoercion occurrences="1"/>
43+
<InvalidArgument occurrences="2">
44+
<code>array_merge($options, ['Bucket' =&gt; $bucket, 'Key' =&gt; $key])</code>
45+
</InvalidArgument>
46+
</file>
47+
<file src="src/Integration/Flysystem/S3/src/AsyncAwsS3Adapter.php">
48+
<InvalidArgument occurrences="2"/>
49+
</file>
3050
<file src="src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php">
51+
<InvalidArgument occurrences="7"/>
3152
<RedundantCast occurrences="1">
3253
<code>(int) $e-&gt;getCode()</code>
3354
</RedundantCast>
@@ -52,13 +73,23 @@
5273
</UndefinedInterfaceMethod>
5374
</file>
5475
<file src="src/Integration/Laravel/Mail/src/Transport/AsyncAwsSesTransport.php">
55-
<InvalidArgument occurrences="1"/>
76+
<InvalidArgument occurrences="2">
77+
<code>array_merge($this-&gt;options, $input)</code>
78+
</InvalidArgument>
79+
</file>
80+
<file src="src/Integration/Laravel/Queue/src/Job/AsyncAwsSqsJob.php">
81+
<ArgumentTypeCoercion occurrences="2"/>
5682
</file>
5783
<file src="src/Integration/Laravel/Queue/src/ServiceProvider.php">
5884
<UndefinedInterfaceMethod occurrences="1">
5985
<code>$this-&gt;app</code>
6086
</UndefinedInterfaceMethod>
6187
</file>
88+
<file src="src/Integration/Monolog/CloudWatch/src/CloudWatchLogsHandler.php">
89+
<ArgumentTypeCoercion occurrences="1">
90+
<code>$data</code>
91+
</ArgumentTypeCoercion>
92+
</file>
6293
<file src="src/Integration/Symfony/Bundle/src/DependencyInjection/Configuration.php">
6394
<PossiblyNullReference occurrences="1">
6495
<code>scalarNode</code>

psalm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<MissingClosureReturnType errorLevel="info" />
4242
<MissingReturnType errorLevel="info" />
4343
<MissingPropertyType errorLevel="info" />
44-
<InvalidDocblock errorLevel="info" />
4544

4645
<PropertyNotSetInConstructor errorLevel="info" />
4746
<MissingConstructor errorLevel="info" />

src/CodeGenerator/src/Generator/InputGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function generate(Operation $operation): ClassName
278278

279279
$constructorBody .= 'parent::__construct($input);';
280280
$constructor = $classBuilder->addMethod('__construct');
281-
[$doc, $memberClassNames] = $this->typeGenerator->generateDocblock($shape, $className, false, true, false, [' @region?: string,']);
281+
[$doc, $memberClassNames] = $this->typeGenerator->generateDocblock($shape, $className, false, true, false, [' \'@region\'?: string|null,']);
282282
$constructor->addComment($doc);
283283
foreach ($memberClassNames as $memberClassName) {
284284
$classBuilder->addUse($memberClassName->getFqdn());

src/CodeGenerator/src/Generator/OperationGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function generate(Operation $operation): void
119119
if (null !== $prefix = $operation->getService()->getEndpointPrefix()) {
120120
$method->addComment('@see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-' . $prefix . '-' . $operation->getService()->getApiVersion() . '.html#' . strtolower($operation->getName()));
121121
}
122-
[$doc, $memberClassNames] = $this->typeGenerator->generateDocblock($inputShape, $inputClass, true, false, false, [' @region?: string,']);
122+
[$doc, $memberClassNames] = $this->typeGenerator->generateDocblock($inputShape, $inputClass, true, false, false, [' \'@region\'?: string|null,']);
123123
$method->addComment($doc);
124124
foreach ($memberClassNames as $memberClassName) {
125125
$classBuilder->addUse($memberClassName->getFqdn());

src/CodeGenerator/src/Generator/WaiterGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function generateMethod(ClassBuilder $classBuilder, Waiter $waiter, Oper
9999
$resultClass = $this->generateWaiterResult($waiter);
100100
$classBuilder->addUse($resultClass->getFqdn());
101101

102-
[$doc, $memberClassNames] = $this->typeGenerator->generateDocblock($inputShape, $inputClass, true, false, false, [' @region?: string,']);
102+
[$doc, $memberClassNames] = $this->typeGenerator->generateDocblock($inputShape, $inputClass, true, false, false, [' \'@region\'?: string|null,']);
103103

104104
$mapping = [];
105105
foreach ($operation->getErrors() as $error) {

src/Core/src/Input.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ abstract class Input
1717
public $region;
1818

1919
/**
20-
* @param array{
21-
*
22-
* @region?: ?string,
23-
* } $input
20+
* @param array{'@region'?: ?string,...} $input
2421
*/
2522
protected function __construct(array $input)
2623
{

src/Core/src/RequestContext.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ class RequestContext
6060

6161
/**
6262
* @param array{
63-
* operation?: null|string
64-
* region?: null|string
65-
* expirationDate?: null|\DateTimeImmutable
66-
* currentDate?: null|\DateTimeImmutable
67-
* exceptionMapping?: string[]
68-
* usesEndpointDiscovery?: bool
69-
* requiresEndpointDiscovery?: bool
70-
* }
63+
* operation?: null|string,
64+
* region?: null|string,
65+
* expirationDate?: null|\DateTimeImmutable,
66+
* currentDate?: null|\DateTimeImmutable,
67+
* exceptionMapping?: string[],
68+
* usesEndpointDiscovery?: bool,
69+
* requiresEndpointDiscovery?: bool,
70+
* } $options
7171
*/
7272
public function __construct(array $options = [])
7373
{

src/Core/src/Sts/Input/AssumeRoleRequest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ final class AssumeRoleRequest extends Input
241241
* SerialNumber?: string,
242242
* TokenCode?: string,
243243
* SourceIdentity?: string,
244-
*
245-
* @region?: string,
244+
* '@region'?: string|null,
246245
* } $input
247246
*/
248247
public function __construct(array $input = [])

src/Core/src/Sts/Input/AssumeRoleWithWebIdentityRequest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ final class AssumeRoleWithWebIdentityRequest extends Input
138138
* PolicyArns?: PolicyDescriptorType[],
139139
* Policy?: string,
140140
* DurationSeconds?: int,
141-
*
142-
* @region?: string,
141+
* '@region'?: string|null,
143142
* } $input
144143
*/
145144
public function __construct(array $input = [])

0 commit comments

Comments
 (0)