• 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

87.5
/Classes/ViewHelpers/Random/NumberViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Random;
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
 * ### Random: Number Generator
16
 *
17
 * Generates a random number. The default minimum number is
18
 * set to 100000 in order to generate a longer integer string
19
 * representation. Decimal values can be generated as well.
20
 */
21
class NumberViewHelper extends AbstractViewHelper
22
{
23
    /**
24
     * @var boolean
25
     */
26
    protected $escapeOutput = false;
27

28
    public function initializeArguments(): void
29
    {
30
        $this->registerArgument(
3✔
31
            'minimum',
3✔
32
            'integer',
3✔
33
            'Minimum number - defaults to 100000 (default max is 999999 for equal string lengths)',
3✔
34
            false,
3✔
35
            100000
3✔
36
        );
3✔
37
        $this->registerArgument(
3✔
38
            'maximum',
3✔
39
            'integer',
3✔
40
            'Maximum number - defaults to 999999 (default min is 100000 for equal string lengths)',
3✔
41
            false,
3✔
42
            999999
3✔
43
        );
3✔
44
        $this->registerArgument(
3✔
45
            'minimumDecimals',
3✔
46
            'integer',
3✔
47
            'Minimum number of also randomized decimal digits to add to number',
3✔
48
            false,
3✔
49
            0
3✔
50
        );
3✔
51
        $this->registerArgument(
3✔
52
            'maximumDecimals',
3✔
53
            'integer',
3✔
54
            'Maximum number of also randomized decimal digits to add to number',
3✔
55
            false,
3✔
56
            0
3✔
57
        );
3✔
58
    }
59

60
    /**
61
     * @return integer|float
62
     */
63
    public static function renderStatic(
64
        array $arguments,
65
        \Closure $renderChildrenClosure,
66
        RenderingContextInterface $renderingContext
67
    ) {
68
        /** @var int $minimum */
69
        $minimum = $arguments['minimum'];
3✔
70
        /** @var int $maximum */
71
        $maximum = $arguments['maximum'];
3✔
72
        /** @var int $minimumDecimals */
73
        $minimumDecimals = $arguments['minimumDecimals'];
3✔
74
        /** @var int $maximumDecimals */
75
        $maximumDecimals = $arguments['maximumDecimals'];
3✔
76
        $natural = random_int($minimum, $maximum);
3✔
77
        if (0 === (int) $minimumDecimals && 0 === (int) $maximumDecimals) {
3✔
78
            return $natural;
3✔
79
        }
80
        /** @var array $decimals */
81
        $decimals = array_fill(0, random_int($minimumDecimals, $maximumDecimals), 0);
×
82
        $decimals = array_map(function () {
×
83
            return random_int(0, 9);
×
84
        }, $decimals);
×
85
        return (float) ($natural . '.' . implode('', $decimals));
×
86
    }
87
}
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