Код: Выделить всё
public function __construct(
ID $id,
Name $name,
array $phones,
array $addresses,
array $specializations
) {
Assert::notEmpty($license, 'The company must contain at least one license');
$this->id = $id;
$this->name = $name;
$this->phones = new Phones($phones);
$this->addresses = new Addresses($addresses);
$this->specializations = new Specializations($specializations);
$this->companyRating = $this->getRatingBySpecialization();
}
Код: Выделить всё
public function __construct(array $directions) {
if (!$specializations) {
throw new \DomainException('must contain at least one specialization');
}
foreach ($specializations as $specialization) {
if ($this->getValid($specialization)) {
$this->add($specialization);
}
}
}
public function getValid($specialization): bool {
if (!in_array($specialization->getSpecializationName(), $this->allAvailableSpecialization, true)) {
throw new \DomainException('specialization must be valid');
}
return true;
}
public allAvailableSpecialization = [
'Электрика',
'Монтаж'
...
]