Multiply   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 4 1
A run() 0 16 4
1
<?php
2
namespace Desmond\functions\core;
3
use Desmond\functions\DesmondFunction;
4
use Desmond\ArgumentHelper;
5
use Desmond\exceptions\ArgumentException;
6
use Desmond\data_types\NumberType;
7
8
class Multiply extends DesmondFunction
9
{
10
    use ArgumentHelper;
11
12 334
    public function id()
13
    {
14 334
        return '*';
15
    }
16
17 8
    public function run(array $args)
18
    {
19 8
        if (!isset($args[0])) {
20 1
            return $this->newReturnType('Number', 0);
21
        }
22 8
        $this->expectArguments('*', [0 => ['Number']], $args);
23 7
        $value = $args[0]->value();
24 7
        array_shift($args);
25 7
        foreach ($args as $number) {
26 6
            if (!$this->isDesmondType('Number', $number)) {
27 1
                throw new ArgumentException('"*" expects all arguments to be Numbers.');
28
            }
29 5
            $value *= $number->value();
30
        }
31 6
        return $this->newReturnType('Number', $value);
32
    }
33
}
34