id === null) { throw new BadRequestException('id is required'); } if ($request->iconImageUrl === null) { throw new BadRequestException('iconImageUrl is required'); } $element = $this->elementRepository->find($request->id); if ($element === null) { throw new NotFoundException('Element not found'); } $iconImageUrl = $this->nullableString($request->iconImageUrl); if ($iconImageUrl === null) { $this->deleteManagedFile($element->getIconImageUrl()); } $element->setIconImageUrl($iconImageUrl); return $this->elementRepository->update($element); } private function nullableString(string $value): ?string { if ($value === '') { return null; } return $value; } private function deleteManagedFile(?string $path): void { if ($path === null) { return; } $this->fileUploader->delete($path); } }