Completed
Push — master ( 5b8d73...30d679 )
by Adam
21:09
created

ValueObject::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace BestServedCold\PhalueObjects;
4
5
/**
6
 * Class ValueObject
7
 *
8
 * @package   BestServedCold\PhalueObjects
9
 * @author    Adam Lewis <[email protected]>
10
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
11
 * @license	  http://http://opensource.org/licenses/GPL-3.0 GPL License
12
 * @link	  http://bestservedcold.com
13
 * @since	  0.0.1-alpha
14
 * @version   0.0.2-alpha
15
 */
16
class ValueObject implements ValueObjectInterface
17
{
18
    /**
19
     * @var \ReflectionClass
20
     */
21
    protected $reflection;
22
23
    /**
24
     * @var mixed
25
     */
26
    protected $value;
27
28
    /**
29
     * Class Constructor
30
     */
31 108
    public function __construct($value)
32
    {
33 108
        $this->value = $value;
34 108
        $this->reflection = new \ReflectionClass($this);
35 108
    }
36
37
    /**
38
     * @return string
39
     */
40 1
    public function getShortName()
41
    {
42 1
        return $this->reflection->getShortName();
43
    }
44
45
    /**
46
     * @param $field
47
     * @param $value
48
     */
49 1
    public function __set($field, $value)
50
    {
51 1
        throw new \RuntimeException(
52
            "You cannot set a value of a Value Object, that's the whole point!"
53 1
        );
54
    }
55
56
    /**
57
     * @return string
58
     */
59 1
    public function hash()
60
    {
61 1
        return spl_object_hash($this);
62
    }
63
64
    /**
65
     * @param  $object
66
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use object.

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...
67
     */
68 1
    public function cloneObject($object)
69
    {
70 1
        return clone($object);
71
    }
72
73
    /**
74
     * @param $string
75
     * @return static
76
     */
77 1
    public static function fromString($string)
78
    {
79 1
        return new static((string) $string);
80
    }
81
82
    /**
83
     * @return mixed
84
     */
85 82
    public function getValue()
86
    {
87 82
        return $this->value;
88
    }
89
90
    /**
91
     * @return string
92
     */
93 30
    public function __toString()
94
    {
95 30
        return (string) $this->value;
96
    }
97
98
    /**
99
     * @param  ValueObject $object
100
     * @return bool
101
     */
102
    public function equals(ValueObject $object)
0 ignored issues
show
Coding Style introduced by
function equals() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
103
    {
104
        return $this->value === $object->value;
105
    }
106
}
107