Skip to content

About

PHPStan extension for thesis packages: precise types where PHPDoc generics cannot express them.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

Thesis PHPStan Extension

PHP Version Requirement GitHub Release

A PHPStan extension for the thesis packages: precise types where the generics of PHPDoc cannot express them. One extension for all packages: it does nothing for a package you do not use.

Installation

composer require --dev thesis/phpstan-extension

With phpstan/extension-installer that is all. Otherwise include the config:

includes:
    - vendor/thesis/phpstan-extension/extension.neon

Requires PHPStan 2.3+.

thesis/async

all() and allSettled() of an array shape of callables return the shape of their results, a type per key:

use function PHPStan\Testing\assertType;
use function Thesis\Async\all;
use function Thesis\Async\allSettled;

$report = all([
    'sales' => loadSales(...),
    'costs' => loadCosts(...),
]);
assertType('array{sales: Sales, costs: Costs}', $report);
// without the extension: array<'sales'|'costs', Sales|Costs>

[$results, $errors] = allSettled(['sales' => loadSales(...), 'costs' => loadCosts(...)]);
assertType('array{sales?: Sales, costs?: Costs}', $results);
assertType('array{sales?: Throwable, costs?: Throwable}', $errors);

all() and map() keep what is known of the keys of their input: a shape gives a shape, a list gives a list, a non-empty array a non-empty one.

use function Thesis\Async\map;

/** @var non-empty-list<string> $urls */
assertType('non-empty-list<Response>', map($urls, 10, fetch(...)));
// without the extension: array<int<0, max>, Response>

assertType('array{sales: Report, costs: Report}', map(['sales' => $sales, 'costs' => $costs], 2, report(...)));
// without the extension: array<'sales'|'costs', Report>

Without such a key or for a generator, the type of the PHPDoc stays. race(), timeout(), group() and the others need no extension: their generics are precise.

About

PHPStan extension for thesis packages: precise types where PHPDoc generics cannot express them.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages