edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||||||
| 2 | |||||||
| 3 | namespace TemplateNamespace\Entity\Fields\Traits; |
||||||
| 4 | |||||||
| 5 | use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
||||||
| 6 | use EdmondsCommerce\DoctrineStaticMeta\MappingHelper; |
||||||
| 7 | use Symfony\Component\Validator\Exception\ConstraintDefinitionException; |
||||||
| 8 | use Symfony\Component\Validator\Exception\InvalidOptionsException; |
||||||
| 9 | use Symfony\Component\Validator\Exception\MissingOptionsException; |
||||||
| 10 | use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData; |
||||||
| 11 | use TemplateNamespace\Entity\Fields\Interfaces\TemplateFieldNameFieldInterface; |
||||||
| 12 | |||||||
| 13 | trait TemplateFieldNameFieldTrait |
||||||
| 14 | { |
||||||
| 15 | /** |
||||||
| 16 | * @var string |
||||||
| 17 | */ |
||||||
| 18 | private $templateFieldName; |
||||||
| 19 | |||||||
| 20 | /** |
||||||
| 21 | * @param ClassMetadataBuilder $builder |
||||||
| 22 | * @SuppressWarnings(PHPMD.StaticAccess) |
||||||
| 23 | */ |
||||||
| 24 | public static function metaForTemplateFieldName(ClassMetadataBuilder $builder): void |
||||||
| 25 | { |
||||||
| 26 | MappingHelper::setSimpleStringFields( |
||||||
| 27 | [TemplateFieldNameFieldInterface::PROP_TEMPLATE_FIELD_NAME], |
||||||
| 28 | $builder, |
||||||
| 29 | TemplateFieldNameFieldInterface::DEFAULT_TEMPLATE_FIELD_NAME |
||||||
| 30 | ); |
||||||
| 31 | } |
||||||
| 32 | |||||||
| 33 | /** |
||||||
| 34 | * This method sets the validation for this field. |
||||||
| 35 | * You should add in as many relevant property constraints as you see fit. |
||||||
| 36 | * |
||||||
| 37 | * Remove the PHPMD suppressed warning once you start setting constraints |
||||||
| 38 | * |
||||||
| 39 | * @param ValidatorClassMetaData $metadata |
||||||
| 40 | * |
||||||
| 41 | * @throws MissingOptionsException |
||||||
| 42 | * @throws InvalidOptionsException |
||||||
| 43 | * @throws ConstraintDefinitionException |
||||||
| 44 | * |
||||||
| 45 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||||||
| 46 | * @see https://symfony.com/doc/current/validation.html#supported-constraints |
||||||
| 47 | * |
||||||
| 48 | */ |
||||||
| 49 | protected static function validatorMetaForPropertyTemplateFieldName(ValidatorClassMetaData $metadata): void |
||||||
|
0 ignored issues
–
show
|
|||||||
| 50 | { |
||||||
| 51 | // $metadata->addPropertyConstraint( |
||||||
| 52 | // TemplateFieldNameFieldInterface::PROP_TEMPLATE_FIELD_NAME, |
||||||
| 53 | // new NotBlank() |
||||||
| 54 | // ); |
||||||
| 55 | } |
||||||
| 56 | |||||||
| 57 | /** |
||||||
| 58 | * @return string |
||||||
| 59 | */ |
||||||
| 60 | public function getTemplateFieldName(): string |
||||||
| 61 | { |
||||||
| 62 | if (null === $this->templateFieldName) { |
||||||
| 63 | return TemplateFieldNameFieldInterface::DEFAULT_TEMPLATE_FIELD_NAME; |
||||||
| 64 | } |
||||||
| 65 | |||||||
| 66 | return $this->templateFieldName; |
||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | private function initTemplateFieldName(): void |
||||||
| 70 | { |
||||||
| 71 | $this->templateFieldName = TemplateFieldNameFieldInterface::DEFAULT_TEMPLATE_FIELD_NAME; |
||||||
| 72 | } |
||||||
| 73 | |||||||
| 74 | /** |
||||||
| 75 | * @param string $templateFieldName |
||||||
| 76 | * |
||||||
| 77 | * @return self |
||||||
| 78 | */ |
||||||
| 79 | private function setTemplateFieldName(string $templateFieldName): self |
||||||
| 80 | { |
||||||
| 81 | $this->updatePropertyValue( |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 82 | TemplateFieldNameFieldInterface::PROP_TEMPLATE_FIELD_NAME, |
||||||
| 83 | $templateFieldName |
||||||
| 84 | ); |
||||||
| 85 | |||||||
| 86 | return $this; |
||||||
| 87 | } |
||||||
| 88 | } |
||||||
| 89 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.