. * * To disable strict typing, comment out the directive below. */ declare(strict_types=1); class Allergies { /** * @var \Allergen[] */ private array $allergies = []; public function __construct(int $score) { $score &= Allergen::CATS * 2 - 1; $id = Allergen::EGGS; while ($id <= Allergen::CATS) { if ($id & $score) { $this->allergies[] = new Allergen($id); } $id <<= 1; } } public function isAllergicTo(Allergen $allergen): bool { return in_array($allergen, $this->allergies); } /** * @return \Allergen[] */ public function getList(): array { return $this->allergies; } } class Allergen { public const EGGS = 1; public const PEANUTS = 2; public const SHELLFISH = 4; public const STRAWBERRIES = 8; public const TOMATOES = 16; public const CHOCOLATE = 32; public const POLLEN = 64; public const CATS = 128; private int $id; public function __construct(int $id) { $this->id = $id; } public static function allergenList(): array { return []; } public function getScore(): int { return $this->id; } }