Commit Graph

60 Commits

Author SHA1 Message Date
Romain Canon
9f99a2a1ef feat: handle integer range type
Integer range can be used as follows:

```php
final class SomeClass
{
    /** @var int<42, 1337> */
    public int $intRange; // accepts any int between 42 and 1337

    /** @var int<-1337, 1337> */
    public int $negativeIntRange; // also works with negative values

    /** @var int<min, 1337> */
    public int $minIntRange; // `min` can be used…

    /** @var int<0, max> */
    public int $maxIntRange; // …as well as `max`
}
```

Note that `min` and `max` will check the range with PHP's internal
constants `PHP_INT_MIN` and `PHP_INT_MAX`.
2021-12-07 18:20:25 +01:00
Romain Canon
9ee2cc471e fix: handle integer value match properly 2021-12-07 18:20:25 +01:00
Romain Canon
fa3ce50dfb feat: handle type alias import in class definition
Type aliases can now be imported from another class definition.

Both PHPStan and Psalm syntax are handled.

```php
/**
 * @phpstan-type SomeTypeAlias = array{foo: string}
 */
final class SomeClass
{
    /** @var SomeTypeAlias */
    public array $someTypeAlias;
}

/**
 * @phpstan-import-type SomeTypeAlias from SomeClass
 */
final class SomeOtherClass
{
    /** @var SomeTypeAlias */
    public array $someTypeAlias;
}
```
2021-12-07 18:20:04 +01:00
Romain Canon
56142dea5b feat: handle local type aliasing in class definition
Type aliases can now be added to a class definition.

Both PHPStan and Psalm syntax are handled.

```php
/**
 * @phpstan-type SomeTypeAlias = array{foo: string}
 * @psalm-type SomeOtherTypeAlias = array{bar: int}
 */
final class SomeClass
{
    /** @var SomeTypeAlias */
    public array $someTypeAlias;

    /** @var SomeOtherTypeAlias */
    public array $someOtherTypeAlias;
}
```
2021-12-07 18:20:04 +01:00
Romain Canon
99b4f4f7aa refactor: extract reflection type resolving to class 2021-12-07 18:20:04 +01:00
Romain Canon
680941687b misc: rename GenericAssignerLexer to TypeAliasLexer 2021-12-07 18:20:04 +01:00
Romain Canon
5a578ea4c2 fix: do not accept shaped array with excessive key(s)
The mapper will now delete the excessive keys given as input to a shaped
 array.
2021-12-02 22:35:34 +01:00
Romain Canon
d99c59dfb5 feat: handle multiline type declaration
The following type will now be handled:

```php
/**
 * @var array{
 *     foo: string,
 *     bar: int
 * }
 */
public array $foo;
```
2021-12-01 09:45:33 +01:00
Romain Canon
dd4624c5e0 fix: handle correctly iterable source during mapping 2021-11-30 13:04:09 +01:00
Romain Canon
396f64a524 feat: initial release
🎉
2021-11-28 18:21:56 +01:00