AsCreatedAt::onPreSave()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
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\SlumberAnnotation;
11
use Psr\Container\ContainerInterface;
12
13
/**
14
 * @Annotation
15
 * @Annotation\Target("PROPERTY")
16
 *
17
 * @author Karsten J. Gerber <[email protected]>
18
 */
19
class AsCreatedAt extends SlumberAnnotation implements PropertyPreSaveVisitorMarker
20
{
21
    /**
22
     * @param ContainerInterface  $provider
23
     * @param mixed               $subject
24
     * @param \ReflectionProperty $property
25
     */
26 27
    public function onPreSave(ContainerInterface $provider, $subject, \ReflectionProperty $property)
27
    {
28 27
        if ($property->getValue($subject) === null) {
29 27
            $property->setValue($subject, new \DateTime());
30
        }
31 27
    }
32
}
33