distributionRotatingBuilder = $this->loadService(DistributionRotatingBuilder::class); $this->distributionRotatingRepository = $this->loadService(DistributionRotatingRepository::class); } public function createDistributionRotating(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating { $distributionRotating = $this->distributionRotatingBuilder->instanciateDistributionRotating(); $distributionRotating ->setDistribution($distribution) ->setRotating($rotatingProduct->getRotating()) ->setRotatingProduct($rotatingProduct); return $distributionRotating; } public function createDistributionRotatingIfNotExist(Distribution $distribution, RotatingProduct $rotatingProduct): DistributionRotating { $distributionRotating = $this->distributionRotatingRepository->findOneDistributionRotating($distribution, $rotatingProduct->getRotating()); if($distributionRotating) { $distributionRotating->setRotatingProduct($rotatingProduct); $distributionRotating->save(); return $distributionRotating; } else { return $this->createDistributionRotating($distribution, $rotatingProduct); } } }