From 531262db5cfd7861785e4b960c84ffdcfb8bd4e0 Mon Sep 17 00:00:00 2001 From: Thilo Lindner Date: Wed, 23 Oct 2024 12:00:02 +0200 Subject: [PATCH] PISHPS-373: Polyfills --- .phpstan.neon | 4 ++- composer.json | 3 +-- composer.lock | 12 ++++----- .../Exception/PaymentProcessException.php | 4 --- .../Checkout/Payment/PaymentException.php | 5 +--- .../Event/BusinessEventInterface.php | 4 --- .../Core/Framework/Event/CustomerAware.php | 4 --- .../Core/Framework/Event/FlowEventAware.php | 4 --- .../Framework/Event/MailActionInterface.php | 4 --- .../Core/Framework/Event/MailAware.php | 4 --- .../Core/Framework/Event/OrderAware.php | 4 --- .../Snippet/Files/AbstractSnippetFile.php | 4 --- .../Snippet/Files/SnippetFileInterface.php | 4 --- src/Compatibility/DependencyLoader.php | 26 ++++++++++++++----- src/MolliePayments.php | 2 +- 15 files changed, 31 insertions(+), 57 deletions(-) diff --git a/.phpstan.neon b/.phpstan.neon index 5587d90e3..72ff805e4 100644 --- a/.phpstan.neon +++ b/.phpstan.neon @@ -19,6 +19,8 @@ parameters: message: 'use some logger instead' - function: 'putenv()' message: 'might overwrite existing variables' + scanDirectories: + - polyfill/Shopware services: - class: MolliePayments\PHPStan\Rules\NoManufacturerRule @@ -26,4 +28,4 @@ services: - phpstan.rules.rule includes: - - vendor/spaze/phpstan-disallowed-calls/extension.neon \ No newline at end of file + - vendor/spaze/phpstan-disallowed-calls/extension.neon diff --git a/composer.json b/composer.json index 325d7fd40..1cb6c092b 100644 --- a/composer.json +++ b/composer.json @@ -43,8 +43,7 @@ "autoload": { "psr-4": { "Kiener\\MolliePayments\\": "src/", - "Mollie\\Api\\": "vendor_manual/mollie/mollie-api-php/src/", - "Shopware\\Core\\": "polyfill/Shopware/Core/" + "Mollie\\Api\\": "vendor_manual/mollie/mollie-api-php/src/" } }, "autoload-dev": { diff --git a/composer.lock b/composer.lock index b1ee09d92..40f7e4cc9 100644 --- a/composer.lock +++ b/composer.lock @@ -62,16 +62,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.324.3", + "version": "3.324.8", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "018a692622175ad65ebefa3f6645e4e6208a11fe" + "reference": "22ac6655d95ac9e068f39364c7756fbc1460ffbb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/018a692622175ad65ebefa3f6645e4e6208a11fe", - "reference": "018a692622175ad65ebefa3f6645e4e6208a11fe", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/22ac6655d95ac9e068f39364c7756fbc1460ffbb", + "reference": "22ac6655d95ac9e068f39364c7756fbc1460ffbb", "shasum": "" }, "require": { @@ -154,9 +154,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.324.3" + "source": "https://github.com/aws/aws-sdk-php/tree/3.324.8" }, - "time": "2024-10-15T18:29:08+00:00" + "time": "2024-10-22T18:32:28+00:00" }, { "name": "brick/math", diff --git a/polyfill/Shopware/Core/Checkout/Payment/Exception/PaymentProcessException.php b/polyfill/Shopware/Core/Checkout/Payment/Exception/PaymentProcessException.php index 7ab271936..eb41badf6 100644 --- a/polyfill/Shopware/Core/Checkout/Payment/Exception/PaymentProcessException.php +++ b/polyfill/Shopware/Core/Checkout/Payment/Exception/PaymentProcessException.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Checkout\Payment\Exception; -if (class_exists(PaymentProcessException::class)) { - return; -} - use Shopware\Core\Framework\Log\Package; use Shopware\Core\Framework\ShopwareHttpException; use Symfony\Component\HttpFoundation\Response; diff --git a/polyfill/Shopware/Core/Checkout/Payment/PaymentException.php b/polyfill/Shopware/Core/Checkout/Payment/PaymentException.php index c5a23c1e6..707f0e75e 100644 --- a/polyfill/Shopware/Core/Checkout/Payment/PaymentException.php +++ b/polyfill/Shopware/Core/Checkout/Payment/PaymentException.php @@ -4,13 +4,10 @@ use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentFinalizeException; use Shopware\Core\Checkout\Payment\Exception\CustomerCanceledAsyncPaymentException; -if (class_exists(PaymentException::class) && !class_exists(AsyncPaymentFinalizeException::class) && !class_exists(CustomerCanceledAsyncPaymentException::class)) { - return; -} - class PaymentException extends \Exception { + public static function asyncFinalizeInterrupted(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): AsyncPaymentFinalizeException { return new AsyncPaymentFinalizeException($orderTransactionId, $errorMessage, $e); diff --git a/polyfill/Shopware/Core/Framework/Event/BusinessEventInterface.php b/polyfill/Shopware/Core/Framework/Event/BusinessEventInterface.php index 3530d5180..1cefafd71 100644 --- a/polyfill/Shopware/Core/Framework/Event/BusinessEventInterface.php +++ b/polyfill/Shopware/Core/Framework/Event/BusinessEventInterface.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Framework\Event; -if (interface_exists(BusinessEventInterface::class)) { - return; -} - use Shopware\Core\Framework\Event\EventData\EventDataCollection; /** diff --git a/polyfill/Shopware/Core/Framework/Event/CustomerAware.php b/polyfill/Shopware/Core/Framework/Event/CustomerAware.php index 3e53177b2..867789d5d 100644 --- a/polyfill/Shopware/Core/Framework/Event/CustomerAware.php +++ b/polyfill/Shopware/Core/Framework/Event/CustomerAware.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Framework\Event; -if (interface_exists(CustomerAware::class)) { - return; -} - interface CustomerAware extends BusinessEventInterface { public const CUSTOMER_ID = 'customerId'; diff --git a/polyfill/Shopware/Core/Framework/Event/FlowEventAware.php b/polyfill/Shopware/Core/Framework/Event/FlowEventAware.php index e95966cdf..7d107db9a 100644 --- a/polyfill/Shopware/Core/Framework/Event/FlowEventAware.php +++ b/polyfill/Shopware/Core/Framework/Event/FlowEventAware.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Framework\Event; -if (interface_exists(FlowEventAware::class)) { - return; -} - use Shopware\Core\Framework\Event\EventData\EventDataCollection; interface FlowEventAware extends ShopwareEvent diff --git a/polyfill/Shopware/Core/Framework/Event/MailActionInterface.php b/polyfill/Shopware/Core/Framework/Event/MailActionInterface.php index 5775b15c1..d41b266ac 100644 --- a/polyfill/Shopware/Core/Framework/Event/MailActionInterface.php +++ b/polyfill/Shopware/Core/Framework/Event/MailActionInterface.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Framework\Event; -if (interface_exists(MailActionInterface::class)) { - return; -} - use Shopware\Core\Framework\Event\EventData\MailRecipientStruct; use Shopware\Core\Framework\Log\Package; diff --git a/polyfill/Shopware/Core/Framework/Event/MailAware.php b/polyfill/Shopware/Core/Framework/Event/MailAware.php index 0b1735d73..b0022523c 100644 --- a/polyfill/Shopware/Core/Framework/Event/MailAware.php +++ b/polyfill/Shopware/Core/Framework/Event/MailAware.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Framework\Event; -if (interface_exists(MailAware::class)) { - return; -} - use Shopware\Core\Framework\Event\EventData\MailRecipientStruct; interface MailAware extends MailActionInterface diff --git a/polyfill/Shopware/Core/Framework/Event/OrderAware.php b/polyfill/Shopware/Core/Framework/Event/OrderAware.php index d16f1ab4f..a9d83ca9d 100644 --- a/polyfill/Shopware/Core/Framework/Event/OrderAware.php +++ b/polyfill/Shopware/Core/Framework/Event/OrderAware.php @@ -2,10 +2,6 @@ namespace Shopware\Core\Framework\Event; -if (interface_exists(OrderAware::class)) { - return; -} - interface OrderAware extends BusinessEventInterface { public const ORDER = 'order'; diff --git a/polyfill/Shopware/Core/System/Snippet/Files/AbstractSnippetFile.php b/polyfill/Shopware/Core/System/Snippet/Files/AbstractSnippetFile.php index 1debdf62a..e23750bb4 100644 --- a/polyfill/Shopware/Core/System/Snippet/Files/AbstractSnippetFile.php +++ b/polyfill/Shopware/Core/System/Snippet/Files/AbstractSnippetFile.php @@ -2,10 +2,6 @@ namespace Shopware\Core\System\Snippet\Files; -if (class_exists(AbstractSnippetFile::class)) { - return; -} - use Shopware\Core\Framework\Log\Package; #[Package('system-settings')] diff --git a/polyfill/Shopware/Core/System/Snippet/Files/SnippetFileInterface.php b/polyfill/Shopware/Core/System/Snippet/Files/SnippetFileInterface.php index 8a63b9ca4..aadd53ea9 100644 --- a/polyfill/Shopware/Core/System/Snippet/Files/SnippetFileInterface.php +++ b/polyfill/Shopware/Core/System/Snippet/Files/SnippetFileInterface.php @@ -2,10 +2,6 @@ namespace Shopware\Core\System\Snippet\Files; -if (interface_exists(SnippetFileInterface::class)) { - return; -} - interface SnippetFileInterface { /** diff --git a/src/Compatibility/DependencyLoader.php b/src/Compatibility/DependencyLoader.php index 215682946..ff799637c 100644 --- a/src/Compatibility/DependencyLoader.php +++ b/src/Compatibility/DependencyLoader.php @@ -56,7 +56,22 @@ public function loadServices(): void } } - public function registerFixturesAutoloader():void + public function registerDependencies(): void + { + $classLoader = new ClassLoader(); + + $this->registerPolyfillsAutoloader($classLoader); + $this->registerFixturesAutoloader($classLoader); + + $classLoader->register(); + } + + private function registerPolyfillsAutoloader(ClassLoader $classLoader): void + { + $classLoader->addPsr4("Shopware\\Core\\", __DIR__ . '/../../polyfill/Shopware/Core', true); + } + + private function registerFixturesAutoloader(ClassLoader $classLoader): void { if ($this->shouldLoadFixtures() === false) { return; @@ -65,17 +80,14 @@ public function registerFixturesAutoloader():void $dirFixtures = (string)realpath(__DIR__ . '/../../tests/Fixtures/'); # we need to tell Shopware to load our custom fixtures # from our TEST autoload-dev area.... - $classLoader = new ClassLoader(); $classLoader->addPsr4("MolliePayments\\Fixtures\\", $dirFixtures, true); - - $classLoader->register(); } - private function shouldLoadFixtures():bool + private function shouldLoadFixtures(): bool { - $composerDevReqsInstalled = file_exists(__DIR__.'/../../vendor/bin/phpunit'); + $composerDevReqsInstalled = file_exists(__DIR__ . '/../../vendor/bin/phpunit'); if ($composerDevReqsInstalled === false) { - return false; + return false; } $dirFixtures = (string)realpath(__DIR__ . '/../../tests/Fixtures/'); return is_dir($dirFixtures); diff --git a/src/MolliePayments.php b/src/MolliePayments.php index e645335cf..c59048676 100644 --- a/src/MolliePayments.php +++ b/src/MolliePayments.php @@ -116,7 +116,7 @@ public function boot(): void # with our current shopware version $loader = new DependencyLoader($container, new VersionCompare($shopwareVersion)); - $loader->registerFixturesAutoloader(); + $loader->registerDependencies(); }