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