GenericSlumberer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 40
c 0
b 0
f 0
rs 10
ccs 14
cts 14
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A slumber() 0 22 4
1
<?php
2
/**
3
 * File was created 07.10.2015 06:33
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Core\Codec;
7
8
use PeekAndPoke\Component\Slumber\Core\LookUp\EntityConfigReader;
9
10
/**
11
 * @author Karsten J. Gerber <[email protected]>
12
 */
13
class GenericSlumberer implements Slumberer
14
{
15
    /** @var EntityConfigReader */
16
    protected $entityConfigLookUp;
17
18
    /**
19
     * @param EntityConfigReader $entityConfigLookUp
20
     */
21 372
    public function __construct(EntityConfigReader $entityConfigLookUp)
22
    {
23 372
        $this->entityConfigLookUp = $entityConfigLookUp;
24 372
    }
25
26
    /**
27
     * @param mixed $subject
28
     *
29
     * @return array|mixed|null
30
     */
31 17
    public function slumber($subject)
32
    {
33 17
        if (\is_object($subject) &&
34 17
            $config = $this->entityConfigLookUp->getEntityConfig(new \ReflectionClass($subject))
35
        ) {
36
37 13
            $result  = [];
38 13
            $entries = $config->getMarkedProperties();
39
40 13
            foreach ($entries as $entry) {
41
42
                // put the value to sleep using the alias name
43 12
                $result[$entry->alias] = $entry->mapper->slumber(
44 12
                    $this,
45 12
                    $entry->propertyAccess->get($subject)
46
                );
47
            }
48
49 13
            return $result;
50
        }
51
52 4
        return null;
53
    }
54
}
55