@@ -37,22 +37,22 @@ public function countTrailingOptionals(): int
3737 return $ trailingOptionals ;
3838 }
3939
40- public function forceGroupIdNonOptional ( int $ id ): self
40+ public function forceGroupNonOptional ( RegexCapturingGroup $ group ): self
4141 {
42- return $ this ->cloneAndReParentList ($ id );
42+ return $ this ->cloneAndReParentList ($ group );
4343 }
4444
45- public function forceGroupIdTypeAndNonOptional ( int $ id , Type $ type ): self
45+ public function forceGroupTypeAndNonOptional ( RegexCapturingGroup $ group , Type $ type ): self
4646 {
47- return $ this ->cloneAndReParentList ($ id , $ type );
47+ return $ this ->cloneAndReParentList ($ group , $ type );
4848 }
4949
50- private function cloneAndReParentList (int $ id , ?Type $ type = null ): self
50+ private function cloneAndReParentList (RegexCapturingGroup $ target , ?Type $ type = null ): self
5151 {
5252 $ groups = [];
5353 $ forcedGroup = null ;
5454 foreach ($ this ->groups as $ i => $ group ) {
55- if ($ group ->getId () === $ id ) {
55+ if ($ group ->getId () === $ target -> getId () ) {
5656 $ forcedGroup = $ group ->forceNonOptional ();
5757 if ($ type !== null ) {
5858 $ forcedGroup = $ forcedGroup ->forceType ($ type );
@@ -78,7 +78,7 @@ private function cloneAndReParentList(int $id, ?Type $type = null): self
7878 continue ;
7979 }
8080
81- if ($ parent ->getId () === $ id ) {
81+ if ($ parent ->getId () === $ target -> getId () ) {
8282 $ groups [$ i ] = $ groups [$ i ]->withParent ($ forcedGroup );
8383 }
8484 $ parent = $ parent ->getParent ();
@@ -88,11 +88,11 @@ private function cloneAndReParentList(int $id, ?Type $type = null): self
8888 return new self ($ groups );
8989 }
9090
91- public function removeGroup (int $ id ): self
91+ public function removeGroup (RegexCapturingGroup $ remove ): self
9292 {
9393 $ groups = [];
9494 foreach ($ this ->groups as $ i => $ group ) {
95- if ($ group ->getId () === $ id ) {
95+ if ($ group ->getId () === $ remove -> getId () ) {
9696 continue ;
9797 }
9898
@@ -102,9 +102,9 @@ public function removeGroup(int $id): self
102102 return new self ($ groups );
103103 }
104104
105- public function getOnlyOptionalTopLevelGroupId (): ?int
105+ public function getOnlyOptionalTopLevelGroup (): ?RegexCapturingGroup
106106 {
107- $ groupIndex = null ;
107+ $ group = null ;
108108 foreach ($ this ->groups as $ captureGroup ) {
109109 if (!$ captureGroup ->isTopLevel ()) {
110110 continue ;
@@ -114,14 +114,14 @@ public function getOnlyOptionalTopLevelGroupId(): ?int
114114 return null ;
115115 }
116116
117- if ($ groupIndex !== null ) {
117+ if ($ group !== null ) {
118118 return null ;
119119 }
120120
121- $ groupIndex = $ captureGroup-> getId () ;
121+ $ group = $ captureGroup ;
122122 }
123123
124- return $ groupIndex ;
124+ return $ group ;
125125 }
126126
127127 public function getOnlyTopLevelAlternation (): ?RegexAlternation
0 commit comments