InMemoryValue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B get() 0 24 4
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