1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\Boolean; |
4
|
|
|
|
5
|
|
|
// phpcs:disable |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\Boolean\DefaultsNullFieldInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
10
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData; |
11
|
|
|
|
12
|
|
|
// phpcs:enable |
13
|
|
|
trait DefaultsNullFieldTrait |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var bool|null |
18
|
|
|
*/ |
19
|
|
|
private $defaultsNull; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
23
|
|
|
* @param ClassMetadataBuilder $builder |
24
|
|
|
*/ |
25
|
1 |
|
public static function metaForDefaultsNull(ClassMetadataBuilder $builder): void |
26
|
|
|
{ |
27
|
1 |
|
MappingHelper::setSimpleBooleanFields( |
28
|
1 |
|
[DefaultsNullFieldInterface::PROP_DEFAULTS_NULL], |
29
|
1 |
|
$builder, |
30
|
1 |
|
DefaultsNullFieldInterface::DEFAULT_DEFAULTS_NULL |
31
|
|
|
); |
32
|
1 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* This method sets the validation for this field. |
36
|
|
|
* |
37
|
|
|
* You should add in as many relevant property constraints as you see fit. |
38
|
|
|
* |
39
|
|
|
* Remove the PHPMD suppressed warning once you start setting constraints |
40
|
|
|
* |
41
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
42
|
|
|
* @see https://symfony.com/doc/current/validation.html#supported-constraints |
43
|
|
|
* |
44
|
|
|
* @param ValidatorClassMetaData $metadata |
45
|
|
|
* |
46
|
|
|
* @throws \Symfony\Component\Validator\Exception\MissingOptionsException |
47
|
|
|
* @throws \Symfony\Component\Validator\Exception\InvalidOptionsException |
48
|
|
|
* @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
49
|
|
|
*/ |
50
|
|
|
protected static function validatorMetaForDefaultsNull(ValidatorClassMetaData $metadata): void |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
// $metadata->addPropertyConstraint( |
53
|
|
|
// DefaultsNullFieldInterface::PROP_DEFAULTS_NULL, |
54
|
|
|
// new NotBlank() |
55
|
|
|
// ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return bool|null |
60
|
|
|
*/ |
61
|
2 |
|
public function isDefaultsNull(): ?bool |
62
|
|
|
{ |
63
|
2 |
|
return $this->defaultsNull; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param bool|null $defaultsNull |
68
|
|
|
* |
69
|
|
|
* @return self |
70
|
|
|
*/ |
71
|
2 |
|
public function setDefaultsNull(?bool $defaultsNull): self |
72
|
|
|
{ |
73
|
2 |
|
$this->updatePropertyValueThenValidateAndNotify( |
|
|
|
|
74
|
2 |
|
DefaultsNullFieldInterface::PROP_DEFAULTS_NULL, |
75
|
2 |
|
$defaultsNull |
76
|
|
|
); |
77
|
|
|
|
78
|
2 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.