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

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

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

93.75
/Classes/ViewHelpers/Iterator/SplitViewHelper.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 FluidTYPO3\Vhs\Core\ViewHelper\AbstractViewHelper;
12
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
13
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
14

15
/**
16
 * Converts a string to an array with $length number of bytes
17
 * per new array element. Wrapper for PHP's `str_split`.
18
 */
19
class SplitViewHelper extends AbstractViewHelper
20
{
21
    use TemplateVariableViewHelperTrait;
22

23
    /**
24
     * @var boolean
25
     */
26
    protected $escapeChildren = false;
27

28
    /**
29
     * @var boolean
30
     */
31
    protected $escapeOutput = false;
32

33
    public function initializeArguments(): void
34
    {
35
        $this->registerArgument('subject', 'string', 'The string that will be split into an array');
3✔
36
        $this->registerArgument('length', 'integer', 'Number of bytes per chunk in the new array', false, 1);
3✔
37
        $this->registerAsArgument();
3✔
38
    }
39

40
    /**
41
     * @return mixed
42
     */
43
    public static function renderStatic(
44
        array $arguments,
45
        \Closure $renderChildrenClosure,
46
        RenderingContextInterface $renderingContext
47
    ) {
48
        /** @var int<1, max> $length */
49
        $length = $arguments['length'];
3✔
50
        if ((int) $length === 0) {
3✔
51
            // Difference from PHP str_split: return an empty array if (potentially dynamically defined) length
52
            // argument is zero for some reason. PHP would throw a warning; Fluid would logically just return empty.
53
            return [];
×
54
        }
55
        /** @var string|null $as */
56
        $as = $arguments['as'];
3✔
57
        return static::renderChildrenWithVariableOrReturnInputStatic(
3✔
58
            str_split(
3✔
59
                empty($as) ? ($arguments['subject'] ?? $renderChildrenClosure()) : $arguments['subject'],
3✔
60
                $length
3✔
61
            ),
3✔
62
            $as,
3✔
63
            $renderingContext,
3✔
64
            $renderChildrenClosure
3✔
65
        );
3✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc