Skip to content

Commit ea94900

Browse files
committed
Update RegexGroupParser.php
1 parent 77c8c95 commit ea94900

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Type/Php/RegexGroupParser.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,14 @@ private function walkGroupAst(
388388
continue;
389389
}
390390

391+
// a single token non-falsy on its own
391392
$isNonFalsy = TrinaryLogic::createYes();
392393
}
393394

394395
if ($meaningfulTokens > 0) {
395396
$isNonEmpty = TrinaryLogic::createYes();
396397

398+
// two non-empty tokens concatenated results in a non-falsy string
397399
if ($meaningfulTokens > 1 && !$inAlternation) {
398400
$isNonFalsy = TrinaryLogic::createYes();
399401
}
@@ -477,11 +479,11 @@ private function isEmptyNode(TreeNode $node, string $patternModifiers, bool &$is
477479
[$min] = $this->getQuantificationRange($node);
478480

479481
if ($min > 0) {
480-
return true;
482+
return false;
481483
}
482484

483485
if ($min === 0) {
484-
return false;
486+
return true;
485487
}
486488
}
487489

@@ -490,16 +492,16 @@ private function isEmptyNode(TreeNode $node, string $patternModifiers, bool &$is
490492
if ($literal !== '' && $literal !== '0') {
491493
$isNonFalsy = true;
492494
}
493-
return true;
495+
return false;
494496
}
495497

496498
foreach ($node->getChildren() as $child) {
497-
if ($this->isEmptyNode($child, $patternModifiers, $isNonFalsy)) {
498-
return true;
499+
if (!$this->isEmptyNode($child, $patternModifiers, $isNonFalsy)) {
500+
return false;
499501
}
500502
}
501503

502-
return false;
504+
return true;
503505
}
504506

505507
/**

0 commit comments

Comments
 (0)