Skip to content

Commit

Permalink
Merge branch 'next-27122/introduce-new-domainexceptions' into 'trunk'
Browse files Browse the repository at this point in the history
NEXT-27122 - Introduce new DomainExceptions

See merge request shopware/6/product/platform!10803
  • Loading branch information
mstegmeyer committed May 26, 2023
2 parents 617979c + 8b009bc commit 0d12bb2
Show file tree
Hide file tree
Showing 115 changed files with 490 additions and 528 deletions.
12 changes: 12 additions & 0 deletions changelog/_unreleased/2023-05-24-introduce-new-domainexceptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Introduce new DomainExceptions
issue: NEXT-27122
author: Max Stegmeyer
author_email: m.stegmeyer@shopware.com
---

# Core
* Deprecated the following exceptions in replacement for Domain Exceptions
* `Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException`
* `Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException`
* `Shopware\Core\Framework\DataAbstractionLayer\Exception\InvalidSerializerFieldException`
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9389,16 +9389,6 @@ parameters:
count: 1
path: src/Core/Framework/DataAbstractionLayer/FieldSerializer/BlobFieldSerializer.php

-
message: "#^Anonymous variable in a `\\$value\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 2
path: src/Core/Framework/DataAbstractionLayer/FieldSerializer/DateFieldSerializer.php

-
message: "#^Anonymous variable in a `\\$value\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 2
path: src/Core/Framework/DataAbstractionLayer/FieldSerializer/DateTimeFieldSerializer.php

