• 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

76.0
/Classes/ViewHelpers/Math/AbstractMultipleMathViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Math;
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\ArrayConsumingViewHelperTrait;
13
use FluidTYPO3\Vhs\Utility\ErrorUtility;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
16

17
/**
18
 * Base class: Math ViewHelpers operating on one number or an
19
 * array of numbers.
20
 */
21
abstract class AbstractMultipleMathViewHelper extends AbstractViewHelper
22
{
23
    use ArrayConsumingViewHelperTrait;
24

25
    public function initializeArguments(): void
26
    {
27
        parent::initializeArguments();
27✔
28
        $this->registerArgument('a', 'mixed', 'First number for calculation');
27✔
29
        $this->registerArgument('b', 'mixed', 'Second number or Iterator/Traversable/Array for calculation', true);
27✔
30
        $this->registerArgument(
27✔
31
            'fail',
27✔
32
            'boolean',
27✔
33
            'If TRUE, throws an Exception if argument "a" is not specified and no child content or inline argument ' .
27✔
34
            'is found. Usually okay to use a NULL value (as integer zero).',
27✔
35
            false,
27✔
36
            false
27✔
37
        );
27✔
38
    }
39

40
    /**
41
     * @return mixed
42
     */
43
    public static function renderStatic(
44
        array $arguments,
45
        \Closure $renderChildrenClosure,
46
        RenderingContextInterface $renderingContext
47
    ) {
48
        /** @var numeric|numeric-string|array|iterable|null $value */
49
        $value = $arguments['a'] ?? $renderChildrenClosure();
30✔
50
        if (null === $value && $arguments['fail']) {
30✔
51
            ErrorUtility::throwViewHelperException('Required argument "a" was not supplied', 1237823699);
×
52
        }
53
        /** @var numeric|numeric-string|array|iterable|null $b */
54
        $b = $arguments['b'];
30✔
55
        return static::calculate($value, $b, $arguments);
30✔
56
    }
57

58
    /**
59
     * @param numeric|numeric-string|array|iterable|null $a
60
     * @param numeric|numeric-string|array|iterable|null $b
61
     * @param array $arguments
62
     * @return numeric|array
63
     * @throws Exception
64
     */
65
    protected static function calculate($a, $b = null, array $arguments = [])
66
    {
67
        $aIsIterable = static::assertIsArrayOrIterator($a);
30✔
68
        $bIsIterable = static::assertIsArrayOrIterator($b);
30✔
69
        if (!$aIsIterable && $bIsIterable) {
30✔
70
            ErrorUtility::throwViewHelperException(
×
71
                'Math operation attempted using an iterator $b against a numeric value $a. Either both $a and $b, ' .
×
72
                'or only $a, must be array/Iterator',
×
73
                1351890876
×
74
            );
×
75
        }
76
        return static::calculateAction($a, $b, $arguments);
30✔
77
    }
78

79
    /**
80
     * @param numeric|numeric-string|array|iterable|null $a
81
     * @param numeric|numeric-string|array|iterable|null $b
82
     * @param array $arguments
83
     * @return numeric|array
84
     */
85
    abstract protected static function calculateAction($a, $b, array $arguments);
86
}
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