Skip to content

Commit

Permalink
Add support for Symfony 6 (#566)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Arlandini <[email protected]>
Co-authored-by: Alessandro Lai <[email protected]>
  • Loading branch information
3 people committed Dec 12, 2021
1 parent 4f79cd2 commit 251114f
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 237 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install dependencies
run: composer update --no-progress --no-interaction --prefer-dist
Expand Down Expand Up @@ -50,9 +52,11 @@ jobs:

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install dependencies
run: composer update --no-progress --no-interaction --prefer-dist

- name: Run script
run: composer psalm
run: composer psalm -- --php-version=8.0
13 changes: 13 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ jobs:
- 3.4.*
- 4.4.*
- 5.*
- 6.*
dependencies:
- highest
exclude:
- php: '7.2'
symfony-version: 6.*
- php: '7.3'
symfony-version: 6.*
- php: '7.4'
symfony-version: 6.*
- php: '8.0'
symfony-version: 3.4.*
- php: '8.1'
Expand All @@ -44,6 +51,9 @@ jobs:
- php: '7.2'
symfony-version: 5.*
dependencies: lowest
- php: '8.0'
symfony-version: 6.*
dependencies: lowest

steps:
- name: Checkout
Expand All @@ -61,6 +71,9 @@ jobs:
- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Remove PHP-CS-Fixer
run: composer remove --dev friendsofphp/php-cs-fixer --no-update

- name: Remove Symfony Messenger
run: composer remove --dev symfony/messenger --no-update
if: matrix.symfony-version == '3.4.*'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Add support for Symfony 6 (#566)
- Fix fatal errors logged twice on Symfony `3.4` (#570)

## 4.2.4 (2021-10-20)
Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
"php-http/discovery": "^1.11",
"sentry/sdk": "^3.1",
"symfony/cache-contracts": "^1.1||^2.4",
"symfony/config": "^3.4.44||^4.4.20||^5.0.11",
"symfony/console": "^3.4.44||^4.4.20||^5.0.11",
"symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11",
"symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11",
"symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11",
"symfony/config": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/console": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/polyfill-php80": "^1.22",
"symfony/psr-http-message-bridge": "^1.2||^2.0",
"symfony/security-core": "^3.4.44||^4.4.20||^5.0.11"
"symfony/security-core": "^3.4.44||^4.4.20||^5.0.11||^6.0"
},
"require-dev": {
"doctrine/dbal": "^2.13||^3.0",
"doctrine/doctrine-bundle": "^1.12||^2.0",
"doctrine/doctrine-bundle": "^1.12||^2.5",
"friendsofphp/php-cs-fixer": "^2.18",
"jangregor/phpstan-prophecy": "^0.8",
"monolog/monolog": "^1.3||^2.0",
Expand All @@ -44,16 +44,17 @@
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^8.5.14||^9.0",
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11",
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11",
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11",
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11",
"symfony/messenger": "^4.4.20||^5.0.11",
"phpunit/phpunit": "^8.5.14||^9.3.9",
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/messenger": "^4.4.20||^5.0.11||^6.0",
"symfony/monolog-bundle": "^3.4",
"symfony/phpunit-bridge": "^5.2.6",
"symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11",
"symfony/yaml": "^3.4.44||^4.4.20||^5.0.11",
"symfony/phpunit-bridge": "^5.2.6||^6.0",
"symfony/process": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"symfony/yaml": "^3.4.44||^4.4.20||^5.0.11||^6.0",
"vimeo/psalm": "^4.3"
},
"suggest": {
Expand Down
37 changes: 31 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ parameters:
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
path: src/EventListener/AbstractTracingRequestListener.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: src/EventListener/ErrorListener.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
path: src/EventListener/RequestListener.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
path: src/EventListener/SubRequestListener.php

-
message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -100,14 +115,19 @@ parameters:
count: 1
path: tests/EventListener/MessengerListenerTest.php

-
message: "#^Call to function method_exists\\(\\) with \\$this\\(Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub\\) and 'setAuthenticated' will always evaluate to false\\.$#"
count: 1
path: tests/EventListener/RequestListenerTest.php

-
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#"
count: 3
path: tests/EventListener/RequestListenerTest.php

-
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 8
count: 9
path: tests/EventListener/RequestListenerTest.php

-
Expand All @@ -120,6 +140,11 @@ parameters:
count: 1
path: tests/EventListener/RequestListenerTest.php

-
message: "#^Parameter \\#1 \\$user of method Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\AbstractToken\\:\\:setUser\\(\\) expects Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface, string\\|Stringable\\|Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface given\\.$#"
count: 1
path: tests/EventListener/RequestListenerTest.php

-
message: "#^Parameter \\$controllerEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelControllerEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent\\.$#"
count: 1
Expand All @@ -130,6 +155,11 @@ parameters:
count: 1
path: tests/EventListener/RequestListenerTest.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
path: tests/EventListener/SubRequestListenerTest.php

-
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
count: 2
Expand Down Expand Up @@ -170,11 +200,6 @@ parameters:
count: 1
path: tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php

-
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with array\\(Symfony\\\\Component\\\\Cache\\\\CacheItem\\) and iterable\\<Symfony\\\\Component\\\\Cache\\\\CacheItem\\>&Traversable will always evaluate to false\\.$#"
count: 1
path: tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php

-
message: "#^Parameter \\#1 \\$decoratedAdapter of method Sentry\\\\SentryBundle\\\\Tests\\\\Tracing\\\\Cache\\\\AbstractTraceableCacheAdapterTest\\<TCacheAdapter of Symfony\\\\Component\\\\Cache\\\\Adapter\\\\AdapterInterface,TDecoratedCacheAdapter of Symfony\\\\Component\\\\Cache\\\\Adapter\\\\AdapterInterface\\>\\:\\:createCacheAdapter\\(\\) expects TDecoratedCacheAdapter of Symfony\\\\Component\\\\Cache\\\\Adapter\\\\AdapterInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Sentry\\\\SentryBundle\\\\Tests\\\\Tracing\\\\Cache\\\\CacheInterface given\\.$#"
count: 2
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parameters:
- src/Tracing/Doctrine/DBAL/TracingDriverForV2.php
- tests/End2End/App
- tests/Tracing/Doctrine/DBAL/TracingDriverForV2Test.php
- tests/EventListener/Fixtures/UserWithoutIdentifierStub.php
dynamicConstantNames:
- Symfony\Component\HttpKernel\Kernel::VERSION
- Symfony\Component\HttpKernel\Kernel::VERSION_ID
Expand Down
28 changes: 27 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.11.1@e33492398bd4e5e2ab60e331d445979bd83feecd">
<files psalm-version="4.13.1@5cf660f63b548ccd4a56f62d916ee4d6028e01a3">
<file src="src/DependencyInjection/SentryExtension.php">
<UndefinedClass occurrences="1">
<code>FatalErrorException</code>
Expand All @@ -13,11 +13,37 @@
<code>public function __construct(HubInterface $hub, bool $captureErrors = true)</code>
</MethodSignatureMismatch>
</file>
<file src="src/EventListener/ErrorListener.php">
<RedundantCondition occurrences="1">
<code>$event instanceof ExceptionEvent</code>
</RedundantCondition>
<UndefinedMethod occurrences="1">
<code>getException</code>
</UndefinedMethod>
</file>
<file src="src/EventListener/KernelEventForwardCompatibilityTrait.php">
<UndefinedMethod occurrences="1">
<code>isMasterRequest</code>
</UndefinedMethod>
</file>
<file src="src/Tracing/Cache/TraceableCacheAdapterTrait.php">
<LessSpecificImplementedReturnType occurrences="1">
<code>iterable</code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/Tracing/Doctrine/DBAL/TracingDriverForV2.php">
<UndefinedClass occurrences="1">
<code>ExceptionConverterDriver</code>
</UndefinedClass>
</file>
<file src="src/Tracing/Doctrine/DBAL/TracingDriverForV3.php">
<InvalidReturnStatement occurrences="1">
<code>$this-&gt;decoratedDriver-&gt;getSchemaManager($conn, $platform)</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>AbstractSchemaManager&lt;T&gt;</code>
</InvalidReturnType>
</file>
<file src="src/Tracing/Doctrine/DBAL/TracingStatementForV2.php">
<InvalidReturnStatement occurrences="2">
<code>$this-&gt;decoratedStatement</code>
Expand Down
1 change: 0 additions & 1 deletion src/EventListener/ErrorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __construct(HubInterface $hub)
*/
public function handleExceptionEvent(ErrorListenerExceptionEvent $event): void
{
/** @psalm-suppress RedundantCondition */
if ($event instanceof ExceptionEvent) {
$this->hub->captureException($event->getThrowable());
} else {
Expand Down
16 changes: 15 additions & 1 deletion src/EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Sentry\State\Scope;
use Sentry\UserDataBag;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
Expand Down Expand Up @@ -67,7 +68,7 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
$token = $this->tokenStorage->getToken();
}

if (null !== $token && $token->isAuthenticated() && null !== $token->getUser()) {
if ($this->isTokenAuthenticated($token)) {
$userData->setUsername($this->getUsername($token->getUser()));
}

Expand Down Expand Up @@ -124,4 +125,17 @@ private function getUsername($user): ?string

return null;
}

private function isTokenAuthenticated(?TokenInterface $token): bool
{
if (null === $token) {
return false;
}

if (method_exists($token, 'isAuthenticated') && !$token->isAuthenticated(false)) {
return false;
}

return null !== $token->getUser();
}
}
7 changes: 5 additions & 2 deletions src/Tracing/Cache/TraceableCacheAdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Sentry\Tracing\SpanContext;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contracts\Cache\CacheInterface;
Expand All @@ -35,7 +36,7 @@ trait TraceableCacheAdapterTrait
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem($key): CacheItem
{
return $this->traceFunction('cache.get_item', function () use ($key) {
return $this->decoratedAdapter->getItem($key);
Expand All @@ -45,7 +46,7 @@ public function getItem($key)
/**
* {@inheritdoc}
*/
public function getItems(array $keys = [])
public function getItems(array $keys = []): iterable
{
return $this->traceFunction('cache.get_items', function () use ($keys) {
return $this->decoratedAdapter->getItems($keys);
Expand All @@ -66,6 +67,8 @@ public function clear(string $prefix = ''): bool
* {@inheritdoc}
*
* @param mixed[] $metadata
*
* @return mixed
*/
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Tracing/Doctrine/DBAL/TracingDriverConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function query(?string $sql = null, ...$args): Result

/**
* {@inheritdoc}
*
* @return mixed
*/
public function quote($value, $type = ParameterType::STRING)
{
Expand All @@ -124,6 +126,8 @@ public function exec($sql): int

/**
* {@inheritdoc}
*
* @return string|int|false
*/
public function lastInsertId($name = null)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Tracing/Doctrine/DBAL/TracingDriverForV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public function getDatabasePlatform(): AbstractPlatform

/**
* {@inheritdoc}
*
* @phpstan-template T of AbstractPlatform
*
* @phpstan-param T $platform
*
* @phpstan-return AbstractSchemaManager<T>
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function query(?string $sql = null, ...$args): Result

/**
* {@inheritdoc}
*
* @return mixed
*/
public function quote($value, $type = ParameterType::STRING)
{
Expand All @@ -67,8 +69,10 @@ public function exec($sql): int

/**
* {@inheritdoc}
*
* @return string|int|false
*/
public function lastInsertId($name = null): ?string
public function lastInsertId($name = null)
{
return $this->decoratedConnection->lastInsertId($name);
}
Expand Down
Loading

0 comments on commit 251114f

Please sign in to comment.