feat: add @valinor-* annotations to override an unparseable type - #830
Merged
Conversation
PHPStan and Psalm accept type syntaxes that this library cannot parse,
for instance a conditional type like `($a is 1 ? int : null)`. Such a
type ends up unresolvable, and the only way out was to remove or weaken
the annotation, making the static analysis tools lose information the
library was not able to use anyway.
The annotations `@valinor-var`, `@valinor-param` and `@valinor-return`
can now declare a type that only this library reads. They take
precedence over their `@phpstan-*`, `@psalm-*` and native counterparts,
so both worlds can be served by the same docblock:
```php
final class SomeClass
{
/**
* @phpstan-param ($a is 1 ? int : null) $b
* @valinor-param int|null $b
*/
public function __construct(
public readonly int $a,
public readonly ?int $b,
) {}
}
```
Finding the parameter name declared by a `@param`-like annotation now
ignores the `$variable` tokens nested inside brackets, so a conditional
type such as `($a is 1 ? int : string) $b` is bound to `$b` and not to
the `$a` appearing inside the type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHPStan and Psalm accept type syntaxes that this library cannot parse, for instance a conditional type like
($a is 1 ? int : null). Such a type ends up unresolvable, and the only way out was to remove or weaken the annotation, making the static analysis tools lose information the library was not able to use anyway.The annotations
@valinor-var,@valinor-paramand@valinor-returncan now declare a type that only this library reads. They take precedence over their@phpstan-*,@psalm-*and native counterparts, so both worlds can be served by the same docblock:Finding the parameter name declared by a
@param-like annotation now ignores the$variabletokens nested inside brackets, so a conditional type such as($a is 1 ? int : string) $bis bound to$band not to the$aappearing inside the type.Fixes #448