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 (#59)
by joseph
17:21
created

SettableUuidFieldTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 76
rs 10
c 0
b 0
f 0
ccs 24
cts 24
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A metaForSettableUuid() 0 16 1
A validatorMetaForSettableUuid() 0 5 1
A setSettableUuid() 0 8 2
A getSettableUuid() 0 7 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String;
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\String\SettableUuidFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use Symfony\Component\Validator\Constraints\Uuid;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
/**
15
 * Trait SettableUuidFieldTrait
16
 *
17
 * This field allows you to set a UUID that is generated elsewhere than the database.
18
 * This is as opposed to using a UUID primary key which is generated by the database
19
 * - eg
20
 * \EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\UuidFieldTrait
21
 *
22
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String
23
 */
24
trait SettableUuidFieldTrait
25
{
26
27
    /**
28
     * @var string|null
29
     */
30
    private $settableUuid;
31
32
    /**
33
     * @SuppressWarnings(PHPMD.StaticAccess)
34
     * @param ClassMetadataBuilder $builder
35
     */
36 1
    public static function metaForSettableUuid(ClassMetadataBuilder $builder): void
37
    {
38 1
        $fieldBuilder = new FieldBuilder(
39 1
            $builder,
40
            [
41 1
                'fieldName' => SettableUuidFieldInterface::PROP_SETTABLE_UUID,
42
                'type'      => Type::STRING,
43
                'default'   => SettableUuidFieldInterface::DEFAULT_SETTABLE_UUID,
44
            ]
45
        );
46
        $fieldBuilder
47 1
            ->columnName(MappingHelper::getColumnNameForField(SettableUuidFieldInterface::PROP_SETTABLE_UUID))
48 1
            ->nullable(null === SettableUuidFieldInterface::DEFAULT_SETTABLE_UUID)
49 1
            ->unique(true)
50 1
            ->length(100)
51 1
            ->build();
52 1
    }
53
54
    /**
55
     * This method sets the validation for this field.
56
     *
57
     * You should add in as many relevant property constraints as you see fit.
58
     *
59
     * @see https://symfony.com/doc/current/validation.html#supported-constraints
60
     *
61
     * @param ValidatorClassMetaData $metadata
62
     *
63
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
64
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
65
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
66
     */
67 2
    protected static function validatorMetaForSettableUuid(ValidatorClassMetaData $metadata)
68
    {
69 2
        $metadata->addPropertyConstraint(
70 2
            SettableUuidFieldInterface::PROP_SETTABLE_UUID,
71 2
            new Uuid()
72
        );
73 2
    }
74
75
    /**
76
     * @return string|null
77
     */
78 2
    public function getSettableUuid(): ?string
79
    {
80 2
        if (null === $this->settableUuid) {
81 1
            return SettableUuidFieldInterface::DEFAULT_SETTABLE_UUID;
82
        }
83
84 2
        return $this->settableUuid;
85
    }
86
87
    /**
88
     * @param string|null $settableUuid
89
     *
90
     * @return self
91
     */
92 2
    public function setSettableUuid(?string $settableUuid): self
93
    {
94 2
        $this->settableUuid = $settableUuid;
95 2
        if ($this instanceof ValidatedEntityInterface) {
96 2
            $this->validateProperty(SettableUuidFieldInterface::PROP_SETTABLE_UUID);
97
        }
98
99 2
        return $this;
100
    }
101
}
102