-
message: "#^Method Shopware\\\\Core\\\\Framework\\\\DataAbstractionLayer\\\\FieldSerializer\\\\FieldSerializerInterface\\:\\:normalize\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
301 changes: 80 additions & 221 deletions phpstan-v66-baseline.neon

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Administration/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\Framework\Feature;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\Exception\LanguageNotFoundException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Framework\Store\Services\FirstRunWizardService;
use Shopware\Core\Framework\Util\HtmlSanitizer;
use Shopware\Core\Framework\Uuid\Uuid;
Expand Down Expand Up @@ -185,7 +185,7 @@ public function checkCustomerEmailValid(Request $request, Context $context): Jso
if ($isCustomerBoundSalesChannel) {
$boundSalesChannelId = $request->request->get('boundSalesChannelId');
if ($boundSalesChannelId !== null && !\is_string($boundSalesChannelId)) {
throw new InvalidRequestParameterException('boundSalesChannelId');
throw RoutingException::invalidRequestParameter('boundSalesChannelId');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Shopware\Core\Checkout\Cart\SalesChannel\CartResponse;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Framework\Rule\Rule;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -63,11 +63,11 @@ public function addCreditItemToOrder(string $orderId, Request $request, Context
$priceDefinition = $request->request->all('priceDefinition');

if ($label !== null && !\is_string($label)) {
throw new InvalidRequestParameterException('label');
throw RoutingException::invalidRequestParameter('label');
}

if ($description !== null && !\is_string($description)) {
throw new InvalidRequestParameterException('description');
throw RoutingException::invalidRequestParameter('description');
}

$lineItem->setLabel($label);
Expand Down Expand Up @@ -146,11 +146,11 @@ private function updateLineItemByRequest(Request $request, LineItem $lineItem):
$priceDefinition = $request->request->all('priceDefinition');

if ($label !== null && !\is_string($label)) {
throw new InvalidRequestParameterException('label');
throw RoutingException::invalidRequestParameter('label');
}

if ($description !== null && !\is_string($description)) {
throw new InvalidRequestParameterException('description');
throw RoutingException::invalidRequestParameter('description');
}

$lineItem->setLabel($label);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Checkout/Customer/SalesChannel/DownloadRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function load(Request $request, SalesChannelContext $context): Response
}

if ($downloadId === false || $orderId === false) {
throw new MissingRequestParameterException(!$downloadId ? 'downloadId' : 'orderId');
throw RoutingException::missingRequestParameter(!$downloadId ? 'downloadId' : 'orderId');
}

$criteria = new Criteria([$downloadId]);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Checkout/Document/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Shopware\Core\Checkout\Document\Struct\DocumentGenerateOperation;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function downloadDocuments(Request $request, Context $context): Response
$documentIds = $request->get('documentIds', []);

if (!\is_array($documentIds) || empty($documentIds)) {
throw new InvalidRequestParameterException('documentIds');
throw RoutingException::invalidRequestParameter('documentIds');
}

$download = $request->query->getBoolean('download', true);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Checkout/Document/DocumentGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Shopware\Core\Checkout\Document\Struct\DocumentGenerateOperation;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Framework\Validation\Constraint\Uuid;
use Shopware\Core\Framework\Validation\DataValidationDefinition;
use Shopware\Core\Framework\Validation\DataValidator;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function createDocuments(Request $request, string $documentTypeName, Cont
$documents = $this->serializer->decode($request->getContent(), 'json');

if (empty($documents) || !\is_array($documents)) {
throw new InvalidRequestParameterException('Request parameters must be an array of documents object');
throw RoutingException::invalidRequestParameter('Request parameters must be an array of documents object');
}

$operations = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Checkout/Order/SalesChannel/CancelOrderRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -39,7 +39,7 @@ public function cancel(Request $request, SalesChannelContext $context): CancelOr
$orderId = $request->get('orderId', null);

if ($orderId === null) {
throw new InvalidRequestParameterException('orderId');
throw RoutingException::invalidRequestParameter('orderId');
}

$this->verify($orderId, $context);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Checkout/Payment/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Framework\ShopwareException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function finalizeTransaction(Request $request): Response
$paymentToken = $request->get('_sw_payment_token');

if ($paymentToken === null) {
throw new MissingRequestParameterException('_sw_payment_token');
throw RoutingException::missingRequestParameter('_sw_payment_token');
}

$salesChannelContext = $this->assembleSalesChannelContext($paymentToken);
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Checkout/Promotion/Api/PromotionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Shopware\Core\Checkout\Promotion\Util\PromotionCodeService;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -34,7 +34,7 @@ public function generateIndividualCodes(Request $request): Response
{
$codePattern = (string) $request->query->get('codePattern');
if ($codePattern === '') {
throw new MissingRequestParameterException('codePattern');
throw RoutingException::missingRequestParameter('codePattern');
}
$amount = $request->query->getInt('amount');

Expand Down Expand Up @@ -69,7 +69,7 @@ public function getCodePreview(Request $request): Response
{
$codePattern = (string) $request->query->get('codePattern');
if ($codePattern === '') {
throw new MissingRequestParameterException('codePattern');
throw RoutingException::missingRequestParameter('codePattern');
}

return new JsonResponse($this->codeService->getPreview($codePattern));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Shopware\Core\Content\Flow\DataAbstractionLayer\FieldSerializer;

use Shopware\Core\Content\Flow\DataAbstractionLayer\Field\FlowTemplateConfigField;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InvalidSerializerFieldException;
use Shopware\Core\Framework\DataAbstractionLayer\DataAbstractionLayerException;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Field;
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\JsonFieldSerializer;
use Shopware\Core\Framework\DataAbstractionLayer\Write\DataStack\KeyValuePair;
Expand All @@ -30,7 +30,7 @@ public function encode(
WriteParameterBag $parameters
): \Generator {
if (!$field instanceof FlowTemplateConfigField) {
throw new InvalidSerializerFieldException(FlowTemplateConfigField::class, $field);
throw DataAbstractionLayerException::invalidSerializerField(FlowTemplateConfigField::class, $field);
}

$this->validateIfNeeded($field, $existence, $data, $parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Framework\Validation\DataValidationDefinition;
use Shopware\Core\Framework\Validation\DataValidator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -146,7 +146,7 @@ public function cancel(Request $request, Context $context): Response
$logId = $request->request->get('logId');

if (!\is_string($logId)) {
throw new InvalidRequestParameterException('logId');
throw RoutingException::invalidRequestParameter('logId');
}

$this->importExportService->cancel($context, $logId);
Expand All @@ -160,7 +160,7 @@ public function prepareTemplateFileDownload(Request $request, Context $context):
{
$profileId = $request->query->get('profileId');
if (!\is_string($profileId)) {
throw new InvalidRequestParameterException('profileId');
throw RoutingException::invalidRequestParameter('profileId');
}
$profileId = strtolower($profileId);

Expand All @@ -183,11 +183,11 @@ public function mappingFromTemplate(Request $request, Context $context): JsonRes
$enclosure = (string) $request->request->get('enclosure', '"');

if ($file === null || !$file->isValid()) {
throw new InvalidRequestParameterException('file');
throw RoutingException::invalidRequestParameter('file');
}

if (!\is_string($sourceEntity)) {
throw new InvalidRequestParameterException('sourceEntity');
throw RoutingException::invalidRequestParameter('sourceEntity');
}

$mapping = $this->mappingService->getMappingFromTemplate($context, $file, $sourceEntity, $delimiter, $enclosure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -41,7 +41,7 @@ public function getDecorated(): AbstractProductSearchRoute
public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSearchRouteResponse
{
if (!$request->get('search')) {
throw new MissingRequestParameterException('search');
throw RoutingException::missingRequestParameter('search');
}

$criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function getDecorated(): AbstractProductSuggestRoute
public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSuggestRouteResponse
{
if (!$request->get('search')) {
throw new MissingRequestParameterException('search');
throw RoutingException::missingRequestParameter('search');
}

$criteria->addFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Query\ScoreQuery;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Term\SearchPattern;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -36,7 +36,7 @@ public function build(Request $request, Criteria $criteria, SalesChannelContext

$term = trim($term);
if (empty($term)) {
throw new MissingRequestParameterException('search');
throw RoutingException::missingRequestParameter('search');
}

$pattern = $this->interpreter->interpret($term, $context->getContext());
Expand Down
11 changes: 5 additions & 6 deletions src/Core/Content/Seo/Api/SeoActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\RequestCriteriaBuilder;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\Framework\Validation\DataValidator;
use Shopware\Core\System\SalesChannel\SalesChannelCollection;
Expand Down Expand Up @@ -144,14 +143,14 @@ public function updateCanonicalUrl(RequestDataBag $seoUrl, Context $context): Re
$salesChannelId = $seoUrlData['salesChannelId'] ?? null;

if ($salesChannelId === null) {
throw new MissingRequestParameterException('salesChannelId');
throw RoutingException::missingRequestParameter('salesChannelId');
}

/** @var SalesChannelEntity|null $salesChannel */
$salesChannel = $this->salesChannelRepository->search(new Criteria([$salesChannelId]), $context)->first();

if ($salesChannel === null) {
throw new InvalidRequestParameterException('salesChannelId');
throw RoutingException::invalidRequestParameter('salesChannelId');
}

$this->seoUrlPersister->updateSeoUrls(
Expand Down Expand Up @@ -197,7 +196,7 @@ public function createCustomSeoUrls(RequestDataBag $dataBag, Context $context):
$salesChannelEntity = null;

if ($salesChannelId === '') {
throw new InvalidRequestParameterException('salesChannelId');
throw RoutingException::invalidRequestParameter('salesChannelId');
}

/** @var SalesChannelEntity $salesChannelEntity */
Expand Down Expand Up @@ -287,7 +286,7 @@ private function getPreview(array $seoUrlTemplate, Context $context, ?Criteria $
}

if ($salesChannel === null) {
throw new InvalidRequestParameterException('salesChannelId');
throw RoutingException::invalidRequestParameter('salesChannelId');
}

$result = $this->seoUrlGenerator->generate($ids, $template, $seoUrlRoute, $context, $salesChannel);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Framework/Api/Controller/InfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Shopware\Core\Framework\Increment\IncrementGatewayRegistry;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Routing\Exception\InvalidRequestParameterException;
use Shopware\Core\Framework\Routing\RoutingException;
use Shopware\Core\Kernel;
use Shopware\Core\Maintenance\System\Service\AppUrlVerifier;
use Shopware\Core\PlatformRequest;
Expand Down Expand Up @@ -58,7 +58,7 @@ public function info(Request $request): JsonResponse

$apiType = $this->definitionService->toApiType($apiType);
if ($apiType === null) {
throw new InvalidRequestParameterException('type');
throw throw RoutingException::invalidRequestParameter('type');
}

$data = $this->definitionService->generate(OpenApi3Generator::FORMAT, DefinitionService::API, $apiType);
Expand Down
Loading

0 comments on commit 0d12bb2

Please sign in to comment.