php-standard-library/psalm-plugin

Psalm plugin for the PHP Standard Library

Installs: 61 515

Dependents: 6

Suggesters: 1

Security: 0

Stars: 4

Watchers: 3

Forks: 2

Open Issues: 0

Type:psalm-plugin

1.1.1 2021-04-11 12:56 UTC

This package is auto-updated.

Last update: 2021-10-11 13:59:06 UTC


README

Static analysis status Type Coverage Total Downloads Latest Stable Version License

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

Sponsors

Thanks to our sponsors and supporters:

JetBrains
68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f617a6a657a7a2f696d6167652f75706c6f61642f76313539393233393931302f6a6574627261696e735f716e7962306f2e706e67

License

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