edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||||||
| 2 | |||||||
| 3 | namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Financial; |
||||||
| 4 | |||||||
| 5 | use Doctrine\ORM\Events; |
||||||
| 6 | use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
||||||
| 7 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Financial\HasMoneyEmbeddableInterface; |
||||||
| 8 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface; |
||||||
| 9 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable; |
||||||
| 10 | |||||||
| 11 | trait HasMoneyEmbeddableTrait |
||||||
| 12 | { |
||||||
| 13 | /** |
||||||
| 14 | * @var MoneyEmbeddableInterface |
||||||
| 15 | */ |
||||||
| 16 | private $moneyEmbeddable; |
||||||
| 17 | |||||||
| 18 | /** |
||||||
| 19 | * @param ClassMetadataBuilder $builder |
||||||
| 20 | */ |
||||||
| 21 | 2 | protected static function metaForMoney(ClassMetadataBuilder $builder): void |
|||||
| 22 | { |
||||||
| 23 | 2 | $builder->addLifecycleEvent('postLoadSetOwningEntityOnMoneyEmbeddable', Events::postLoad); |
|||||
| 24 | 2 | $builder->createEmbedded( |
|||||
| 25 | 2 | HasMoneyEmbeddableInterface::PROP_MONEY_EMBEDDABLE, |
|||||
| 26 | 2 | MoneyEmbeddable::class |
|||||
| 27 | ) |
||||||
| 28 | 2 | ->setColumnPrefix( |
|||||
| 29 | 2 | HasMoneyEmbeddableInterface::COLUMN_PREFIX_MONEY |
|||||
| 30 | ) |
||||||
| 31 | 2 | ->build(); |
|||||
| 32 | 2 | } |
|||||
| 33 | |||||||
| 34 | public function postLoadSetOwningEntityOnMoneyEmbeddable(): void |
||||||
| 35 | { |
||||||
| 36 | $this->moneyEmbeddable->setOwningEntity($this); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 37 | } |
||||||
| 38 | |||||||
| 39 | /** |
||||||
| 40 | * Called at construction time |
||||||
| 41 | */ |
||||||
| 42 | 2 | private function initMoneyEmbeddable(): void |
|||||
| 43 | { |
||||||
| 44 | 2 | $this->setMoneyEmbeddable(new MoneyEmbeddable(), false); |
|||||
| 45 | 2 | } |
|||||
| 46 | |||||||
| 47 | /** |
||||||
| 48 | * @return MoneyEmbeddableInterface |
||||||
| 49 | */ |
||||||
| 50 | 3 | public function getMoneyEmbeddable(): MoneyEmbeddableInterface |
|||||
| 51 | { |
||||||
| 52 | 3 | return $this->moneyEmbeddable; |
|||||
| 53 | } |
||||||
| 54 | |||||||
| 55 | /** |
||||||
| 56 | * @param MoneyEmbeddableInterface $moneyEmbeddable |
||||||
| 57 | * |
||||||
| 58 | * @param bool $notify |
||||||
| 59 | * |
||||||
| 60 | * @return $this |
||||||
| 61 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||||||
| 62 | */ |
||||||
| 63 | 3 | public function setMoneyEmbeddable(MoneyEmbeddableInterface $moneyEmbeddable, bool $notify = true): self |
|||||
| 64 | { |
||||||
| 65 | 3 | $this->moneyEmbeddable = $moneyEmbeddable; |
|||||
| 66 | 3 | $this->moneyEmbeddable->setOwningEntity($this); |
|||||
|
0 ignored issues
–
show
$this of type EdmondsCommerce\Doctrine...HasMoneyEmbeddableTrait 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...
|
|||||||
| 67 | 3 | if (true === $notify) { |
|||||
| 68 | 1 | $this->notifyEmbeddablePrefixedProperties(HasMoneyEmbeddableInterface::PROP_MONEY_EMBEDDABLE); |
|||||
|
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...
|
|||||||
| 69 | } |
||||||
| 70 | |||||||
| 71 | 3 | return $this; |
|||||
| 72 | } |
||||||
| 73 | } |
||||||
| 74 |