AsPublicReference   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onPreSave() 0 6 2
A createReference() 0 7 1
1
<?php
2
/**
3
 * File was created 05.10.2015 17:01
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\PublicReference\PublicReferenceGenerator;
12
use Psr\Container\ContainerInterface;
13
14
/**
15
 * @Annotation
16
 * @Annotation\Target("PROPERTY")
17
 *
18
 * @author Karsten J. Gerber <[email protected]>
19
 */
20
class AsPublicReference extends ServiceInjectingSlumberAnnotation implements PropertyPreSaveVisitorMarker
21
{
22
    /**
23
     * @param ContainerInterface  $provider
24
     * @param mixed               $subject
25
     * @param \ReflectionProperty $property
26
     */
27 27
    public function onPreSave(ContainerInterface $provider, $subject, \ReflectionProperty $property)
28
    {
29 27
        if (empty($property->getValue($subject))) {
30 26
            $property->setValue($subject, $this->createReference($provider, $subject));
31
        }
32 27
    }
33
34
    /**
35
     * @param ContainerInterface $provider
36
     * @param mixed              $subject
37
     *
38
     * @return mixed
39
     */
40 26
    private function createReference(ContainerInterface $provider, $subject)
41
    {
42
        /** @var PublicReferenceGenerator $creator */
43 26
        $creator = $this->getService($provider);
44
45 26
        return $creator->create($subject);
46
    }
47
}
48