id === null) { throw new BadRequestException('id is required'); } if ($request->youtubeUrl === null) { throw new BadRequestException('youtubeUrl is required'); } $element = $this->elementRepository->find($request->id); if ($element === null) { throw new NotFoundException('Element not found'); } $element->setYoutubeUrl($this->nullableString( $request->youtubeUrl, )); return $this->elementRepository->update($element); } private function nullableString(string $value): ?string { if ($value === '') { return null; } return $value; } }