php-standard-library / psalm-plugin
Psalm plugin for the PHP Standard Library
Installs: 1 439 516
Dependents: 32
Suggesters: 1
Security: 0
Stars: 24
Watchers: 4
Forks: 6
Open Issues: 1
Type:psalm-plugin
Requires
- php: ^8.1
- vimeo/psalm: >=5.16
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.5
Conflicts
- azjezz/psl: <2.0
README
Installation
Supported installation method is via composer:
composer require php-standard-library/psalm-plugin --dev
Usage
To enable the plugin, add the Psl\Psalm\Plugin
class to your psalm configuration using psalm-plugin
binary as follows:
php vendor/bin/psalm-plugin enable php-standard-library/psalm-plugin
Type improvements
Given the following example:
use Psl\Type; $specification = Type\shape([ 'name' => Type\string(), 'age' => Type\int(), 'location' => Type\optional(Type\shape([ 'city' => Type\string(), 'state' => Type\string(), 'country' => Type\string(), ])) ]); $input = $specification->coerce($_GET['user']); /** @psalm-trace $input */
Psalm assumes that $input
is of type array<"age"|"location"|"name", array<"city"|"country"|"state", string>|int|string>
.
If we enable the php-standard-library/psalm-plugin
plugin, you will get a more specific
and correct type of array{name: string, age: int, location?: array{city: string, state: string, country: string}}
.
Compatibility
Sponsors
Thanks to our sponsors and supporters:
License
The MIT License (MIT). Please see LICENSE
for more information.