Completed
Push — master ( e7b529...3b65c3 )
by Scott
02:52
created

Range   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 30
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 4 1
A run() 0 13 3
A getInts() 0 6 1
1
<?php
2
namespace Desmond\functions\core;
3
use Desmond\functions\DesmondFunction;
4
use Desmond\ArgumentHelper;
5
use Desmond\data_types\NumberType;
6
use Desmond\exceptions\ArgumentException;
7
8
class Range extends DesmondFunction
9
{
10
    use ArgumentHelper;
11
12 260
    public function id()
13
    {
14 260
        return 'range';
15
    }
16
17 5
    public function run(array $args)
18
    {
19 5
        $this->expectArguments('range', [['Number']], $args);
20 4
        if (!isset($args[1])) {
21 2
            $numbers = $this->getInts(range(0, $args[0]->value()));
22 2
            return $this->newReturnType('Vector', $numbers);
23
        }
24 2
        if (!$this->isDesmondType('Number', $args[1])) {
25 1
            throw new ArgumentException('"range" expects argument 2 to be a Number.');
26
        }
27 1
        $numbers = $this->getInts(range($args[0]->value(), $args[1]->value()));
28 1
        return $this->newReturnType('Vector', $numbers);
29
    }
30
31
    private function getInts($numbers)
32
    {
33 3
        return array_map(function($num) {
34 3
            return new NumberType($num);
35 3
        }, $numbers);
36
    }
37
}
38