7
7
final class RegexCapturingGroup
8
8
{
9
9
10
- private bool $ forceNonOptional = false ;
11
-
12
- private ?Type $ forceType = null ;
13
-
14
10
public function __construct (
15
11
private readonly int $ id ,
16
12
private readonly ?string $ name ,
17
13
private readonly ?RegexAlternation $ alternation ,
18
14
private readonly bool $ inOptionalQuantification ,
19
- private RegexCapturingGroup |RegexNonCapturingGroup |null $ parent ,
15
+ private readonly RegexCapturingGroup |RegexNonCapturingGroup |null $ parent ,
20
16
private readonly Type $ type ,
17
+ private readonly bool $ forceNonOptional = false ,
18
+ private readonly ?Type $ forceType = null ,
21
19
)
22
20
{
23
21
}
@@ -29,23 +27,44 @@ public function getId(): int
29
27
30
28
public function forceNonOptional (): self
31
29
{
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
+ );
35
40
}
36
41
37
42
public function forceType (Type $ type ): self
38
43
{
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
+ );
42
54
}
43
55
44
56
public function withParent (RegexCapturingGroup |RegexNonCapturingGroup $ parent ): self
45
57
{
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
+ );
49
68
}
50
69
51
70
public function resetsGroupCounter (): bool
0 commit comments