GenericSlumberer::slumber()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 22
c 0
b 0
f 0
rs 9.9332
ccs 11
cts 11
cp 1
cc 4
nc 3
nop 1
crap 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