ValueObject   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 85
c 1
b 0
f 0
wmc 9
lcom 1
cbo 1
ccs 18
cts 20
cp 0.9
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getValue() 0 4 1
A __set() 0 6 1
A __toString() 0 4 2
A getType() 0 4 1
A hash() 0 4 1
A equals() 0 4 1
A __destruct() 0 4 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects;
4
5
use BestServedCold\PhalueObjects\Contract\ValueObject as ValueObjectInterface;
6
7
/**
8
 * Class ValueObject
9
 *
10
 * @package   BestServedCold\PhalueObjects
11
 * @author    Adam Lewis <[email protected]>
12
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
13
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
14
 * @link      http://bestservedcold.com
15
 * @since     0.0.1-alpha
16
 * @version   1.0.0
17
 */
18
abstract class ValueObject implements ValueObjectInterface
0 ignored issues
show
Coding Style introduced by
ValueObject does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
19
{
20
    /**
21
     * @var mixed
22
     */
23
    protected $value;
24
25
    /**
26
     * @var string
27
     */
28
    protected $type;
29
30
    /**
31
     * ValueObject constructor.
32
     *
33
     * @param $value
34
     */
35 200
    public function __construct($value)
36
    {
37 200
        $this->value = $value;
38 200
        $this->type  = gettype($value);
39 200
    }
40
41
    /**
42
     * @return mixed
43
     */
44 171
    public function getValue()
45
    {
46 171
        return $this->value;
47
    }
48
49
    /**
50
     * @param  $field
51
     * @param  $value
52
     * @throws \RuntimeException
53
     * @return void
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use NoType.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
54
     */
55 1
    public function __set($field, $value)
56
    {
57 1
        throw new \RuntimeException(
58
            "You cannot set a value of a Value Object, that's the whole point!"
59 1
        );
60
    }
61
62
    /**
63
     * @return string
64
     */
65 31
    public function __toString()
66
    {
67 31
        return method_exists($this, 'toString') ? $this->toString() : (string) $this->getValue();
0 ignored issues
show
Bug introduced by
The method toString() does not exist on BestServedCold\PhalueObjects\ValueObject. Did you maybe mean __toString()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getType()
74
    {
75
        return $this->type;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 1
    public function hash()
82
    {
83 1
        return spl_object_hash($this);
84
    }
85
86
    /**
87
     * @param  ValueObjectInterface $object
88
     * @return bool
89
     */
90 2
    public function equals(ValueObjectInterface $object)
91
    {
92 2
        return $this->getValue() === $object->getValue();
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98 190
    public function __destruct()
99
    {
100 190
        $this->value = null;
101 190
    }
102
}
103