<?phpnamespace App\Entity;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;use Symfony\Component\Validator\Context\ExecutionContextInterface;/** * @ORM\Entity */class CompanyDocumentAddress extends CompanyAddress{ /** * @param string $name */ public function __construct(string $name) { parent::__construct($name); } public function __clone() { $this->id = null; } /** * @return Company|null */ public function getCompany(): ?Company { return null; } /** * @return string */ public function getType(): string { return 'document'; } /** * @param AddressInterface $address * * @return CompanyDocumentAddress */ public static function create(AddressInterface $address): CompanyDocumentAddress { $obj = new self($address->getName()); $obj->populate($address); return $obj; } /** * @param bool $includeVat * * @return bool */ public function isEmpty(bool $includeVat = true): bool { $name = trim($this->name); if (empty($name)) { $name = null; } return null === $name && null === $this->contactPersonName && null === $this->contactPersonEmail && null === $this->addressRow1 && null === $this->addressRow2 && null === $this->addressRow3 && null === $this->addressRow4 && null === $this->postalCode && null === $this->city && null === $this->country && (!$includeVat || null === $this->vatId); } /** * @param AddressInterface $address */ public function populate(AddressInterface $address): void { $this->setName($address->getName()); $this->setContactPersonName($address->getContactPersonName()); $this->setContactPersonEmail($address->getContactPersonEmail()); $this->setAddressRow1($address->getAddressRow1()); $this->setAddressRow2($address->getAddressRow2()); $this->setAddressRow3($address->getAddressRow3()); $this->setAddressRow4($address->getAddressRow4()); $this->setPostalCode($address->getPostalCode()); $this->setCity($address->getCity()); $this->setCountry($address->getCountry()); $this->setVatId($address->getVatId()); } /** * @Assert\Callback(groups={"Offer"}) */ public function validate(ExecutionContextInterface $context): void { $name = trim($this->name); if (empty($name)) { $name = null; } if (!$this->isEmpty() && empty($name)) { $context->buildViolation('validation.name.empty') ->setTranslationDomain('CompanyAddress') ->atPath('name') ->addViolation(); } }}