Skip to content

Commit

Permalink
Fix for variadic types
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Aug 27, 2024
1 parent 1b4fc5c commit 0679847
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix for static property types (#129)
- Fix for attribute in promoted property (#133)
- Fix for comments in function argument lists (#134)
- Fix for variadic types (#140)

## 2.8.2

Expand Down
3 changes: 2 additions & 1 deletion src/Languages/Php/Patterns/TypeForVariablePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
#[PatternTest(input: 'Foo|Bar|null $bar', output: 'Foo|Bar|null')]
#[PatternTest(input: '(Foo&Bar)|null $bar', output: '(Foo&Bar)|null')]
#[PatternTest(input: 'string|\Stringable $bar', output: 'string|\Stringable')]
#[PatternTest(input: 'Foo ...$params', output: 'Foo')]
final readonly class TypeForVariablePattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '(?<match>[\w\&\(\)\|\\\\\?]+)\s+\\$';
return '(?<match>[\w\&\(\)\|\\\\\?]+)\s+(\.*)\\$';
}

public function getTokenType(): TokenTypeEnum
Expand Down
11 changes: 1 addition & 10 deletions tests/targets/test.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
```php
public function __construct(
// Allow a union on a special "missing relation" type:
public Relation|Author $author,

// Making the relation nullable would be an option as well:
/** @var Chapter[] $chapters */
/**
* hello */
public ?array $chapters,
) {}
public function update(Foo ...$params): self;
```

0 comments on commit 0679847

Please sign in to comment.