• 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

46.15
/Classes/ViewHelpers/Math/SumViewHelper.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\Traits\ArgumentOverride;
12
use FluidTYPO3\Vhs\Traits\ArrayConsumingViewHelperTrait;
13
use FluidTYPO3\Vhs\Utility\ErrorUtility;
14

15
/**
16
 * Math: Sum
17
 *
18
 * Performs sum of $a and $b. A can be an array and $b a
19
 * number, in which case each member of $a gets summed with $b.
20
 * If $a is an array and $b is not provided then array_sum is
21
 * used to return a single numeric value. If both $a and $b are
22
 * arrays, each member of $a is summed against the corresponding
23
 * member in $b compared using index.
24
 */
25
class SumViewHelper extends AbstractMultipleMathViewHelper
26
{
27
    use ArrayConsumingViewHelperTrait;
28
    use ArgumentOverride;
29

30
    public function initializeArguments(): void
31
    {
32
        parent::initializeArguments();
3✔
33
        $this->overrideArgument('b', 'mixed', 'Optional: Second number or Iterator/Traversable/Array for calculation');
3✔
34
    }
35

36
    /**
37
     * @param mixed $a
38
     * @param mixed $b
39
     * @return mixed
40
     */
41
    protected static function calculateAction($a, $b, array $arguments)
42
    {
43
        $aIsIterable = static::assertIsArrayOrIterator($a);
3✔
44
        if (!$aIsIterable && $b === null && $arguments['fail']) {
3✔
45
            ErrorUtility::throwViewHelperException('Required argument "b" was not supplied', 1237823699);
×
46
        }
47
        if ($aIsIterable) {
3✔
48
            if (null === $b) {
×
49
                $a = static::arrayFromArrayOrTraversableOrCSVStatic($a);
×
50
                return array_sum($a);
×
51
            }
52
            /**
53
             * @var string|integer $index
54
             * @var mixed $value
55
             * @var array $a
56
             */
57
            foreach ($a as $index => $value) {
×
58
                $a[$index] = static::calculateAction($value, $b, $arguments);
×
59
            }
60
            return $a;
×
61
        }
62
        return $a + $b;
3✔
63
    }
64
}
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