Map   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 35
ccs 20
cts 20
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 2
A requireArgTypes() 0 11 3
1
<?php
2
namespace Desmond\functions\core;
3
use Desmond\functions\DesmondFunction;
4
use Desmond\ArgumentHelper;
5
use Desmond\exceptions\ArgumentException;
6
7
class Map extends DesmondFunction
8
{
9
    use ArgumentHelper;
10
11 334
    public function id()
12
    {
13 334
        return 'map';
14
    }
15
16 7
    public function run(array $args)
17
    {
18 7
        $args = $this->cloneArgs($args);
19 7
        $this->requireArgTypes($args);
20 5
        $collection = $args[0];
21 5
        $values = $collection->value();
22 5
        $function = $args[1];
23 5
        foreach ($values as $key => $value) {
24 5
            $collection->set(
25 5
                $function->run([$value]), $key);
26
        }
27 5
        return $collection;
28
    }
29
30 7
    private function requireArgTypes(array $args)
31
    {
32 7
        $this->expectArguments(
33 7
            'map',
34 7
            [['List', 'Vector', 'Hash']],
35 7
            $args
36
        );
37 6
        if (!isset($args[1]) || !($args[1] instanceof DesmondFunction)) {
38 1
            throw new ArgumentException('"map" expects argument 1 to be a function.');
39
        }
40 5
    }
41
}
42