diff --git a/phpstan.neon b/phpstan.neon index bb2a47f4b..895903226 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,6 +25,7 @@ parameters: - %currentWorkingDirectory%/src/Bundle/Tests/* - %currentWorkingDirectory%/src/Component/legacy/spec/* - %currentWorkingDirectory%/src/Component/legacy/src/Annotation/* + - %currentWorkingDirectory%/src/Component/legacy/src/Exception/* - %currentWorkingDirectory%/src/Component/legacy/src/Factory/* - %currentWorkingDirectory%/src/Component/legacy/src/Generator/* - %currentWorkingDirectory%/src/Component/legacy/src/Metadata/* diff --git a/psalm.xml b/psalm.xml index 6ca0ec4b0..197af7240 100644 --- a/psalm.xml +++ b/psalm.xml @@ -227,6 +227,7 @@ + diff --git a/src/Bundle/Controller/ResourceController.php b/src/Bundle/Controller/ResourceController.php index 268fed837..e672f1eb2 100644 --- a/src/Bundle/Controller/ResourceController.php +++ b/src/Bundle/Controller/ResourceController.php @@ -16,9 +16,9 @@ use Doctrine\Persistence\ObjectManager; use FOS\RestBundle\View\View; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; -use Sylius\Component\Resource\Exception\DeleteHandlingException; -use Sylius\Component\Resource\Exception\UpdateHandlingException; use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; +use Sylius\Resource\Exception\DeleteHandlingException; +use Sylius\Resource\Exception\UpdateHandlingException; use Sylius\Resource\Factory\FactoryInterface; use Sylius\Resource\Metadata\MetadataInterface; use Sylius\Resource\Model\ResourceInterface; diff --git a/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php b/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php index 5b23dda12..e292c96ea 100644 --- a/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php +++ b/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php @@ -13,7 +13,7 @@ namespace Sylius\Bundle\ResourceBundle\Form\EventSubscriber; -use Sylius\Component\Resource\Exception\UnexpectedTypeException; +use Sylius\Resource\Exception\UnexpectedTypeException; use Sylius\Resource\Model\CodeAwareInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\Extension\Core\Type\TextType; diff --git a/src/Bundle/spec/Controller/ResourceControllerSpec.php b/src/Bundle/spec/Controller/ResourceControllerSpec.php index 702051644..4daf97dcc 100644 --- a/src/Bundle/spec/Controller/ResourceControllerSpec.php +++ b/src/Bundle/spec/Controller/ResourceControllerSpec.php @@ -33,8 +33,8 @@ use Sylius\Bundle\ResourceBundle\Controller\StateMachineInterface; use Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; -use Sylius\Component\Resource\Exception\DeleteHandlingException; use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; +use Sylius\Resource\Exception\DeleteHandlingException; use Sylius\Resource\Factory\FactoryInterface; use Sylius\Resource\Metadata\MetadataInterface; use Sylius\Resource\Model\ResourceInterface; diff --git a/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php b/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php index 7f79c3907..056469703 100644 --- a/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php +++ b/src/Bundle/spec/Form/EventSubscriber/AddCodeFormSubscriberSpec.php @@ -15,7 +15,7 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; -use Sylius\Component\Resource\Exception\UnexpectedTypeException; +use Sylius\Resource\Exception\UnexpectedTypeException; use Sylius\Resource\Model\CodeAwareInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\Extension\Core\Type\FormType; diff --git a/src/Component/legacy/spec/Exception/DeleteHandlingExceptionSpec.php b/src/Component/legacy/spec/Exception/DeleteHandlingExceptionSpec.php index d0d45e6d8..53a315d48 100644 --- a/src/Component/legacy/spec/Exception/DeleteHandlingExceptionSpec.php +++ b/src/Component/legacy/spec/Exception/DeleteHandlingExceptionSpec.php @@ -14,26 +14,12 @@ namespace spec\Sylius\Component\Resource\Exception; use PhpSpec\ObjectBehavior; +use Sylius\Resource\Exception\DeleteHandlingException as NewDeleteHandlingException; final class DeleteHandlingExceptionSpec extends ObjectBehavior { - function it_extends_an_exception(): void + function it_should_be_an_alias_of_delete_handling_exception(): void { - $this->shouldHaveType(\Exception::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('Ups, something went wrong during deleting a resource, please try again.'); - } - - function it_has_a_flash(): void - { - $this->getFlash()->shouldReturn('something_went_wrong_error'); - } - - function it_has_an_api_response_code(): void - { - $this->getApiResponseCode()->shouldReturn(500); + $this->shouldBeAnInstanceOf(NewDeleteHandlingException::class); } } diff --git a/src/Component/legacy/spec/Exception/RaceConditionExceptionSpec.php b/src/Component/legacy/spec/Exception/RaceConditionExceptionSpec.php index 1db77e079..bfe27b644 100644 --- a/src/Component/legacy/spec/Exception/RaceConditionExceptionSpec.php +++ b/src/Component/legacy/spec/Exception/RaceConditionExceptionSpec.php @@ -14,27 +14,12 @@ namespace spec\Sylius\Component\Resource\Exception; use PhpSpec\ObjectBehavior; -use Sylius\Component\Resource\Exception\UpdateHandlingException; +use Sylius\Resource\Exception\RaceConditionException as NewRaceConditionException; final class RaceConditionExceptionSpec extends ObjectBehavior { - function it_extends_an_update_handling_exception(): void + function it_should_be_an_alias_of_race_condition_exception(): void { - $this->shouldHaveType(UpdateHandlingException::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('Operated entity was previously modified.'); - } - - function it_has_a_flash(): void - { - $this->getFlash()->shouldReturn('race_condition_error'); - } - - function it_has_an_api_response_code(): void - { - $this->getApiResponseCode()->shouldReturn(409); + $this->shouldBeAnInstanceOf(NewRaceConditionException::class); } } diff --git a/src/Component/legacy/spec/Exception/UnexpectedTypeExceptionSpec.php b/src/Component/legacy/spec/Exception/UnexpectedTypeExceptionSpec.php index 71b7b66ad..2de922a9e 100644 --- a/src/Component/legacy/spec/Exception/UnexpectedTypeExceptionSpec.php +++ b/src/Component/legacy/spec/Exception/UnexpectedTypeExceptionSpec.php @@ -14,6 +14,7 @@ namespace spec\Sylius\Component\Resource\Exception; use PhpSpec\ObjectBehavior; +use Sylius\Resource\Exception\UnexpectedTypeException as NewUnexpectedTypeException; final class UnexpectedTypeExceptionSpec extends ObjectBehavior { @@ -22,13 +23,8 @@ function let(): void $this->beConstructedWith('stringValue', '\ExpectedType'); } - function it_extends_invalid_argument_exception(): void + function it_should_be_an_alias_of_unexpected_type_exception(): void { - $this->shouldHaveType(\InvalidArgumentException::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('Expected argument of type "\ExpectedType", "string" given.'); + $this->shouldBeAnInstanceOf(NewUnexpectedTypeException::class); } } diff --git a/src/Component/legacy/spec/Exception/UnsupportedMethodExceptionSpec.php b/src/Component/legacy/spec/Exception/UnsupportedMethodExceptionSpec.php index bc4960c4f..41675fe1c 100644 --- a/src/Component/legacy/spec/Exception/UnsupportedMethodExceptionSpec.php +++ b/src/Component/legacy/spec/Exception/UnsupportedMethodExceptionSpec.php @@ -14,6 +14,7 @@ namespace spec\Sylius\Component\Resource\Exception; use PhpSpec\ObjectBehavior; +use Sylius\Resource\Exception\UnsupportedMethodException as NewUnsupportedMethodException; final class UnsupportedMethodExceptionSpec extends ObjectBehavior { @@ -22,13 +23,8 @@ function let(): void $this->beConstructedWith('methodName'); } - function it_extends_exception(): void + function it_should_be_an_alias_of_unsupported_method_exception(): void { - $this->shouldHaveType(\Exception::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('The method "methodName" is not supported.'); + $this->shouldBeAnInstanceOf(NewUnsupportedMethodException::class); } } diff --git a/src/Component/legacy/spec/Exception/UpdateHandlingExceptionSpec.php b/src/Component/legacy/spec/Exception/UpdateHandlingExceptionSpec.php index 364d1a486..c31865f60 100644 --- a/src/Component/legacy/spec/Exception/UpdateHandlingExceptionSpec.php +++ b/src/Component/legacy/spec/Exception/UpdateHandlingExceptionSpec.php @@ -14,26 +14,12 @@ namespace spec\Sylius\Component\Resource\Exception; use PhpSpec\ObjectBehavior; +use Sylius\Resource\Exception\UpdateHandlingException as NewUpdateHandlingException; final class UpdateHandlingExceptionSpec extends ObjectBehavior { - function it_extends_an_exception(): void + function it_should_be_an_alias_of_unsupported_method_exception(): void { - $this->shouldHaveType(\Exception::class); - } - - function it_has_a_message(): void - { - $this->getMessage()->shouldReturn('Ups, something went wrong during updating a resource, please try again.'); - } - - function it_has_a_flash(): void - { - $this->getFlash()->shouldReturn('something_went_wrong_error'); - } - - function it_has_an_api_response_code(): void - { - $this->getApiResponseCode()->shouldReturn(400); + $this->shouldBeAnInstanceOf(NewUpdateHandlingException::class); } } diff --git a/src/Component/legacy/src/Exception/DeleteHandlingException.php b/src/Component/legacy/src/Exception/DeleteHandlingException.php index aa1a3e123..4dbddc423 100644 --- a/src/Component/legacy/src/Exception/DeleteHandlingException.php +++ b/src/Component/legacy/src/Exception/DeleteHandlingException.php @@ -13,32 +13,10 @@ namespace Sylius\Component\Resource\Exception; -class DeleteHandlingException extends \Exception -{ - protected string $flash; +class_exists(\Sylius\Resource\Exception\DeleteHandlingException::class); - protected int $apiResponseCode; - - public function __construct( - string $message = 'Ups, something went wrong during deleting a resource, please try again.', - string $flash = 'something_went_wrong_error', - int $apiResponseCode = 500, - int $code = 0, - ?\Exception $previous = null, - ) { - parent::__construct($message, $code, $previous); - - $this->flash = $flash; - $this->apiResponseCode = $apiResponseCode; - } - - public function getFlash(): string - { - return $this->flash; - } - - public function getApiResponseCode(): int +if (false) { + class DeleteHandlingException extends \Sylius\Resource\Exception\DeleteHandlingException { - return $this->apiResponseCode; } } diff --git a/src/Component/legacy/src/Exception/RaceConditionException.php b/src/Component/legacy/src/Exception/RaceConditionException.php index b232dc2de..4d4357ee3 100644 --- a/src/Component/legacy/src/Exception/RaceConditionException.php +++ b/src/Component/legacy/src/Exception/RaceConditionException.php @@ -13,16 +13,10 @@ namespace Sylius\Component\Resource\Exception; -class RaceConditionException extends UpdateHandlingException -{ - public function __construct(?\Exception $previous = null) +class_exists(\Sylius\Resource\Exception\RaceConditionException::class); + +if (false) { + class RaceConditionException extends \Sylius\Resource\Exception\RaceConditionException { - parent::__construct( - 'Operated entity was previously modified.', - 'race_condition_error', - 409, - null !== $previous ? (int) $previous->getCode() : 0, - $previous, - ); } } diff --git a/src/Component/legacy/src/Exception/UnexpectedTypeException.php b/src/Component/legacy/src/Exception/UnexpectedTypeException.php index 546837f0a..bb174796e 100644 --- a/src/Component/legacy/src/Exception/UnexpectedTypeException.php +++ b/src/Component/legacy/src/Exception/UnexpectedTypeException.php @@ -13,17 +13,10 @@ namespace Sylius\Component\Resource\Exception; -class UnexpectedTypeException extends \InvalidArgumentException -{ - /** - * @param mixed $value - */ - public function __construct($value, string $expectedType) +class_exists(\Sylius\Resource\Exception\UnexpectedTypeException::class); + +if (false) { + class UnexpectedTypeException extends \Sylius\Resource\Exception\UnexpectedTypeException { - parent::__construct(sprintf( - 'Expected argument of type "%s", "%s" given.', - $expectedType, - is_object($value) ? get_class($value) : gettype($value), - )); } } diff --git a/src/Component/legacy/src/Exception/UnsupportedMethodException.php b/src/Component/legacy/src/Exception/UnsupportedMethodException.php index cb3f4f926..76b257b06 100644 --- a/src/Component/legacy/src/Exception/UnsupportedMethodException.php +++ b/src/Component/legacy/src/Exception/UnsupportedMethodException.php @@ -13,13 +13,10 @@ namespace Sylius\Component\Resource\Exception; -class UnsupportedMethodException extends \Exception -{ - public function __construct(string $methodName) +class_exists(\Sylius\Resource\Exception\UnsupportedMethodException::class); + +if (false) { + class UnsupportedMethodException extends \Sylius\Resource\Exception\UnsupportedMethodException { - parent::__construct(sprintf( - 'The method "%s" is not supported.', - $methodName, - )); } } diff --git a/src/Component/legacy/src/Exception/UpdateHandlingException.php b/src/Component/legacy/src/Exception/UpdateHandlingException.php index e6aac90dc..a4102472e 100644 --- a/src/Component/legacy/src/Exception/UpdateHandlingException.php +++ b/src/Component/legacy/src/Exception/UpdateHandlingException.php @@ -13,32 +13,10 @@ namespace Sylius\Component\Resource\Exception; -class UpdateHandlingException extends \Exception -{ - protected string $flash; +class_exists(\Sylius\Resource\Exception\UpdateHandlingException::class); - protected int $apiResponseCode; - - public function __construct( - string $message = 'Ups, something went wrong during updating a resource, please try again.', - string $flash = 'something_went_wrong_error', - int $apiResponseCode = 400, - int $code = 0, - ?\Exception $previous = null, - ) { - parent::__construct($message, $code, $previous); - - $this->flash = $flash; - $this->apiResponseCode = $apiResponseCode; - } - - public function getFlash(): string - { - return $this->flash; - } - - public function getApiResponseCode(): int +if (false) { + class UpdateHandlingException extends \Sylius\Resource\Exception\UpdateHandlingException { - return $this->apiResponseCode; } } diff --git a/src/Component/legacy/src/Exception/VariantWithNoOptionsValuesException.php b/src/Component/legacy/src/Exception/VariantWithNoOptionsValuesException.php index 9c128c68b..0739f93c6 100644 --- a/src/Component/legacy/src/Exception/VariantWithNoOptionsValuesException.php +++ b/src/Component/legacy/src/Exception/VariantWithNoOptionsValuesException.php @@ -13,10 +13,10 @@ namespace Sylius\Component\Resource\Exception; -final class VariantWithNoOptionsValuesException extends \Exception -{ - public function __construct() +class_exists(\Sylius\Resource\Exception\VariantWithNoOptionsValuesException::class); + +if (false) { + final class VariantWithNoOptionsValuesException extends \Sylius\Resource\Exception\VariantWithNoOptionsValuesException { - parent::__construct('sylius.product_variant.cannot_generate_variants'); } } diff --git a/src/Component/spec/Doctrine/Persistence/InMemoryRepositorySpec.php b/src/Component/spec/Doctrine/Persistence/InMemoryRepositorySpec.php index b4297ba8e..23b7e9816 100644 --- a/src/Component/spec/Doctrine/Persistence/InMemoryRepositorySpec.php +++ b/src/Component/spec/Doctrine/Persistence/InMemoryRepositorySpec.php @@ -16,9 +16,9 @@ use Pagerfanta\Pagerfanta; use PhpSpec\ObjectBehavior; use spec\Sylius\Component\Resource\Fixtures\SampleBookResourceInterface; -use Sylius\Component\Resource\Exception\UnexpectedTypeException; use Sylius\Resource\Doctrine\Persistence\Exception\ResourceExistsException; use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; +use Sylius\Resource\Exception\UnexpectedTypeException; use Sylius\Resource\Model\ResourceInterface; require_once dirname(__DIR__, 3) . '/legacy/spec/Fixtures/SampleBookResourceInterface.php'; diff --git a/src/Component/spec/Exception/RaceConditionExceptionSpec.php b/src/Component/spec/Exception/RaceConditionExceptionSpec.php new file mode 100644 index 000000000..95cd8d7ea --- /dev/null +++ b/src/Component/spec/Exception/RaceConditionExceptionSpec.php @@ -0,0 +1,40 @@ +shouldHaveType(UpdateHandlingException::class); + } + + function it_has_a_message(): void + { + $this->getMessage()->shouldReturn('Operated entity was previously modified.'); + } + + function it_has_a_flash(): void + { + $this->getFlash()->shouldReturn('race_condition_error'); + } + + function it_has_an_api_response_code(): void + { + $this->getApiResponseCode()->shouldReturn(409); + } +} diff --git a/src/Component/src/Exception/DeleteHandlingException.php b/src/Component/src/Exception/DeleteHandlingException.php new file mode 100644 index 000000000..794e67181 --- /dev/null +++ b/src/Component/src/Exception/DeleteHandlingException.php @@ -0,0 +1,46 @@ +flash = $flash; + $this->apiResponseCode = $apiResponseCode; + } + + public function getFlash(): string + { + return $this->flash; + } + + public function getApiResponseCode(): int + { + return $this->apiResponseCode; + } +} + +class_alias(DeleteHandlingException::class, \Sylius\Component\Resource\Exception\DeleteHandlingException::class); diff --git a/src/Component/src/Exception/Exception.php b/src/Component/src/Exception/Exception.php new file mode 100644 index 000000000..077fb49b1 --- /dev/null +++ b/src/Component/src/Exception/Exception.php @@ -0,0 +1,18 @@ +getCode() : 0, + $previous, + ); + } +} + +class_alias(RaceConditionException::class, \Sylius\Component\Resource\Exception\RaceConditionException::class); diff --git a/src/Component/src/Exception/UnexpectedTypeException.php b/src/Component/src/Exception/UnexpectedTypeException.php new file mode 100644 index 000000000..0422b9644 --- /dev/null +++ b/src/Component/src/Exception/UnexpectedTypeException.php @@ -0,0 +1,31 @@ +flash = $flash; + $this->apiResponseCode = $apiResponseCode; + } + + public function getFlash(): string + { + return $this->flash; + } + + public function getApiResponseCode(): int + { + return $this->apiResponseCode; + } +} + +class_alias(UpdateHandlingException::class, \Sylius\Component\Resource\Exception\UpdateHandlingException::class); diff --git a/src/Component/src/Exception/VariantWithNoOptionsValuesException.php b/src/Component/src/Exception/VariantWithNoOptionsValuesException.php new file mode 100644 index 000000000..6b8f32acc --- /dev/null +++ b/src/Component/src/Exception/VariantWithNoOptionsValuesException.php @@ -0,0 +1,24 @@ +