• 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

33.33
/Classes/ViewHelpers/Math/DivisionViewHelper.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\Utility\ErrorUtility;
12

13
/**
14
 * Math: Division
15
 *
16
 * Performs division of $a using $b. A can be an array and $b a
17
 * number, in which case each member of $a gets divided by $b.
18
 * If both $a and $b are arrays, each member of $a is summed
19
 * against the corresponding member in $b compared using index.
20
 */
21
class DivisionViewHelper extends AbstractMultipleMathViewHelper
22
{
23
    /**
24
     * @param mixed $a
25
     * @param mixed $b
26
     * @param array $arguments
27
     * @return mixed
28
     */
29
    protected static function calculateAction($a, $b, array $arguments)
30
    {
31
        $aIsIterable = static::assertIsArrayOrIterator($a);
3✔
32
        $bIsIterable = static::assertIsArrayOrIterator($b);
3✔
33
        if (!$aIsIterable && $b === null && $arguments['fail']) {
3✔
34
            ErrorUtility::throwViewHelperException('Required argument "b" was not supplied', 1237823699);
×
35
        }
36
        if ($aIsIterable && null === $b) {
3✔
37
            $a = static::arrayFromArrayOrTraversableOrCSVStatic($a);
×
38
            $sum = array_sum($a);
×
39
            $distribution = count($a);
×
40
            return $sum / $distribution;
×
41
        } elseif ($aIsIterable && $b !== null) {
3✔
42
            $a = static::arrayFromArrayOrTraversableOrCSVStatic($a);
×
43
            if ($bIsIterable) {
×
44
                $b = static::arrayFromArrayOrTraversableOrCSVStatic($b);
×
45
            }
46
            foreach ($a as $index => $value) {
×
47
                $bSide = is_array($b) ? $b[$index] : $b;
×
48
                $a[$index] = static::calculateAction($value, $bSide, $arguments);
×
49
            }
50
            return $a;
×
51
        }
52
        return (0 <> $b ? $a / $b : $a);
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