classes[$ai] = $class; } } public function getClassForValue(int $value): string { return array_key_exists($value, $this->classes) ? $this->classes[$value] : GenericObject::class; } public function createObjectForValue(int $value, ?string $data): OtherObject { /** @var OtherObject $class */ $class = $this->getClassForValue($value); return $class::createFromLoadedData($value, $data); } }