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 ( 37eca9...fbc101 )
by joseph
236:04 queued 233:05
created

metaForDateTimeSettableOnce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1.1016

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 15
ccs 8
cts 15
cp 0.5333
crap 1.1016
rs 9.9666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\DateTime;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
7
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\DateTime\DateTimeSettableOnceFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
10
11
/**
12
 * Trait DateTimeSettableOnceFieldTrait
13
 *
14
 * This field is a dateTime that will be null until you set it. Once set (and possibly saved) it can not be updated
15
 *
16
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\DateTime
17
 */
18
trait DateTimeSettableOnceFieldTrait
19
{
20
21
    /**
22
     * @var \DateTimeImmutable|null
23
     */
24
    private $dateTimeSettableOnce;
25
26
    /**
27
     * @SuppressWarnings(PHPMD.StaticAccess)
28
     * @param ClassMetadataBuilder $builder
29
     */
30 2
    public static function metaForDateTimeSettableOnce(ClassMetadataBuilder $builder): void
31
    {
32 2
        $fieldBuilder = new FieldBuilder(
33 2
            $builder,
34
            [
35 2
                'fieldName' => DateTimeSettableOnceFieldInterface::PROP_DATE_TIME_SETTABLE_ONCE,
36
                'type'      => Type::DATETIME_IMMUTABLE,
37
            ]
38
        );
39
        $fieldBuilder
40 2
            ->columnName(MappingHelper::getColumnNameForField(
41 2
                DateTimeSettableOnceFieldInterface::PROP_DATE_TIME_SETTABLE_ONCE
42
            ))
43 2
            ->nullable(DateTimeSettableOnceFieldInterface::DEFAULT_DATE_TIME_SETTABLE_ONCE === null)
44 2
            ->build();
45 2
    }
46
47
    /**
48
     * @return \DateTimeImmutable|null
49
     */
50 2
    public function getDateTimeSettableOnce(): ?\DateTimeImmutable
51
    {
52 2
        return $this->dateTimeSettableOnce;
53
    }
54
55
    /**
56
     * @param \DateTimeImmutable|null $dateTimeSettableOnce
57
     *
58
     * @return self
59
     */
60 2
    private function setDateTimeSettableOnce(?\DateTimeImmutable $dateTimeSettableOnce): self
61
    {
62 2
        if (null === $dateTimeSettableOnce) {
63 2
            return $this;
64
        }
65 2
        if (null !== $this->dateTimeSettableOnce) {
66
            throw new \RuntimeException(
67
                DateTimeSettableOnceFieldInterface::PROP_DATE_TIME_SETTABLE_ONCE
68
                . ' is already set, you can not overwrite this with a new dateTime'
69
            );
70
        }
71 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

71
        $this->/** @scrutinizer ignore-call */ 
72
               updatePropertyValue(
Loading history...
72 2
            DateTimeSettableOnceFieldInterface::PROP_DATE_TIME_SETTABLE_ONCE,
73 2
            $dateTimeSettableOnce
74
        );
75
76 2
        return $this;
77
    }
78
}
79