• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.9
/Classes/ViewHelpers/Iterator/LoopViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Iterator;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
12

13
/**
14
 * Repeats rendering of children $count times while updating $iteration.
15
 */
16
class LoopViewHelper extends AbstractLoopViewHelper
17
{
18
    public function initializeArguments(): void
19
    {
20
        parent::initializeArguments();
7✔
21

22
        $this->registerArgument('count', 'integer', 'Number of times to render child content', true);
7✔
23
        $this->registerArgument('minimum', 'integer', 'Minimum number of loops before stopping', false, 0);
7✔
24
        $this->registerArgument('maximum', 'integer', 'Maxiumum number of loops before stopping', false, PHP_INT_MAX);
7✔
25
    }
26

27
    /**
28
     * @return string
29
     */
30
    public static function renderStatic(
31
        array $arguments,
32
        \Closure $renderChildrenClosure,
33
        RenderingContextInterface $renderingContext
34
    ) {
35
        /** @var int $count */
36
        $count = $arguments['count'];
×
37
        /** @var int $minimum */
38
        $minimum = $arguments['minimum'];
×
39
        /** @var int $maximum */
40
        $maximum = $arguments['maximum'];
×
41
        /** @var string|null $iteration */
42
        $iteration = $arguments['iteration'];
×
43
        $content = '';
×
44
        $variableProvider = $renderingContext->getVariableProvider();
×
45

46
        if ($count < $minimum) {
×
47
            $count = $minimum;
×
48
        } elseif ($count > $maximum) {
×
49
            $count = $maximum;
×
50
        }
51

52
        if ($iteration !== null && $variableProvider->exists($iteration)) {
×
53
            $backupVariable = $variableProvider->get($iteration);
×
54
            $variableProvider->remove($iteration);
×
55
        }
56

57
        for ($i = 0; $i < $count; $i++) {
×
58
            $content .= static::renderIteration(
×
59
                $i,
×
60
                0,
×
61
                $count,
×
62
                1,
×
63
                $iteration,
×
64
                $renderingContext,
×
65
                $renderChildrenClosure
×
66
            );
×
67
        }
68

69
        if ($iteration !== null && isset($backupVariable)) {
×
70
            $variableProvider->add($iteration, $backupVariable);
×
71
        }
72

73
        return $content;
×
74
    }
75

76
    protected static function isLast(int $i, int $from, int $to, int $step): bool
77
    {
78
        return ($i + $step >= $to);
×
79
    }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc