77final class RegexCapturingGroup
88{
99
10- private bool $ forceNonOptional = false ;
11-
12- private ?Type $ forceType = null ;
13-
1410 public function __construct (
1511 private readonly int $ id ,
1612 private readonly ?string $ name ,
1713 private readonly ?RegexAlternation $ alternation ,
1814 private readonly bool $ inOptionalQuantification ,
19- private RegexCapturingGroup |RegexNonCapturingGroup |null $ parent ,
15+ private readonly RegexCapturingGroup |RegexNonCapturingGroup |null $ parent ,
2016 private readonly Type $ type ,
17+ private readonly bool $ forceNonOptional = false ,
18+ private readonly ?Type $ forceType = null ,
2119 )
2220 {
2321 }
@@ -29,23 +27,44 @@ public function getId(): int
2927
3028 public function forceNonOptional (): self
3129 {
32- $ new = clone $ this ;
33- $ new ->forceNonOptional = true ;
34- return $ new ;
30+ return new self (
31+ $ this ->id ,
32+ $ this ->name ,
33+ $ this ->alternation ,
34+ $ this ->inOptionalQuantification ,
35+ $ this ->parent ,
36+ $ this ->type ,
37+ true ,
38+ $ this ->forceType ,
39+ );
3540 }
3641
3742 public function forceType (Type $ type ): self
3843 {
39- $ new = clone $ this ;
40- $ new ->forceType = $ type ;
41- return $ new ;
44+ return new self (
45+ $ this ->id ,
46+ $ this ->name ,
47+ $ this ->alternation ,
48+ $ this ->inOptionalQuantification ,
49+ $ this ->parent ,
50+ $ type ,
51+ $ this ->forceNonOptional ,
52+ $ this ->forceType ,
53+ );
4254 }
4355
4456 public function withParent (RegexCapturingGroup |RegexNonCapturingGroup $ parent ): self
4557 {
46- $ new = clone $ this ;
47- $ new ->parent = $ parent ;
48- return $ new ;
58+ return new self (
59+ $ this ->id ,
60+ $ this ->name ,
61+ $ this ->alternation ,
62+ $ this ->inOptionalQuantification ,
63+ $ parent ,
64+ $ this ->type ,
65+ $ this ->forceNonOptional ,
66+ $ this ->forceType ,
67+ );
4968 }
5069
5170 public function resetsGroupCounter (): bool
0 commit comments