ModuleMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getModule() 0 12 4
A getData() 0 11 1
1
<?php
2
3
namespace Wambo\Core\Module;
4
5
use InvalidArgumentException;
6
7
class ModuleMapper
8
{
9
    /**
10
     * @param $data
11
     * @return Module
12
     */
13 4
    public function getModule($data) : Module
14
    {
15
        // ToDo: may static is better?
16 4
        if (!array_key_exists('name', $data) ||
17 3
            !array_key_exists('version', $data) ||
18 4
            !array_key_exists('class', $data)
19
        ) {
20 1
            throw new InvalidArgumentException('can not create Module. Not all nessesary data provided');
21
        }
22
23 3
        return new Module($data['name'], $data['version'], $data['class']);
24
    }
25
26
    /**
27
     * @param Module $module
28
     * @return array
29
     */
30 3
    public function getData(Module $module)
31
    {
32
        // ToDo: may static is better?
33
        $data = array(
34 3
            'name' => $module->getName(),
35 3
            'version' => $module->getVersion(),
36 3
            'class' => $module->getClass()
37
        );
38
39 3
        return $data;
40
    }
41
}