getsentry / sentry-symfony

The official Symfony SDK for Sentry (sentry.io)
https://sentry.io
MIT License
694 stars 170 forks source link

PHP Fatal error: Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): #834

Closed jeslopcru closed 6 months ago

jeslopcru commented 6 months ago

How do you use Sentry?

Sentry SaaS (sentry.io)

SDK version

5.0.0

Steps to reproduce

I tried to Bump sentry/sentry-symfony from 4.14.0 to 5.0.0. When I run PHP-cs-fixer or PHPStan or any other command Then the result is a failure

PHP Fatal error:  Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): mixed in /home/runner/work/phone-app/phone-app/vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php on line 15
Fatal error: Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): mixed in /home/runner/work/phone-app/phone-app/vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php on line 15
time=2024-04-15T14:04:36.151Z level=INFO msg="[phpstan] reported: https://github.com/DocPlanner/phone-app/runs/23830731474 (conclusion=success)"

I'm using symfony/http-client-contracts version 3.4.2 in composer.lock

Expected result

A ok result when executing the command

This is signature of the method getInfo https://github.com/symfony/contracts/blob/main/HttpClient/ResponseInterface.php#L108

public function getInfo(?string $type = null): mixed;

Actual result

PHP Fatal error:  Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): mixed in /home/runner/work/phone-app/phone-app/vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php on line 15
Fatal error: Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): mixed in /home/runner/work/phone-app/phone-app/vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php on line 15
time=2024-04-15T14:04:36.151Z level=INFO msg="[phpstan] reported: https://github.com/DocPlanner/phone-app/runs/23830731474 (conclusion=success)"
Jean85 commented 6 months ago

You shouldn't run PHP-CS-Fixer on your vendor folder. As for PHPStan, you can ignore that file with this snippet in your config:

parameters:
    excludePaths:
        analyseAndScan:
            - vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php

We could try to make that class conditionally declared to fix this, but I think PHPStan would have errors anyway.

jeslopcru commented 6 months ago

Awesome! Thank you so much for the clarification. I will do this change on my PHPStan config

jeslopcru commented 6 months ago

Only to give more information about it: The project where I'm using sentry is in PHP 8.2.5 and Symfony 6.4 When I executed the test the problem it was the same:

PHP Fatal error:  Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): mixed in /home/runner/work/phone-app/phone-app/vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php on line 15
Fatal error: Declaration of Sentry\SentryBundle\Tracing\HttpClient\TraceableResponseForV4::getInfo(?string $type = null) must be compatible with Symfony\Contracts\HttpClient\ResponseInterface::getInfo(?string $type = null): mixed in /home/runner/work/phone-app/phone-app/vendor/sentry/sentry-symfony/src/Tracing/HttpClient/TraceableResponseForV4.php on line 15

Debugging in sentry-symfony library I found src/aliases.php file where the class TraceableResponseForV4 was added 🤓

image

So I realized that StreameableInterface was not added to my composer.json After some browsing I found the class in Symfony Http Client library

So I added composer require symfony/http-client

And now the tests are green 🥳 We can use new Sentry version