• 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

90.91
/Classes/ViewHelpers/Format/SubstringViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Format;
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 TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
13

14
/**
15
 * Gets a substring from a string or string-compatible value.
16
 *
17
 * Also see the `<f:format.crop>` view helper.
18
 */
19
class SubstringViewHelper extends AbstractViewHelper
20
{
21
    public function initializeArguments(): void
22
    {
23
        $this->registerArgument('content', 'string', 'Content string to substring');
3✔
24
        $this->registerArgument('start', 'integer', 'Positive or negative offset', false, 0);
3✔
25
        $this->registerArgument('length', 'integer', 'Positive or negative length');
3✔
26
    }
27

28
    /**
29
     * Substrings a string or string-compatible value
30
     *
31
     * @return mixed
32
     */
33
    public static function renderStatic(
34
        array $arguments,
35
        \Closure $renderChildrenClosure,
36
        RenderingContextInterface $renderingContext
37
    ) {
38
        /** @var string $content */
39
        $content = $arguments['content'] ?? $renderChildrenClosure();
6✔
40
        /** @var int $start */
41
        $start = $arguments['start'];
6✔
42
        /** @var int $length */
43
        $length = $arguments['length'];
6✔
44
        if (null !== $length) {
6✔
45
            if ($length < 0) {
3✔
46
                // mb_substr does not support negative length, therefore we must calculate the length based on
47
                // original string length and offset, so we can pass a positive integer to mb_substr.
48
                $length = $length + mb_strlen($content) - $start;
×
49
            }
50
            return mb_substr($content, $start, $length);
3✔
51
        }
52
        return mb_substr($content, $start);
3✔
53
    }
54
}
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