Skip to content

Commit 2f19fab

Browse files
committed
Asymmetric visibility updates
1 parent 099967d commit 2f19fab

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

src/Languages/Php/Patterns/ClassPropertyPattern.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
#[PatternTest(input: 'public Foo|Bar $foo', output: '$foo')]
1616
#[PatternTest(input: 'public Foo&Bar $foo', output: '$foo')]
1717
#[PatternTest(input: 'public (Foo&Bar)|null $foo', output: '$foo')]
18+
#[PatternTest(input: 'private(set) Foo $foo;', output: '$foo')]
19+
#[PatternTest(input: 'public(set) Foo $foo;', output: '$foo')]
20+
#[PatternTest(input: 'protected(set) Foo $foo;', output: '$foo')]
1821
final readonly class ClassPropertyPattern implements Pattern
1922
{
2023
use IsPattern;
2124

2225
public function getPattern(): string
2326
{
24-
return '(public|private|protected)(\s(.+?)) (?<match>\\$[\w]+)';
27+
return '(public|private|protected)(\(set\))?(\s(.+?)) (?<match>\\$[\w]+)';
2528
}
2629

2730
public function getTokenType(): TokenTypeEnum

src/Languages/Php/Patterns/PhpAsymmetricPropertyPattern.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,28 @@
1111
use Tempest\Highlight\Tokens\TokenTypeEnum;
1212

1313
#[PatternTest(input: 'public public(set) Foo $foo', output: 'set')]
14-
#[PatternTest(input: 'public public(get) Foo $foo', output: 'get')]
15-
#[PatternTest(input: 'public private(get) Foo $foo', output: 'get')]
16-
#[PatternTest(input: 'public protected(get) Foo $foo', output: 'get')]
14+
#[PatternTest(input: 'public private(set) Foo $foo', output: 'set')]
15+
#[PatternTest(input: 'public protected(set) Foo $foo', output: 'set')]
1716
final readonly class PhpAsymmetricPropertyPattern implements Pattern
1817
{
1918
use IsPattern;
2019

20+
public function match(string $content): array
21+
{
22+
$pattern = $this->getPattern();
23+
24+
if (! str_starts_with($pattern, '/')) {
25+
$pattern = "/$pattern/";
26+
}
27+
28+
preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE);
29+
30+
return $matches;
31+
}
32+
2133
public function getPattern(): string
2234
{
23-
return '/(public|private|protected)\((?<match>set|get)\)/';
35+
return '/(public|private|protected)\((?<match>set)\)/';
2436
}
2537

2638
public function getTokenType(): TokenType

src/Languages/Php/PhpTypeLanguage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Tempest\Highlight\Languages\Php\Patterns\KeywordPattern;
1313
use Tempest\Highlight\Languages\Php\Patterns\MultilineSingleDocCommentPattern;
1414
use Tempest\Highlight\Languages\Php\Patterns\NewObjectPattern;
15+
use Tempest\Highlight\Languages\Php\Patterns\PhpAsymmetricPropertyPattern;
1516
use Tempest\Highlight\Languages\Php\Patterns\SinglelineCommentPattern;
1617
use Tempest\Highlight\Languages\Php\Patterns\TypeForVariablePattern;
1718

@@ -53,6 +54,7 @@ public function getPatterns(): array
5354
new TypeForVariablePattern(),
5455
new ClassPropertyPattern(),
5556
new NewObjectPattern(),
57+
new PhpAsymmetricPropertyPattern(),
5658
];
5759
}
5860
}

tests/targets/test.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
```php
2-
// controller for home
3-
final readonly class HomeController
4-
{
5-
#[Get(uri: '/home')]
6-
public function __invoke(): View
7-
{
8-
return view('Views/home.view.php')
9-
->data(
10-
name: 'Brent',
11-
date: new DateTime(),
12-
);
13-
}
14-
15-
#[Post(uri: '/home')]
16-
public function __invoke(): View
17-
{
18-
}
19-
}
2+
public function __construct(
3+
private(set) Author $author,
4+
) {}
205
```

0 commit comments

Comments
 (0)