GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( fd432d...bef2be )
by Ross
25s queued 11s
created

metaForCreationTimestamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1.0837

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 16
ccs 9
cts 16
cp 0.5625
crap 1.0837
rs 9.9332
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\TimeStamp;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\ORM\Events;
7
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
8
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\TimeStamp\CreationTimestampFieldInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
12
/**
13
 * Trait TimestampFieldTrait
14
 *
15
 * An Immutable creation timestamp. It is null until it is saved (and reloaded)
16
 *
17
 * Notice the use of a lifecyle event to handle setting the pre persist creation timestamp
18
 *
19
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\DateTime
20
 */
21
trait CreationTimestampFieldTrait
22
{
23
24
    /**
25
     * @var \DateTimeImmutable|null
26
     */
27
    private $creationTimestamp;
28
29
    /**
30
     * @SuppressWarnings(PHPMD.StaticAccess)
31
     * @param ClassMetadataBuilder $builder
32
     */
33 2
    public static function metaForCreationTimestamp(ClassMetadataBuilder $builder): void
34
    {
35 2
        $builder->addLifecycleEvent('prePersistCreationTimestamp', Events::prePersist);
36 2
        $fieldBuilder = new FieldBuilder(
37 2
            $builder,
38
            [
39 2
                'fieldName' => CreationTimestampFieldInterface::PROP_CREATION_TIMESTAMP,
40
                'type'      => Type::DATETIME_IMMUTABLE,
41
            ]
42
        );
43
        $fieldBuilder
44 2
            ->columnName(MappingHelper::getColumnNameForField(
45 2
                CreationTimestampFieldInterface::PROP_CREATION_TIMESTAMP
46
            ))
47 2
            ->nullable(false)
48 2
            ->build();
49 2
    }
50
51
    /**
52
     * @throws \Exception
53
     */
54 2
    public function prePersistCreationTimestamp(): void
55
    {
56 2
        if (null === $this->creationTimestamp) {
57 2
            $this->creationTimestamp = new \DateTimeImmutable();
58
        }
59 2
    }
60
61
    /**
62
     * @return \DateTimeImmutable|null
63
     */
64 2
    public function getCreationTimestamp(): ?\DateTimeImmutable
65
    {
66 2
        return $this->creationTimestamp;
67
    }
68
}
69