Module   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 83
ccs 20
cts 21
cp 0.9524
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getName() 0 4 1
A getVersion() 0 4 1
A getClass() 0 4 1
A getValue() 0 6 1
A validate() 0 12 3
1
<?php
2
3
namespace Wambo\Core\Module;
4
5
use Wambo\Core\Module\Exception\InvalidArgumentException;
6
use Wambo\Core\ValueObject\ValueObjectInterface;
7
use Wambo\Core\ValueObject\ValueObjectTrait;
8
9
/**
10
 * The Module Model is a Value Object. It is only represents by his values.
11
 *
12
 * @package Wambo\Core\Model
13
 */
14
class Module implements ValueObjectInterface
15
{
16
    use ValueObjectTrait;
17
18
    /**
19
     * @var string
20
     */
21
    private $name;
22
23
    /**
24
     * @var string
25
     */
26
    private $version;
27
28
    /**
29
     * @var string
30
     */
31
    private $class;
32
33
34
    /**
35
     * Module constructor.
36
     * @param string $name
37
     */
38 6
    public function __construct(string $name, string $version, string $class)
39
    {
40 6
        $this->validate($name, 'name');
41
42 5
        $this->name = $name;
43 5
        $this->version = $version;
44 5
        $this->class = $class;
45 5
    }
46
47
    /**
48
     * @return string
49
     */
50 3
    public function getName() : string
51
    {
52 3
        return $this->name;
53
    }
54
55
    /**
56
     * @return string
57
     */
58 3
    public function getVersion() : string
59
    {
60 3
        return $this->version;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 3
    public function getClass() : string
67
    {
68 3
        return $this->class;
69
    }
70
71
72 2
    public function getValue()
73
    {
74
        // ToDo: is the use of ModuleMapper ok in this scope?
75 2
        $mapper = new ModuleMapper();
76 2
        return $mapper->getData($this);
77
    }
78
79
    /**
80
     * @param string $attr
81
     * @param string $attrName
82
     */
83 6
    private function validate(string $attr, string $attrName)
84
    {
85
        // empty
86 6
        if (strlen($attr) === 0) {
87 1
            throw new InvalidArgumentException(sprintf('%s can not be empty', $attrName));
88
        }
89
90
        // whitespaces
91 5
        if (preg_match('/\s/', $attr)) {
92
            throw new InvalidArgumentException(sprintf('illigal %s', $attrName));
93
        }
94 5
    }
95
96
}