Passed
Push — master ( e55347...7a3ff4 )
by Artem
06:53
created

ValueObject::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2016 Artem Rodygin
6
//
7
//  This file is part of DataTables Symfony bundle.
8
//
9
//  You should have received a copy of the MIT License along with
10
//  the bundle. If not, see <http://opensource.org/licenses/MIT>.
11
//
12
//----------------------------------------------------------------------
13
14
namespace DataTables;
15
16
/**
17
 * Immutable value object.
18
 */
19
class ValueObject
20
{
21
    /**
22
     * Checks whether specified property exists.
23
     *
24
     * @param string $name Name of the property.
25
     *
26
     * @return bool TRUE if the property exists, FALSE otherwise.
27
     */
28 1
    public function __isset(string $name): bool
29
    {
30 1
        return property_exists($this, $name);
31
    }
32
33
    /**
34
     * Returns current value of specified property.
35
     *
36
     * @param string $name Name of the property.
37
     *
38
     * @throws \BadMethodCallException If the property doesn't exist.
39
     *
40
     * @return mixed Current value of the property.
41
     */
42 2
    public function __get(string $name)
43
    {
44 2
        if (!property_exists($this, $name)) {
45 1
            throw new \BadMethodCallException(sprintf('Unknown property "%s" in class "%s".', $name, get_class($this)));
46
        }
47
48 1
        return $this->{$name};
49
    }
50
51
    /**
52
     * Prevents object's properties from modification.
53
     *
54
     * @param string $name  Name of the property.
55
     * @param mixed  $value New value of the property.
56
     */
57 1
    final public function __set(string $name, $value)
58
    {
59 1
    }
60
}
61