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
Pull Request — master (#221)
by joseph
96:29 queued 93:03
created

UpdatedAtTimestampFieldTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 47
ccs 18
cts 18
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prePersistUpdatedAtTimestamp() 0 5 1
A getUpdatedAtTimestamp() 0 3 1
A metaForUpdatedAtTimestamp() 0 17 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\TimeStamp;
4
5
use DateTimeImmutable;
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\ORM\Events;
8
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
9
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\TimeStamp\UpdatedAtTimestampFieldInterface;
11
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
12
use Exception;
13
14
/**
15
 * Trait TimestampFieldTrait
16
 *
17
 * An Immutable creation timestamp. It is null until it is saved (and reloaded)
18
 *
19
 * Notice the use of a lifecyle event to handle setting the pre persist creation timestamp
20
 *
21
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\DateTime
22
 */
23
trait UpdatedAtTimestampFieldTrait
24
{
25
    /**
26
     * @var DateTimeImmutable|null
27
     */
28
    private $updatedAtTimestamp;
29
30
    /**
31
     * @SuppressWarnings(PHPMD.StaticAccess)
32
     * @param ClassMetadataBuilder $builder
33
     */
34 6
    public static function metaForUpdatedAtTimestamp(ClassMetadataBuilder $builder): void
35
    {
36 6
        $builder->addLifecycleEvent('prePersistUpdatedAtTimestamp', Events::preUpdate);
37 6
        $builder->addLifecycleEvent('prePersistUpdatedAtTimestamp', Events::prePersist);
38 6
        $fieldBuilder = new FieldBuilder(
39 6
            $builder,
40
            [
41 6
                'fieldName' => UpdatedAtTimestampFieldInterface::PROP_UPDATED_AT_TIMESTAMP,
42
                'type'      => Type::DATETIME_IMMUTABLE,
43
            ]
44
        );
45
        $fieldBuilder
46 6
            ->columnName(MappingHelper::getColumnNameForField(
47 6
                UpdatedAtTimestampFieldInterface::PROP_UPDATED_AT_TIMESTAMP
48
            ))
49 6
            ->nullable(false)
50 6
            ->build();
51 6
    }
52
53
    /**
54
     * @throws Exception
55
     */
56 6
    public function prePersistUpdatedAtTimestamp(): void
57
    {
58 6
        $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

58
        $this->/** @scrutinizer ignore-call */ 
59
               updatePropertyValue(
Loading history...
59 6
            UpdatedAtTimestampFieldInterface::PROP_UPDATED_AT_TIMESTAMP,
60 6
            new DateTimeImmutable()
61
        );
62 6
    }
63
64
    /**
65
     * @return DateTimeImmutable|null
66
     */
67 6
    public function getUpdatedAtTimestamp(): ?DateTimeImmutable
68
    {
69 6
        return $this->updatedAtTimestamp;
70
    }
71
}
72