Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Mar 23, 2024
1 parent 8cec641 commit d108d8a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Languages/Php/Patterns/ParameterTypePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
#[PatternTest(input: '?Bar $bar, Baz $baz', output: ['?Bar', 'Baz'])]
#[PatternTest(input: 'Foo|Bar|null $bar', output: 'Foo|Bar|null')]
#[PatternTest(input: '|null $bar', output: '|null')]
#[PatternTest(input: 'string|\Stringable $bar', output: 'string|\Stringable')]
final readonly class ParameterTypePattern implements Pattern
{
use IsPattern;

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

public function getTokenType(): TokenType
Expand Down
1 change: 0 additions & 1 deletion src/Languages/Php/PhpLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function getPatterns(): array
new KeywordPattern('__halt_compiler'),
new KeywordPattern('abstract'),
new KeywordPattern('and'),
new KeywordPattern('array'),
new KeywordPattern('as'),
new KeywordPattern('break'),
new KeywordPattern('callable'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Languages/Php/PhpLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function data(): array
['$foo || $bar', '<span class="hl-variable">$foo</span> <span class="hl-operator">||</span> <span class="hl-variable">$bar</span>'],
['$foo <=> $bar', '<span class="hl-variable">$foo</span> <span class="hl-operator">&lt;=&gt;</span> <span class="hl-variable">$bar</span>'],
["public const string|\Stringable MESSAGE = 'hi';", '<span class="hl-keyword">public</span> <span class="hl-keyword">const</span> <span class="hl-type">string|\Stringable</span> <span class="hl-property">MESSAGE</span> = \'<span class="hl-value">hi</span>\';'],
["public string|\Stringable \$message;", '<span class="hl-keyword">public</span> <span class="hl-type">string|\<span class="hl-type">Stringable</span></span> <span class="hl-property">$message</span>;'],
["public string|\Stringable \$message;", '<span class="hl-keyword">public</span> <span class="hl-type">string|\Stringable</span> <span class="hl-property">$message</span>;'],
['for($x = 0; $x < 150; $x++) {', '<span class="hl-keyword">for</span>(<span class="hl-variable">$x</span> = 0; <span class="hl-variable">$x</span> &lt; 150; <span class="hl-variable">$x</span>++) {'],
["'namespace ';", "'<span class=\"hl-value\">namespace </span>';"],
["static::foo()", '<span class="hl-keyword">static</span>::<span class="hl-property">foo</span>()'],
Expand Down
5 changes: 4 additions & 1 deletion tests/targets/test.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
```php
#[PatternTest(input: 'new Foo()', output: 'Foo')]
public function warning(
string|\Stringable $message,
array $context = []
): void;
```

0 comments on commit d108d8a

Please sign in to comment.