diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 36d3c280..630ba94d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -72,7 +72,7 @@ jobs: - uses: actions/cache@v2 with: path: ~/.composer/cache/files - key: '7.4--' + key: '7.4' - uses: shivammathur/setup-php@v2 with: php-version: '7.4' @@ -86,7 +86,7 @@ jobs: - uses: actions/cache@v2 with: path: ~/.composer/cache/files - key: '7.4--' + key: '7.4' - uses: shivammathur/setup-php@v2 with: php-version: '7.4' diff --git a/composer.json b/composer.json index 0f94637f..054993eb 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,9 @@ "monolog/monolog": "Allow sending log messages to Sentry by using the included Monolog handler." }, "autoload": { + "files": [ + "src/aliases.php" + ], "psr-4": { "Sentry\\SentryBundle\\": "src/" } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 99506a98..14744de8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -30,85 +30,25 @@ parameters: count: 1 path: src/DependencyInjection/SentryExtension.php - - - message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent not found\\.$#" - count: 1 - path: src/EventListener/ErrorListener.php - - message: "#^Else branch is unreachable because previous condition is always true\\.$#" count: 1 path: src/EventListener/ErrorListener.php - - message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent not found\\.$#" - count: 2 - path: src/EventListener/RequestListener.php - - - - message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent not found\\.$#" - count: 2 - path: src/EventListener/RequestListener.php - - - - message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#" - count: 1 - path: src/EventListener/RequestListener.php - - - - message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#" - count: 1 - path: src/EventListener/RequestListener.php - - - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelRequestEvent\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent\\.$#" - count: 2 - path: src/EventListener/RequestListener.php - - - - message: "#^Call to method isMasterRequest\\(\\) on an unknown class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent\\.$#" - count: 1 - path: src/EventListener/RequestListener.php - - - - message: "#^Call to method getRequest\\(\\) on an unknown class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent\\.$#" - count: 1 - path: src/EventListener/RequestListener.php - - - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelControllerEvent\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent\\.$#" - count: 2 - path: src/EventListener/RequestListener.php - - - - message: "#^Call to method isMasterRequest\\(\\) on an unknown class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent\\.$#" - count: 1 - path: src/EventListener/RequestListener.php - - - - message: "#^Call to method getRequest\\(\\) on an unknown class Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent\\.$#" + message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseForExceptionEvent not found\\.$#" count: 1 - path: src/EventListener/RequestListener.php - - - - message: "#^Class Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent not found\\.$#" - count: 2 - path: src/EventListener/SubRequestListener.php + path: src/aliases.php - message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#" - count: 1 - path: src/EventListener/SubRequestListener.php - - - - message: "#^Parameter \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:handleKernelRequestEvent\\(\\) has invalid typehint type Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent\\.$#" count: 2 - path: src/EventListener/SubRequestListener.php + path: src/aliases.php - - message: "#^Call to method isMasterRequest\\(\\) on an unknown class Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent\\.$#" + message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#" count: 1 - path: src/EventListener/SubRequestListener.php + path: src/aliases.php - message: "#^Method Sentry\\\\SentryBundle\\\\Test\\\\DependencyInjection\\\\ConfigurationTest\\:\\:testOptionValuesProcessing\\(\\) has parameter \\$value with no typehint specified\\.$#" @@ -221,7 +161,7 @@ parameters: path: test/End2End/End2EndTest.php - - message: "#^Comparison operation \"\\<\" between 50108 and 40300 is always false\\.$#" + message: "#^Comparison operation \"\\<\" between 50201 and 40300 is always false\\.$#" count: 1 path: test/End2End/End2EndTest.php @@ -271,7 +211,7 @@ parameters: path: test/EventListener/RequestListenerTest.php - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerRequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" + message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" count: 1 path: test/EventListener/RequestListenerTest.php @@ -286,7 +226,7 @@ parameters: path: test/EventListener/RequestListenerTest.php - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelControllerEvent\\(\\) expects Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListenerControllerEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ControllerEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent given\\.$#" + message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\RequestListener\\:\\:handleKernelControllerEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ControllerEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ControllerEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent given\\.$#" count: 1 path: test/EventListener/RequestListenerTest.php @@ -306,7 +246,7 @@ parameters: path: test/EventListener/SubRequestListenerTest.php - - message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListenerRequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" + message: "#^Parameter \\#1 \\$event of method Sentry\\\\SentryBundle\\\\EventListener\\\\SubRequestListener\\:\\:handleKernelRequestEvent\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent, Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent\\|Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\RequestEvent given\\.$#" count: 1 path: test/EventListener/SubRequestListenerTest.php diff --git a/phpunit.xml b/phpunit.xml index 2695c705..6eafa5f5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,6 +20,9 @@ ./src + + ./src/aliases.php + diff --git a/src/EventListener/ErrorListener.php b/src/EventListener/ErrorListener.php index 7b7fed1e..87bf6a93 100644 --- a/src/EventListener/ErrorListener.php +++ b/src/EventListener/ErrorListener.php @@ -4,18 +4,6 @@ use Sentry\State\HubInterface; use Symfony\Component\HttpKernel\Event\ExceptionEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Kernel; - -if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - if (! class_exists(ErrorListenerExceptionEvent::class, false)) { - class_alias(ExceptionEvent::class, ErrorListenerExceptionEvent::class); - } -} else { - if (! class_exists(ErrorListenerExceptionEvent::class, false)) { - class_alias(GetResponseForExceptionEvent::class, ErrorListenerExceptionEvent::class); - } -} /** * This listener listens for error events and logs them to Sentry. diff --git a/src/EventListener/RequestListener.php b/src/EventListener/RequestListener.php index 035b2ba9..35b17fbc 100644 --- a/src/EventListener/RequestListener.php +++ b/src/EventListener/RequestListener.php @@ -5,32 +5,9 @@ use Sentry\State\HubInterface; use Sentry\State\Scope; use Sentry\UserDataBag; -use Symfony\Component\HttpKernel\Event\ControllerEvent; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\RequestEvent; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\User\UserInterface; -if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - if (! class_exists(RequestListenerRequestEvent::class, false)) { - class_alias(RequestEvent::class, RequestListenerRequestEvent::class); - } - - if (! class_exists(RequestListenerControllerEvent::class, false)) { - class_alias(ControllerEvent::class, RequestListenerControllerEvent::class); - } -} else { - if (! class_exists(RequestListenerRequestEvent::class, false)) { - class_alias(GetResponseEvent::class, RequestListenerRequestEvent::class); - } - - if (! class_exists(RequestListenerControllerEvent::class, false)) { - class_alias(FilterControllerEvent::class, RequestListenerControllerEvent::class); - } -} - /** * This listener ensures that a new {@see \Sentry\State\Scope} is created for * each request and that it is filled with useful information, e.g. the IP diff --git a/src/EventListener/SubRequestListener.php b/src/EventListener/SubRequestListener.php index d100e494..2973839d 100644 --- a/src/EventListener/SubRequestListener.php +++ b/src/EventListener/SubRequestListener.php @@ -4,19 +4,6 @@ use Sentry\State\HubInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\RequestEvent; -use Symfony\Component\HttpKernel\Kernel; - -if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { - if (! class_exists(SubRequestListenerRequestEvent::class, false)) { - class_alias(RequestEvent::class, SubRequestListenerRequestEvent::class); - } -} else { - if (! class_exists(SubRequestListenerRequestEvent::class, false)) { - class_alias(GetResponseEvent::class, SubRequestListenerRequestEvent::class); - } -} /** * This listener ensures that a new {@see \Sentry\State\Scope} is created for diff --git a/src/aliases.php b/src/aliases.php new file mode 100644 index 00000000..7838fb38 --- /dev/null +++ b/src/aliases.php @@ -0,0 +1,47 @@ +=')) { + if (! class_exists(ErrorListenerExceptionEvent::class, false)) { + class_alias(ExceptionEvent::class, ErrorListenerExceptionEvent::class); + } + + if (! class_exists(RequestListenerRequestEvent::class, false)) { + class_alias(RequestEvent::class, RequestListenerRequestEvent::class); + } + + if (! class_exists(RequestListenerControllerEvent::class, false)) { + class_alias(ControllerEvent::class, RequestListenerControllerEvent::class); + } + + if (! class_exists(SubRequestListenerRequestEvent::class, false)) { + class_alias(RequestEvent::class, SubRequestListenerRequestEvent::class); + } +} else { + if (! class_exists(ErrorListenerExceptionEvent::class, false)) { + class_alias(GetResponseForExceptionEvent::class, ErrorListenerExceptionEvent::class); + } + + if (! class_exists(RequestListenerRequestEvent::class, false)) { + class_alias(GetResponseEvent::class, RequestListenerRequestEvent::class); + } + + if (! class_exists(RequestListenerControllerEvent::class, false)) { + class_alias(FilterControllerEvent::class, RequestListenerControllerEvent::class); + } + + if (! class_exists(SubRequestListenerRequestEvent::class, false)) { + class_alias(GetResponseEvent::class, SubRequestListenerRequestEvent::class); + } +}