Skip to content

php-standard-library/phpstan-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e3e7773 · Nov 11, 2024

History

34 Commits
Nov 11, 2024
Jun 10, 2022
Nov 11, 2024
Jun 10, 2022
Nov 11, 2024
Jun 10, 2022
Jun 10, 2022
Jun 10, 2022
May 25, 2022
Jun 10, 2022
Jun 10, 2022
Nov 11, 2024
Jun 10, 2022
Jun 10, 2022
May 25, 2022
May 25, 2022

Repository files navigation

PHPStan PSL extension

Build Latest Stable Version License

Description

The main goal of this extension is to help PHPStan to detect the types after using Psl\Type\shape.

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']);

PHPStan assumes that $input is of type array<"age"|"location"|"name", array<"city"|"country"|"state", string>|int|string>.

If we enable the extension, you will get a more specific and correct type of array{name: string, age: int, location?: array{city: string, state: string, country: string}}.

Besides coerce, this extension also supports matches() and assert() methods.

Installation

To use this extension, require it in Composer:

composer require --dev php-standard-library/phpstan-extension

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:

includes:
    - vendor/php-standard-library/phpstan-extension/extension.neon