SimpleValueObject   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A value() 0 4 1
A __toString() 0 4 1
A equals() 0 4 2
A mutate() 0 4 1
1
<?php
2
3
namespace JimmyOak\DataType;
4
5
abstract class SimpleValueObject
6
{
7
    /**
8
     * @var mixed
9
     */
10
    private $value;
11
12
    /**
13
     * SimpleValueObject constructor.
14
     *
15
     * @param mixed $value
16
     */
17
    public function __construct($value)
18
    {
19
        $this->value = $value;
20
    }
21
22
    /**
23
     * @return mixed
24
     */
25
    public function value()
26
    {
27
        return $this->value;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function __toString()
34
    {
35
        return (string) $this->value();
36
    }
37
38
    /**
39
     * @param SimpleValueObject $object
40
     *
41
     * @return bool
42
     */
43
    public function equals(SimpleValueObject $object)
44
    {
45
        return $this->value() === $object->value() && static::class === get_class($object);
46
    }
47
48
    /**
49
     * @param mixed $newValue
50
     *
51
     * @return static
52
     */
53
    protected function mutate($newValue)
54
    {
55
        return new static($newValue);
56
    }
57
}
58