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

ApprovedFieldTrait::isApproved()   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\ApprovedFieldInterface;
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 ApprovedFieldTrait
17
{
18
19
    /**
20
     * @var bool
21
     */
22
    private $approved;
23
24
    /**
25
     * @SuppressWarnings(PHPMD.StaticAccess)
26
     * @param ClassMetadataBuilder $builder
27
     */
28
    public static function metaForIsApproved(ClassMetadataBuilder $builder): void
29
    {
30
        $fieldBuilder = new FieldBuilder($builder, [
31
            'default'    => ApprovedFieldInterface::DEFAULT_APPROVED,
32
            'fieldName'  => ApprovedFieldInterface::PROP_APPROVED,
33
            'columnName' => MappingHelper::getColumnNameForField(ApprovedFieldInterface::PROP_APPROVED),
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 validatorMetaForIsApproved(ValidatorClassMetaData $metadata): void
48
    {
49
        $metadata->addPropertyConstraint(
50
            ApprovedFieldInterface::PROP_APPROVED,
51
            new NotNull()
52
        );
53
    }
54
55
    /**
56
     * @return bool
57
     */
58 1
    public function isApproved(): bool
59
    {
60 1
        if (null === $this->approved) {
61 1
            return ApprovedFieldInterface::DEFAULT_APPROVED;
62
        }
63
64 1
        return $this->approved;
65
    }
66
67
    /**
68
     * @param bool $approved
69
     *
70
     * @return $this|ApprovedFieldInterface
71
     */
72 1
    public function setApproved(bool $approved): self
73
    {
74 1
        $this->approved = $approved;
75 1
        if ($this instanceof ValidatedEntityInterface) {
76 1
            $this->validateProperty(ApprovedFieldInterface::PROP_APPROVED);
77
        }
78
79 1
        return $this;
80
    }
81
}
82