Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly handle nested local type aliases #521

Merged
merged 1 commit into from
Apr 7, 2024

Conversation

romm
Copy link
Member

@romm romm commented Apr 7, 2024

The following annotation now works properly:

/**
 * @phpstan-type Address = array{street?: string, city: string}
 * @phpstan-type User = array{name: non-empty-string, address: Address}
 */
final class SomeClass
{
    public function __construct(
        /** @var User */
        public $value,
    ) {}
}

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map(SomeClass::class, [
        'name' => 'John Doe',
        'address' => [
            'street' => 'Bron-Yr-Aur',
            'city' => 'SY20 8QA, Machynlleth',
        ],
    ]);

Fixes #308
Fixes #428

@romm romm changed the title fix: allow any constant in class constant type fix: properly handle nested local type aliases Apr 7, 2024
The following annotation now works properly:

```php
/**
 * @phpstan-type Address = array{street?: string, city: string}
 * @phpstan-type User = array{name: non-empty-string, address: Address}
 */
final class SomeClass
{
    public function __construct(
        /** @var User */
        public $value,
    ) {}
}

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map(SomeClass::class, [
        'name' => 'John Doe',
        'address' => [
            'street' => 'Bron-Yr-Aur',
            'city' => 'SY20 8QA, Machynlleth',
        ],
    ]);
 ```
@romm romm merged commit 1278392 into CuyZ:master Apr 7, 2024
11 checks passed
@romm romm deleted the fix/nested-type-alias branch April 7, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixing phpstan-type and psalm-type phpdocs breaks type resolution Nested type aliases are not supported
1 participant