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 ( 84e592...894b2c )
by joseph
127:56 queued 125:09
created

CreationTimestampFieldTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 62.07%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 49
ccs 18
cts 29
cp 0.6207
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A metaForCreationTimestamp() 0 16 1
A getCreationTimestamp() 0 3 1
A prePersistCreationTimestamp() 0 6 2
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->updatePropertyValue(
0 ignored issues
show
Bug introduced by
It seems like updatePropertyValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            $this->/** @scrutinizer ignore-call */ 
58
                   updatePropertyValue(
Loading history...
58 2
                CreationTimestampFieldInterface::PROP_CREATION_TIMESTAMP,
59 2
                new \DateTimeImmutable()
60
            );
61
        }
62 2
    }
63
64
    /**
65
     * @return \DateTimeImmutable|null
66
     */
67 2
    public function getCreationTimestamp(): ?\DateTimeImmutable
68
    {
69 2
        return $this->creationTimestamp;
70
    }
71
}
72