Go to file
2021-03-27 21:50:28 +01:00
.github create psalm plugin 2021-03-27 19:33:18 +01:00
src remove dependency on psl 2021-03-27 21:50:28 +01:00
.editorconfig Initial commit 2021-03-26 10:10:46 +01:00
.gitattributes Initial commit 2021-03-26 10:10:46 +01:00
.gitignore create psalm plugin 2021-03-27 19:33:18 +01:00
.php_cs.dist create psalm plugin 2021-03-27 19:33:18 +01:00
.phpcs.xml create psalm plugin 2021-03-27 19:33:18 +01:00
CHANGELOG.md Initial commit 2021-03-26 10:10:46 +01:00
CODE_OF_CONDUCT.md Initial commit 2021-03-26 10:10:46 +01:00
composer.json remove dependency on psl 2021-03-27 21:50:28 +01:00
LICENSE Initial commit 2021-03-26 10:10:46 +01:00
psalm.xml create psalm plugin 2021-03-27 19:33:18 +01:00
README.md create psalm plugin 2021-03-27 19:33:18 +01:00
SECURITY.md Initial commit 2021-03-26 10:10:46 +01:00

PSL Psalm Plugin

Static analysis status Type Coverage Total Downloads Latest Stable Version License

Installation

Supported installation method is via composer:

composer install 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}}.

Sponsors

Thanks to our sponsors and supporters:

JetBrains

License

The MIT License (MIT). Please see LICENSE for more information.