. */ declare(strict_types=1); namespace App\Services\EntityMergers\Mergers; use App\Entity\Parts\Part; use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; #[Autoconfigure(public: true)] class PartMerger implements EntityMergerInterface { use EntityMergerHelperTrait; public function supports(object $target, object $other, array $context = []): bool { return $target instanceof Part && $other instanceof Part; } public function merge(object $target, object $other, array $context = []): Part { if (!$target instanceof Part || !$other instanceof Part) { throw new \InvalidArgumentException('The target and the other entity must be instances of Part'); } //Merge the fields $this->useOtherValueIfNotNull($target, $other, 'manufacturer'); $this->mergeCollections($target, $other, 'partLots'); $this->mergeCollections($target, $other, 'attachments'); $this->mergeCollections($target, $other, 'orderdetails'); $this->mergeCollections($target, $other, 'parameters'); return $target; } }