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 (#51)
by joseph
102:38 queued 99:24
created

DefaultFieldTrait::isDefault()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Flag;
4
5
// phpcs:disable
6
7
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
8
use Doctrine\ORM\Mapping\Builder\FieldBuilder;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Flag\DefaultFieldInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
11
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
12
use Symfony\Component\Validator\Constraints\NotNull;
13
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
14
15
// phpcs:enable
16
trait DefaultFieldTrait
17
{
18
19
    /**
20
     * @var bool
21
     */
22
    private $default;
23
24
    /**
25
     * @SuppressWarnings(PHPMD.StaticAccess)
26
     * @param ClassMetadataBuilder $builder
27
     */
28
    public static function metaForIsDefault(ClassMetadataBuilder $builder): void
29
    {
30
        $fieldBuilder = new FieldBuilder($builder, [
31
            'default'    => DefaultFieldInterface::DEFAULT_DEFAULT,
32
            'fieldName'  => DefaultFieldInterface::PROP_DEFAULT,
33
            'columnName' => MappingHelper::getColumnNameForField(DefaultFieldInterface::PROP_DEFAULT),
34
            'type'       => MappingHelper::TYPE_BOOLEAN,
35
            'nullable'   => false,
36
        ]);
37
        $fieldBuilder->build();
38
    }
39
40
    /**
41
     * @param ValidatorClassMetaData $metadata
42
     *
43
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
44
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
45
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
46
     */
47
    protected static function validatorMetaForIsDefault(ValidatorClassMetaData $metadata): void
48
    {
49
        $metadata->addPropertyConstraint(
50
            DefaultFieldInterface::PROP_DEFAULT,
51
            new NotNull()
52
        );
53
    }
54
55
    /**
56
     * @return bool
57
     */
58 1
    public function isDefault(): bool
59
    {
60 1
        if (null === $this->default) {
61 1
            return DefaultFieldInterface::DEFAULT_DEFAULT;
62
        }
63
64 1
        return $this->default;
65
    }
66
67
    /**
68
     * @param bool $default
69
     *
70
     * @return $this|DefaultFieldInterface
71
     */
72 1
    public function setDefault(bool $default): self
73
    {
74 1
        $this->default = $default;
75 1
        if ($this instanceof ValidatedEntityInterface) {
76 1
            $this->validateProperty(DefaultFieldInterface::PROP_DEFAULT);
77
        }
78
79 1
        return $this;
80
    }
81
}
82