Skip to content

Commit e7b1980

Browse files
committed
Fix catch typed exception variable (#176)
1 parent 30afeb8 commit e7b1980

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/Languages/Php/Patterns/CatchTypePattern.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
use Tempest\Highlight\Tokens\TokenTypeEnum;
1111

1212
#[PatternTest(input: 'catch (Foo) {}', output: 'Foo')]
13+
#[PatternTest(input: 'catch(Foo) {}', output: 'Foo')]
14+
#[PatternTest(input: 'catch (Foo $foo) {}', output: 'Foo')]
1315
#[PatternTest(input: 'catch (Foo|Bar) {}', output: 'Foo|Bar')]
14-
#[PatternTest(input: 'catch (Foo|Bar $bar) {}', output: null)]
16+
#[PatternTest(input: 'catch (Foo|Bar $bar) {}', output: 'Foo|Bar')]
1517
final readonly class CatchTypePattern implements Pattern
1618
{
1719
use IsPattern;
1820

1921
public function getPattern(): string
2022
{
21-
return 'catch \((?<match>[\w\||]+)\)';
23+
return 'catch\s*\((?<match>[\w\||]+)(\)|\s)';
2224
}
2325

2426
public function getTokenType(): TokenTypeEnum

tests/targets/test.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
```ini
2-
[PHP]
3-
4-
;zend_extension = xdebug
5-
xdebug.mode = profile
6-
xdebug.output_dir = /Users/brentroose/Desktop
7-
xdebug.profiler_output_name = cachegrind.out.%p
8-
9-
;;;;;;;;;;;;;;;;;;;
10-
; About php.ini ;
11-
;;;;;;;;;;;;;;;;;;;
1+
```php
2+
try {
3+
} catch (HttpRequestFailed $failure) {
4+
}
125
```

0 commit comments

Comments
 (0)