Chainable types do not work
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
No source file, test, or entry point is named. Start by reproducing the supplied PHP example and tracing the chainable Assert::that()->nullOr()->string()->numeric() inference; done when $payload['percent'] is inferred as string|null and the closure error is gone.
Written by the indexing model from the issue text.
Description
the following code:
<?php
declare(strict_types=1);
use Assert\Assert;
class Result
{
private ?float $percent;
private function __construct()
{
}
/** @param array<string, mixed> $payload */
public static function fromQueryResults(array $payload): self
{
Assert::that($payload['percent'])
->nullOr()
->string()
->numeric();
$floatOrNull = static fn (?string $value): ?float => null === $value ? null : (float) $value;
$instance = new self();
$instance->percent = $floatOrNull($payload['percent']);
return $instance;
}
}
Produces the error:
Parameter #1 $value of closure expects string|null, float|int|string|null given.
The type of $payload['percent'] should be infered to string|null, not float|int|string|null
- Dominant language
- PHP
- Stars
- 43
- Forks
- 16
- Avg merge
- 10d 5h
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-beberlei-assert
-
Dependency Dashboard Open
Difficulty 4/5 3-5 days Newbie friendliness 15/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
All issues in phpstan/phpstan-beberlei-assert
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·