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 (#154)
by Ross
22:04
created

ShortIndexedRequiredStringFieldTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 90.63%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 80
ccs 29
cts 32
cp 0.9063
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setShortIndexedRequiredString() 0 8 1
A getShortIndexedRequiredString() 0 7 2
A validatorMetaForPropertyShortIndexedRequiredString() 0 7 1
A initShortIndexedRequiredString() 0 4 1
A metaForShortIndexedRequiredString() 0 21 1
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\ShortIndexedRequiredStringFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
10
use Symfony\Component\Validator\Constraints\NotBlank;
11
use Symfony\Component\Validator\Constraints\NotEqualTo;
12
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
13
14
/**
15
 * This trait provides a short (50 characters) string which is non uniquely indexed and is required
16
 *
17
 * Trait ShortIndexedRequiredStringFieldTrait
18
 *
19
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String
20
 */
21
trait ShortIndexedRequiredStringFieldTrait
22
{
23
24
    /**
25
     * @var string
26
     */
27
    private $shortIndexedRequiredString;
28
29
    /**
30
     * @SuppressWarnings(PHPMD.StaticAccess)
31
     * @param ClassMetadataBuilder $builder
32
     */
33 4
    public static function metaForShortIndexedRequiredString(ClassMetadataBuilder $builder): void
34
    {
35 4
        $columnName   = MappingHelper::getColumnNameForField(
36 4
            ShortIndexedRequiredStringFieldInterface::PROP_SHORT_INDEXED_REQUIRED_STRING
37
        );
38 4
        $fieldBuilder = new FieldBuilder(
39 4
            $builder,
40
            [
41 4
                'fieldName' => ShortIndexedRequiredStringFieldInterface::PROP_SHORT_INDEXED_REQUIRED_STRING,
42
                'type'      => Type::STRING,
43
                'default'   => ShortIndexedRequiredStringFieldInterface::DEFAULT_SHORT_INDEXED_REQUIRED_STRING,
44
            ]
45
        );
46
        $fieldBuilder
47 4
            ->columnName($columnName)
48 4
            ->nullable(false)
49 4
            ->unique(false)
50 4
            ->length(50)
51 4
            ->build();
52
53 4
        $builder->addIndex([$columnName], $columnName . '_idx');
54 4
    }
55
56
    /**
57
     * @param ValidatorClassMetaData $metadata
58
     */
59 4
    protected static function validatorMetaForPropertyShortIndexedRequiredString(ValidatorClassMetaData $metadata): void
60
    {
61 4
        $metadata->addPropertyConstraints(
62 4
            ShortIndexedRequiredStringFieldInterface::PROP_SHORT_INDEXED_REQUIRED_STRING,
63
            [
64 4
                new NotEqualTo(ShortIndexedRequiredStringFieldInterface::DEFAULT_SHORT_INDEXED_REQUIRED_STRING),
65 4
                new NotBlank(),
66
            ]
67
        );
68 4
    }
69
70
    /**
71
     * @return string
72
     */
73 4
    public function getShortIndexedRequiredString(): string
74
    {
75 4
        if (null === $this->shortIndexedRequiredString) {
76
            return ShortIndexedRequiredStringFieldInterface::DEFAULT_SHORT_INDEXED_REQUIRED_STRING;
77
        }
78
79 4
        return $this->shortIndexedRequiredString;
80
    }
81
82
    /**
83
     * @param string|null $shortIndexedRequiredString
84
     *
85
     * @return self
86
     */
87 4
    private function setShortIndexedRequiredString(string $shortIndexedRequiredString): self
88
    {
89 4
        $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

89
        $this->/** @scrutinizer ignore-call */ 
90
               updatePropertyValue(
Loading history...
90 4
            ShortIndexedRequiredStringFieldInterface::PROP_SHORT_INDEXED_REQUIRED_STRING,
91 4
            $shortIndexedRequiredString
92
        );
93
94 4
        return $this;
95
    }
96
97 4
    private function initShortIndexedRequiredString(): void
98
    {
99 4
        $this->shortIndexedRequiredString =
100
            ShortIndexedRequiredStringFieldInterface::DEFAULT_SHORT_INDEXED_REQUIRED_STRING;
101 4
    }
102
}
103