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

Range::id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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