Completed
Push — master ( 50437b...6d2b5a )
by Adam
02:31
created

ValueObject::diff()   C

Complexity

Conditions 11
Paths 10

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 25
cts 25
cp 1
rs 5.2653
c 0
b 0
f 0
cc 11
eloc 22
nc 10
nop 1
crap 11

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 32
    public function __toString()
66
    {
67 32
        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