Completed
Push — master ( 33be91...7b0176 )
by
unknown
29:05
created

InMemoryValue::get()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.6845
cc 4
eloc 13
nc 4
nop 2
1
<?php
2
3
namespace NilPortugues\Foundation\Infrastructure\Model\Repository\InMemory;
4
5
class InMemoryValue
6
{
7
    /**
8
     * @param $object
9
     * @param string $property
10
     *
11
     * @return mixed
12
     *
13
     * @throws \Exception
14
     */
15
    public static function get($object, $property)
16
    {
17
        if (array_key_exists($property, get_object_vars($object))) {
18
            return $object->{$property};
19
        }
20
21
        if (method_exists(get_class($object), $property)) {
22
            return $object->{$property}();
23
        }
24
25
        if (method_exists(get_class($object), 'get'.$property)) {
26
            $property = 'get'.$property;
27
28
            return $object->{$property}();
29
        }
30
31
        throw new \Exception(
32
            sprintf(
33
                'Could not filter by property \'%s\' as it does not exist in object %s.',
34
                $property,
35
                get_class($object)
36
            )
37
        );
38
    }
39
}
40