Skip to content

Commit e82bdfb

Browse files
committed
coding style tweaks
1 parent b7b7bd4 commit e82bdfb

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/Compiler.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,11 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
395395
if ($i < $from) {
396396
continue;
397397
}
398-
if ($this->matchExtendsSingle($part, $origin)) {
399398

399+
if ($this->matchExtendsSingle($part, $origin)) {
400400
$after = array_slice($selector, $i + 1);
401401
$before = array_slice($selector, 0, $i);
402+
402403
list($before, $nonBreakableBefore) = $this->extractRelationshipFromFragment($before);
403404

404405
foreach ($origin as $new) {
@@ -413,13 +414,16 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
413414

414415
$replacement = [];
415416
$tempReplacement = $k > 0 ? array_slice($new, $k) : $new;
416-
for ($l = count($tempReplacement) - 1; $l >= 0 ; $l--) {
417+
418+
for ($l = count($tempReplacement) - 1; $l >= 0; $l--) {
417419
$slice = $tempReplacement[$l];
418420
array_unshift($replacement, $slice);
419-
if (!$this->isImmediateRelationshipCombinator(end($slice))) {
421+
422+
if (! $this->isImmediateRelationshipCombinator(end($slice))) {
420423
break;
421424
}
422425
}
426+
423427
$afterBefore = $l != 0 ? array_slice($tempReplacement, 0, $l) : [];
424428

425429
// Merge shared direct relationships.
@@ -443,9 +447,9 @@ protected function matchExtends($selector, &$out, $from = 0, $initial = true)
443447

444448
// selector sequence merging
445449
if (! empty($before) && count($new) > 1) {
446-
447450
$sharedParts = $k > 0 ? array_slice($before, 0, $k) : [];
448451
$postSharedParts = $k > 0 ? array_slice($before, $k) : $before;
452+
449453
list($injectBetweenSharedParts, $nonBreakable2) = $this->extractRelationshipFromFragment($afterBefore);
450454

451455
$result2 = array_merge(
@@ -492,6 +496,7 @@ protected function matchExtendsSingle($rawSingle, &$outOrigin)
492496
}
493497

494498
$extendingDecoratedTag = false;
499+
495500
if (count($single) > 1) {
496501
$matches = null;
497502
$extendingDecoratedTag = preg_match('/^[a-z0-9]+$/i', $single[0], $matches) ? $matches[0] : false;
@@ -529,8 +534,9 @@ protected function matchExtendsSingle($rawSingle, &$outOrigin)
529534
$replacement = end($new);
530535

531536
// Extending a decorated tag with another tag is not possible.
532-
if ($extendingDecoratedTag && $replacement[0] != $extendingDecoratedTag
533-
&& preg_match('/^[a-z0-9]+$/i', $replacement[0])) {
537+
if ($extendingDecoratedTag && $replacement[0] != $extendingDecoratedTag &&
538+
preg_match('/^[a-z0-9]+$/i', $replacement[0])
539+
) {
534540
unset($origin[$j]);
535541
continue;
536542
}
@@ -568,15 +574,17 @@ protected function extractRelationshipFromFragment(array $fragment)
568574
$children = [];
569575
$j = $i = count($fragment);
570576

571-
do {
577+
for (;;) {
572578
$children = $j != $i ? array_slice($fragment, $j, $i - $j) : [];
573579
$parents = array_slice($fragment, 0, $j);
574580
$slice = end($parents);
575-
$hasImmediateRelationshipCombinator = !empty($slice) && $this->isImmediateRelationshipCombinator($slice[0]);
576-
if ($hasImmediateRelationshipCombinator) {
577-
$j -= 2;
581+
582+
if (empty($slice) || ! $this->isImmediateRelationshipCombinator($slice[0])) {
583+
break;
578584
}
579-
} while ($hasImmediateRelationshipCombinator);
585+
586+
$j -= 2;
587+
}
580588

581589
return [$parents, $children];
582590
}
@@ -1353,30 +1361,33 @@ protected function compileMediaQuery($queryList)
13531361
return $out;
13541362
}
13551363

1356-
protected function mergeDirectRelationships($selectors1, $selectors2) {
1364+
protected function mergeDirectRelationships($selectors1, $selectors2)
1365+
{
13571366
if (empty($selectors1) || empty($selectors2)) {
13581367
return array_merge($selectors1, $selectors2);
13591368
}
13601369

13611370
$part1 = end($selectors1);
13621371
$part2 = end($selectors2);
1363-
if (!$this->isImmediateRelationshipCombinator($part1[0]) || $part1 !== $part2) {
1372+
1373+
if (! $this->isImmediateRelationshipCombinator($part1[0]) || $part1 !== $part2) {
13641374
return array_merge($selectors1, $selectors2);
13651375
}
13661376

13671377
$merged = [];
1378+
13681379
do {
13691380
$part1 = array_pop($selectors1);
13701381
$part2 = array_pop($selectors2);
13711382

1372-
if ($this->isImmediateRelationshipCombinator($part1[0]) && $part1 === $part2) {
1373-
array_unshift($merged, $part1);
1374-
array_unshift($merged, [array_pop($selectors1)[0] . array_pop($selectors2)[0]]);
1375-
} else {
1383+
if ($this->isImmediateRelationshipCombinator($part1[0]) && $part1 !== $part2) {
13761384
$merged = array_merge($selectors1, [$part1], $selectors2, [$part2], $merged);
13771385
break;
13781386
}
1379-
} while (!empty($selectors1) && !empty($selectors2));
1387+
1388+
array_unshift($merged, $part1);
1389+
array_unshift($merged, [array_pop($selectors1)[0] . array_pop($selectors2)[0]]);
1390+
} while (! empty($selectors1) && ! empty($selectors2));
13801391

13811392
return $merged;
13821393
}
@@ -1720,7 +1731,7 @@ protected function compileChild($child, OutputBlock $out)
17201731
$end = $end[1];
17211732
$d = $start < $end ? 1 : -1;
17221733

1723-
while (true) {
1734+
for (;;) {
17241735
if ((! $for->until && $start - $d == $end) ||
17251736
($for->until && $start == $end)
17261737
) {
@@ -3063,13 +3074,14 @@ public function get($name, $shouldThrow = true, Environment $env = null)
30633074

30643075
$nextIsRoot = false;
30653076
$hasNamespace = $normalizedName[0] === '^' || $normalizedName[0] === '@' || $normalizedName[0] === '%';
3077+
30663078
for (;;) {
30673079
if (array_key_exists($normalizedName, $env->store)) {
30683080
return $env->store[$normalizedName];
30693081
}
30703082

30713083
if (! $hasNamespace && isset($env->marker)) {
3072-
if (! $nextIsRoot && !empty($env->store[$specialContentKey])) {
3084+
if (! $nextIsRoot && ! empty($env->store[$specialContentKey])) {
30733085
$env = $env->store[$specialContentKey]->scope;
30743086
$nextIsRoot = true;
30753087
continue;

0 commit comments

Comments
 (0)