Completed
Push — master ( 693b87...d2ff05 )
by Woody
12:19 queued 10:29
created

ProtectedValueObjectTrait::__isset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Equip\Data\Traits;
4
5
use RuntimeException;
6
7
trait ProtectedValueObjectTrait
8
{
9
    /**
10
     * Checks if a property is defined in the object
11
     *
12
     * This will return `false` if the value is `null`! To check if a value
13
     * exists in the object, use `has()`.
14
     *
15
     * @param string $key
16
     *
17
     * @return boolean
18
     */
19 1
    public function __isset($key)
20
    {
21 1
        return isset($this->$key);
22
    }
23
24
    /**
25
     * Allow read access to immutable object properties
26
     *
27
     * @param string $key
28
     *
29
     * @return mixed
30
     */
31 3
    public function __get($key)
32
    {
33 3
        return $this->$key;
34
    }
35
36
    /**
37
     * Protects against the object being modified
38
     *
39
     * @param string $key
40
     * @param mixed  $value
41
     *
42
     * @return void
43
     *
44
     * @throws \RuntimeException
45
     */
46 1
    public function __set($key, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48 1
        throw new RuntimeException(sprintf(
49 1
            'Modification of immutable object `%s` is not allowed',
50
            get_class($this)
51
        ));
52
    }
53
54
    /**
55
     * Protects against the object being modified
56
     *
57
     * @param string $key
58
     *
59
     * @return void
60
     *
61
     * @throws \RuntimeException
62
     */
63 1
    public function __unset($key)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65 1
        throw new RuntimeException(sprintf(
66 1
            'Modification of immutable object `%s` is not allowed',
67
            get_class($this)
68
        ));
69
    }
70
}
71