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

FluidTYPO3 / vhs / 11984205186

11 Nov 2024 01:59PM UTC coverage: 72.746%. Remained the same
11984205186

push

github

NamelessCoder
[TASK] Set beta stability

5544 of 7621 relevant lines covered (72.75%)

13.49 hits per line

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

4.35
/Classes/ViewHelpers/Iterator/AbstractLoopViewHelper.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
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
13

14
/**
15
 * Abstract class with basic functionality for loop view helpers.
16
 */
17
abstract class AbstractLoopViewHelper extends AbstractViewHelper
18
{
19
    /**
20
     * @var boolean
21
     */
22
    protected $escapeChildren = false;
23

24
    /**
25
     * @var boolean
26
     */
27
    protected $escapeOutput = false;
28

29
    public function initializeArguments(): void
30
    {
31
        $this->registerArgument('iteration', 'string', 'Variable name to insert result into, suppresses output');
12✔
32
    }
33

34
    /**
35
     * @return string
36
     */
37
    protected static function renderIteration(
38
        int $i,
39
        int $from,
40
        int $to,
41
        int $step,
42
        ?string $iterationArgument,
43
        RenderingContextInterface $renderingContext,
44
        \Closure $renderChildrenClosure
45
    ) {
46
        if (!empty($iterationArgument)) {
×
47
            $variableProvider = $renderingContext->getVariableProvider();
×
48
            $cycle = (integer) (($i - $from) / $step) + 1;
×
49
            $iteration = [
×
50
                'index' => $i,
×
51
                'cycle' => $cycle,
×
52
                'isOdd' => 0 === $cycle % 2,
×
53
                'isEven' => 0 === $cycle % 2,
×
54
                'isFirst' => $i === $from,
×
55
                'isLast' => static::isLast($i, $from, $to, $step)
×
56
            ];
×
57
            $variableProvider->add($iterationArgument, $iteration);
×
58
            $content = $renderChildrenClosure();
×
59
            $variableProvider->remove($iterationArgument);
×
60
        } else {
61
            $content = $renderChildrenClosure();
×
62
        }
63

64
        return $content;
×
65
    }
66

67
    protected static function isLast(int $i, int $from, int $to, int $step): bool
68
    {
69
        if ($from === $to) {
×
70
            $isLast = true;
×
71
        } elseif ($from < $to) {
×
72
            $isLast = ($i + $step > $to);
×
73
        } else {
74
            $isLast = ($i + $step < $to);
×
75
        }
76

77
        return $isLast;
×
78
    }
79
}
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