edmondscommerce /
doctrine-static-meta
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Identity; |
||||||
| 6 | |||||||
| 7 | use Doctrine\ORM\Events; |
||||||
| 8 | use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
||||||
| 9 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Identity\HasFullNameEmbeddableInterface; |
||||||
| 10 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Identity\FullNameEmbeddableInterface; |
||||||
| 11 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Identity\FullNameEmbeddable; |
||||||
| 12 | |||||||
| 13 | trait HasFullNameEmbeddableTrait |
||||||
| 14 | { |
||||||
| 15 | /** |
||||||
| 16 | * @var FullNameEmbeddableInterface |
||||||
| 17 | */ |
||||||
| 18 | private $fullNameEmbeddable; |
||||||
| 19 | |||||||
| 20 | /** |
||||||
| 21 | * @param ClassMetadataBuilder $builder |
||||||
| 22 | */ |
||||||
| 23 | 1 | protected static function metaForFullNameEmbeddable(ClassMetadataBuilder $builder): void |
|||||
| 24 | { |
||||||
| 25 | 1 | $builder->addLifecycleEvent( |
|||||
| 26 | 1 | 'postLoadSetOwningEntityOnFullNameEmbeddable', |
|||||
| 27 | 1 | Events::postLoad |
|||||
| 28 | ); |
||||||
| 29 | 1 | $builder->createEmbedded( |
|||||
| 30 | 1 | HasFullNameEmbeddableInterface::PROP_FULL_NAME_EMBEDDABLE, |
|||||
| 31 | 1 | FullNameEmbeddable::class |
|||||
| 32 | ) |
||||||
| 33 | 1 | ->setColumnPrefix( |
|||||
| 34 | 1 | HasFullNameEmbeddableInterface::COLUMN_PREFIX_FULL_NAME |
|||||
| 35 | ) |
||||||
| 36 | 1 | ->build(); |
|||||
| 37 | 1 | } |
|||||
| 38 | |||||||
| 39 | /** |
||||||
| 40 | * @return mixed |
||||||
| 41 | */ |
||||||
| 42 | 1 | public function getFullNameEmbeddable(): FullNameEmbeddableInterface |
|||||
| 43 | { |
||||||
| 44 | 1 | return $this->fullNameEmbeddable; |
|||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | public function postLoadSetOwningEntityOnFullNameEmbeddable(): void |
||||||
| 48 | { |
||||||
| 49 | $this->fullNameEmbeddable->setOwningEntity($this); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 50 | } |
||||||
| 51 | |||||||
| 52 | /** |
||||||
| 53 | * Called at construction time |
||||||
| 54 | * @SuppressWarnings(PHPMD.StaticAccess) |
||||||
| 55 | */ |
||||||
| 56 | 1 | private function initFullNameEmbeddable(): void |
|||||
| 57 | { |
||||||
| 58 | 1 | $this->setFullNameEmbeddable( |
|||||
| 59 | 1 | FullNameEmbeddable::create(FullNameEmbeddable::DEFAULTS), |
|||||
| 60 | 1 | false |
|||||
| 61 | ); |
||||||
| 62 | 1 | } |
|||||
| 63 | |||||||
| 64 | /** |
||||||
| 65 | * @param FullNameEmbeddableInterface $fullNameEmbeddable |
||||||
| 66 | * |
||||||
| 67 | * @param bool $notify |
||||||
| 68 | * |
||||||
| 69 | * @return $this |
||||||
| 70 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||||||
| 71 | */ |
||||||
| 72 | 1 | private function setFullNameEmbeddable(FullNameEmbeddableInterface $fullNameEmbeddable, bool $notify = true): self |
|||||
| 73 | { |
||||||
| 74 | 1 | $this->fullNameEmbeddable = $fullNameEmbeddable; |
|||||
| 75 | 1 | $this->fullNameEmbeddable->setOwningEntity($this); |
|||||
|
0 ignored issues
–
show
$this of type EdmondsCommerce\Doctrine...FullNameEmbeddableTrait is incompatible with the type EdmondsCommerce\Doctrine...TrackingPolicyInterface expected by parameter $entity of EdmondsCommerce\Doctrine...face::setOwningEntity().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 76 | 1 | if (true === $notify) { |
|||||
| 77 | 1 | $this->notifyEmbeddablePrefixedProperties( |
|||||
|
0 ignored issues
–
show
It seems like
notifyEmbeddablePrefixedProperties() 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...
|
|||||||
| 78 | 1 | HasFullNameEmbeddableInterface::PROP_FULL_NAME_EMBEDDABLE |
|||||
| 79 | ); |
||||||
| 80 | } |
||||||
| 81 | |||||||
| 82 | 1 | return $this; |
|||||
| 83 | } |
||||||
| 84 | } |
||||||
| 85 |