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

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

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

69.23
/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\Traits\CompileWithContentArgumentAndRenderStatic;
14
use FluidTYPO3\Vhs\Utility\ErrorUtility;
15

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

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

38
    /**
39
     * @param mixed $a
40
     * @param mixed $b
41
     * @return mixed
42
     */
43
    protected static function calculateAction($a, $b, array $arguments)
44
    {
45
        $aIsIterable = static::assertIsArrayOrIterator($a);
14✔
46
        if (!$aIsIterable && $b === null && $arguments['fail']) {
14✔
47
            ErrorUtility::throwViewHelperException('Required argument "b" was not supplied', 1237823699);
×
48
        }
49
        if ($aIsIterable) {
14✔
50
            if (null === $b) {
7✔
51
                $a = static::arrayFromArrayOrTraversableOrCSVStatic($a);
7✔
52
                return array_sum($a);
7✔
53
            }
54
            /**
55
             * @var string|integer $index
56
             * @var mixed $value
57
             * @var array $a
58
             */
59
            foreach ($a as $index => $value) {
×
60
                $a[$index] = static::calculateAction($value, $b, $arguments);
×
61
            }
62
            return $a;
×
63
        }
64
        return $a + $b;
7✔
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc