AsUserRecord   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A onPreSave() 0 12 4
1
<?php
2
/**
3
 * File was created 26.04.2016 07:20
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Annotation\Slumber\Store;
7
8
use Doctrine\Common\Annotations\Annotation;
9
use PeekAndPoke\Component\Slumber\Annotation\PropertyPreSaveVisitorMarker;
10
use PeekAndPoke\Component\Slumber\Annotation\ServiceInjectingSlumberAnnotation;
11
use PeekAndPoke\Component\Slumber\Data\Addon\UserRecord\UserRecord;
12
use PeekAndPoke\Component\Slumber\Data\Addon\UserRecord\UserRecordProvider;
13
use Psr\Container\ContainerInterface;
14
15
/**
16
 * @Annotation
17
 * @Annotation\Target("PROPERTY")
18
 *
19
 * @author Karsten J. Gerber <[email protected]>
20
 */
21
class AsUserRecord extends ServiceInjectingSlumberAnnotation implements PropertyPreSaveVisitorMarker
22
{
23
    /**
24
     * @param ContainerInterface  $provider
25
     * @param mixed               $subject
26
     * @param \ReflectionProperty $property
27
     */
28 28
    public function onPreSave(ContainerInterface $provider, $subject, \ReflectionProperty $property)
29
    {
30 28
        $val = $property->getValue($subject);
31
32 28
        if ($val === null || ($val instanceof UserRecord && empty($val->getName()))) {
33
34
            /** @var UserRecordProvider $creator */
35 28
            $creator = $this->getService($provider);
36
37 28
            $property->setValue($subject, $creator->getUserRecord());
38
        }
39 28
    }
40
}
41