Completed
Push — master ( d17d72...1ce681 )
by Mario
03:24
created

ValueObject::__isset()   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
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Marek\Toggable\API\Toggl\Values;
4
5
use Marek\Toggable\API\Exception\PropertyNotFoundException;
6
use RuntimeException;
7
8
/**
9
 * Class ValueObject
10
 * @package Marek\Toggable\API\Toggl\Values
11
 */
12
abstract class ValueObject
13
{
14
    /**
15
     * Construct object optionally with a set of properties.
16
     *
17
     * Readonly properties values must be set using $properties as they are not writable anymore
18
     * after object has been created.
19
     *
20
     * @param array $properties
21
     *
22
     * @throws \Marek\Toggable\API\Exception\PropertyNotFoundException
23
     */
24 303
    public function __construct(array $properties = array())
25
    {
26 303
        foreach ($properties as $property => $value) {
27 266
            if (property_exists($this, $property)) {
28 265
                $this->$property = $value;
29
            } else {
30 266
                throw new PropertyNotFoundException($property, get_class($this));
31
            }
32
        }
33 303
    }
34
35
36
    /**
37
     * @param $property
38
     *
39
     * @return mixed
40
     *
41
     * @throws \Marek\Toggable\API\Exception\PropertyNotFoundException
42
     */
43
    public function __get($property)
44
    {
45
        if (property_exists($this, $property)) {
46
            return $this->$property;
47
        }
48
        throw new PropertyNotFoundException($property, get_class($this));
49
    }
50
51
    /**
52
     * Magic isset function handling isset() to non public properties.
53
     *
54
     * Returns true for all (public/)protected/private properties.
55
     *
56
     * @ignore This method is for internal use
57
     *
58
     * @param string $property Name of the property
59
     *
60
     * @return bool
61
     */
62
    public function __isset($property)
63
    {
64
        return property_exists($this, $property);
65
    }
66
}
67