Download the PHP package rikudou/aws-sdk-phpstan without Composer
On this page you can find all versions of the php package rikudou/aws-sdk-phpstan. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rikudou/aws-sdk-phpstan
More information about rikudou/aws-sdk-phpstan
Files in rikudou/aws-sdk-phpstan
Package aws-sdk-phpstan
Short Description Allows strong typing for AWS SDK
License MIT
Informations about the package aws-sdk-phpstan
AWS SDK PHPStan extension
This extension helps PHPStan to correctly determine the return type of all the SDK api calls.
Table of contents
- AWS SDK PHPStan extension
- Installation
- Usage
- How does it work?
- Fine-tuning
Installation
composer require --dev rikudou/aws-sdk-phpstan
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use `phpstan/extension-installer`, include extension.neon in your project's PHPStan config:Usage
You can simply use AWS SDK as usual, except all return types are strongly typed and PHPStan knows exactly what type each key is.
Note that using
treatPhpDocTypesAsCertain: false
in your phpstan.neon makes this extension entirely useless as all errors reported by the strong typing will be ignored.
For example:
This prints the following:
Strict comparison using === between null and 'SomeName' will always evaluate to false.
That's because PHPStan knows that there's no property called Name
!
Or something more specific:
ChecksumType indeed exists, but it's very strictly typed to only two possible values, neither of which is md5. And indeed, PHPStan tells us:
Strict comparison using === between 'COMPOSITE'|'FULL_OBJECT' and 'md5' will always evaluate to false.
If you were to dump the PHPStan type of the $object
variable, you'd get the following:
How does it work?
There's a build script that traverses the official AWS SDK for PHP data and extracts type information from them. Afterwards it converts the information to a PHPStan extension class that provides dynamic types based on the method being called (for example the S3ClientReturnTypeExtension.).
Additionally, the AWS Result
class is made generic using a stub file.
Fine-tuning
By default, every single one of AWS clients is generated which can slow down PHPStan significantly and is rarely needed.
The build script is included as part of the package, so you can automatically generate only the classes that interest you,
for example if you wanted to only work with S3Client
and CloudFrontClient
, you could do the following:
composer.json:
Then, as part of your process, run the vendor/bin/generate-aws-phpstan
. For example using the post install script
of composer.json:
If you now check the vendor/rikudou/aws-sdk-phpstan/src/Types
directory, you should only see the following two files:
CloudFrontClientReturnTypeExtension.php
S3ClientReturnTypeExtension.php
Additionally, the vendor/rikudou/aws-sdk-phpstan/extension.neon
should now only include the two above services.