id === null) { throw new BadRequestException('setId is required'); } if ($this->hasNoFields($request)) { throw new BadRequestException('nothing to update'); } if ($request->name !== null) { $this->updateName->execute(new UpdateNameRequest( id: $request->id, name: $request->name, )); } if ($request->description !== null) { $this->updateDescription->execute(new UpdateDescriptionRequest( id: $request->id, description: $request->description, )); } if ($this->hasIconImageInput($request)) { $this->updateIconImage->execute(new UpdateIconImageRequest( id: $request->id, fileContents: $request->iconImageContents, fileOriginalName: $request->iconImageOriginalName, fileMimeType: $request->iconImageMimeType, fileSizeBytes: $request->iconImageSizeBytes, )); } $set = $this->setRepository->find($request->id); if ($set === null) { throw new NotFoundException('Set not found'); } return $set; } private function hasNoFields(UpdateSetRequest $request): bool { return $request->name === null && $request->description === null && ! $this->hasIconImageInput($request); } private function hasIconImageInput(UpdateSetRequest $request): bool { return $request->iconImageContents !== null || $request->iconImageOriginalName !== null || $request->iconImageMimeType !== null || $request->iconImageSizeBytes !== null; } }