id === null) { throw new BadRequestException('id is required'); } if ($request->shortPdfPath === null) { throw new BadRequestException('shortPdfPath is required'); } $element = $this->elementRepository->find($request->id); if ($element === null) { throw new NotFoundException('Element not found'); } $shortPdfPath = $this->nullableString($request->shortPdfPath); if ($shortPdfPath === null) { $this->deleteManagedFile($element->getShortPdfPath()); } $element->setShortPdfPath($shortPdfPath); 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->filesystem->delete($path); } }