Skip to content

Commit 251114f

Browse files
alexander-schranzste93cryJean85
authored
Add support for Symfony 6 (#566)
Co-authored-by: Stefano Arlandini <[email protected]> Co-authored-by: Alessandro Lai <[email protected]>
1 parent 4f79cd2 commit 251114f

19 files changed

+290
-237
lines changed

.github/workflows/static-analysis.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818

1919
- name: Setup PHP
2020
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.0'
2123

2224
- name: Install dependencies
2325
run: composer update --no-progress --no-interaction --prefer-dist
@@ -50,9 +52,11 @@ jobs:
5052

5153
- name: Setup PHP
5254
uses: shivammathur/setup-php@v2
55+
with:
56+
php-version: '8.0'
5357

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

5761
- name: Run script
58-
run: composer psalm
62+
run: composer psalm -- --php-version=8.0

.github/workflows/tests.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ jobs:
2727
- 3.4.*
2828
- 4.4.*
2929
- 5.*
30+
- 6.*
3031
dependencies:
3132
- highest
3233
exclude:
34+
- php: '7.2'
35+
symfony-version: 6.*
36+
- php: '7.3'
37+
symfony-version: 6.*
38+
- php: '7.4'
39+
symfony-version: 6.*
3340
- php: '8.0'
3441
symfony-version: 3.4.*
3542
- php: '8.1'
@@ -44,6 +51,9 @@ jobs:
4451
- php: '7.2'
4552
symfony-version: 5.*
4653
dependencies: lowest
54+
- php: '8.0'
55+
symfony-version: 6.*
56+
dependencies: lowest
4757

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

74+
- name: Remove PHP-CS-Fixer
75+
run: composer remove --dev friendsofphp/php-cs-fixer --no-update
76+
6477
- name: Remove Symfony Messenger
6578
run: composer remove --dev symfony/messenger --no-update
6679
if: matrix.symfony-version == '3.4.*'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

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

78
## 4.2.4 (2021-10-20)

composer.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
"php-http/discovery": "^1.11",
2525
"sentry/sdk": "^3.1",
2626
"symfony/cache-contracts": "^1.1||^2.4",
27-
"symfony/config": "^3.4.44||^4.4.20||^5.0.11",
28-
"symfony/console": "^3.4.44||^4.4.20||^5.0.11",
29-
"symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11",
30-
"symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11",
31-
"symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11",
27+
"symfony/config": "^3.4.44||^4.4.20||^5.0.11||^6.0",
28+
"symfony/console": "^3.4.44||^4.4.20||^5.0.11||^6.0",
29+
"symfony/dependency-injection": "^3.4.44||^4.4.20||^5.0.11||^6.0",
30+
"symfony/event-dispatcher": "^3.4.44||^4.4.20||^5.0.11||^6.0",
31+
"symfony/http-kernel": "^3.4.44||^4.4.20||^5.0.11||^6.0",
3232
"symfony/polyfill-php80": "^1.22",
3333
"symfony/psr-http-message-bridge": "^1.2||^2.0",
34-
"symfony/security-core": "^3.4.44||^4.4.20||^5.0.11"
34+
"symfony/security-core": "^3.4.44||^4.4.20||^5.0.11||^6.0"
3535
},
3636
"require-dev": {
3737
"doctrine/dbal": "^2.13||^3.0",
38-
"doctrine/doctrine-bundle": "^1.12||^2.0",
38+
"doctrine/doctrine-bundle": "^1.12||^2.5",
3939
"friendsofphp/php-cs-fixer": "^2.18",
4040
"jangregor/phpstan-prophecy": "^0.8",
4141
"monolog/monolog": "^1.3||^2.0",
@@ -44,16 +44,17 @@
4444
"phpstan/extension-installer": "^1.0",
4545
"phpstan/phpstan": "^0.12",
4646
"phpstan/phpstan-phpunit": "^0.12",
47-
"phpunit/phpunit": "^8.5.14||^9.0",
48-
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11",
49-
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11",
50-
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11",
51-
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11",
52-
"symfony/messenger": "^4.4.20||^5.0.11",
47+
"phpunit/phpunit": "^8.5.14||^9.3.9",
48+
"symfony/browser-kit": "^3.4.44||^4.4.20||^5.0.11||^6.0",
49+
"symfony/cache": "^3.4.44||^4.4.20||^5.0.11||^6.0",
50+
"symfony/dom-crawler": "^3.4.44||^4.4.20||^5.0.11||^6.0",
51+
"symfony/framework-bundle": "^3.4.44||^4.4.20||^5.0.11||^6.0",
52+
"symfony/messenger": "^4.4.20||^5.0.11||^6.0",
5353
"symfony/monolog-bundle": "^3.4",
54-
"symfony/phpunit-bridge": "^5.2.6",
55-
"symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11",
56-
"symfony/yaml": "^3.4.44||^4.4.20||^5.0.11",
54+
"symfony/phpunit-bridge": "^5.2.6||^6.0",
55+
"symfony/process": "^3.4.44||^4.4.20||^5.0.11||^6.0",
56+
"symfony/twig-bundle": "^3.4.44||^4.4.20||^5.0.11||^6.0",
57+
"symfony/yaml": "^3.4.44||^4.4.20||^5.0.11||^6.0",
5758
"vimeo/psalm": "^4.3"
5859
},
5960
"suggest": {

phpstan-baseline.neon

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ parameters:
1515
count: 1
1616
path: src/DependencyInjection/SentryExtension.php
1717

18+
-
19+
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
20+
count: 1
21+
path: src/EventListener/AbstractTracingRequestListener.php
22+
1823
-
1924
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
2025
count: 1
2126
path: src/EventListener/ErrorListener.php
2227

28+
-
29+
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
30+
count: 1
31+
path: src/EventListener/RequestListener.php
32+
33+
-
34+
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
35+
count: 1
36+
path: src/EventListener/SubRequestListener.php
37+
2338
-
2439
message: "#^Method Sentry\\\\SentryBundle\\\\Tracing\\\\Doctrine\\\\DBAL\\\\TracingDriverConnection\\:\\:errorInfo\\(\\) return type has no value type specified in iterable type array\\.$#"
2540
count: 1
@@ -100,14 +115,19 @@ parameters:
100115
count: 1
101116
path: tests/EventListener/MessengerListenerTest.php
102117

118+
-
119+
message: "#^Call to function method_exists\\(\\) with \\$this\\(Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\AuthenticatedTokenStub\\) and 'setAuthenticated' will always evaluate to false\\.$#"
120+
count: 1
121+
path: tests/EventListener/RequestListenerTest.php
122+
103123
-
104124
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent not found\\.$#"
105125
count: 3
106126
path: tests/EventListener/RequestListenerTest.php
107127

108128
-
109129
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
110-
count: 8
130+
count: 9
111131
path: tests/EventListener/RequestListenerTest.php
112132

113133
-
@@ -120,6 +140,11 @@ parameters:
120140
count: 1
121141
path: tests/EventListener/RequestListenerTest.php
122142

143+
-
144+
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\\.$#"
145+
count: 1
146+
path: tests/EventListener/RequestListenerTest.php
147+
123148
-
124149
message: "#^Parameter \\$controllerEvent of method Sentry\\\\SentryBundle\\\\Tests\\\\EventListener\\\\RequestListenerTest\\:\\:testHandleKernelControllerEvent\\(\\) has invalid typehint type Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterControllerEvent\\.$#"
125150
count: 1
@@ -130,6 +155,11 @@ parameters:
130155
count: 1
131156
path: tests/EventListener/RequestListenerTest.php
132157

158+
-
159+
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
160+
count: 1
161+
path: tests/EventListener/SubRequestListenerTest.php
162+
133163
-
134164
message: "#^Instantiated class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\GetResponseEvent not found\\.$#"
135165
count: 2
@@ -170,11 +200,6 @@ parameters:
170200
count: 1
171201
path: tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php
172202

173-
-
174-
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\\.$#"
175-
count: 1
176-
path: tests/Tracing/Cache/AbstractTraceableCacheAdapterTest.php
177-
178203
-
179204
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\\.$#"
180205
count: 2

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ parameters:
1414
- src/Tracing/Doctrine/DBAL/TracingDriverForV2.php
1515
- tests/End2End/App
1616
- tests/Tracing/Doctrine/DBAL/TracingDriverForV2Test.php
17+
- tests/EventListener/Fixtures/UserWithoutIdentifierStub.php
1718
dynamicConstantNames:
1819
- Symfony\Component\HttpKernel\Kernel::VERSION
1920
- Symfony\Component\HttpKernel\Kernel::VERSION_ID

psalm-baseline.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="4.11.1@e33492398bd4e5e2ab60e331d445979bd83feecd">
2+
<files psalm-version="4.13.1@5cf660f63b548ccd4a56f62d916ee4d6028e01a3">
33
<file src="src/DependencyInjection/SentryExtension.php">
44
<UndefinedClass occurrences="1">
55
<code>FatalErrorException</code>
@@ -13,11 +13,37 @@
1313
<code>public function __construct(HubInterface $hub, bool $captureErrors = true)</code>
1414
</MethodSignatureMismatch>
1515
</file>
16+
<file src="src/EventListener/ErrorListener.php">
17+
<RedundantCondition occurrences="1">
18+
<code>$event instanceof ExceptionEvent</code>
19+
</RedundantCondition>
20+
<UndefinedMethod occurrences="1">
21+
<code>getException</code>
22+
</UndefinedMethod>
23+
</file>
24+
<file src="src/EventListener/KernelEventForwardCompatibilityTrait.php">
25+
<UndefinedMethod occurrences="1">
26+
<code>isMasterRequest</code>
27+
</UndefinedMethod>
28+
</file>
29+
<file src="src/Tracing/Cache/TraceableCacheAdapterTrait.php">
30+
<LessSpecificImplementedReturnType occurrences="1">
31+
<code>iterable</code>
32+
</LessSpecificImplementedReturnType>
33+
</file>
1634
<file src="src/Tracing/Doctrine/DBAL/TracingDriverForV2.php">
1735
<UndefinedClass occurrences="1">
1836
<code>ExceptionConverterDriver</code>
1937
</UndefinedClass>
2038
</file>
39+
<file src="src/Tracing/Doctrine/DBAL/TracingDriverForV3.php">
40+
<InvalidReturnStatement occurrences="1">
41+
<code>$this-&gt;decoratedDriver-&gt;getSchemaManager($conn, $platform)</code>
42+
</InvalidReturnStatement>
43+
<InvalidReturnType occurrences="1">
44+
<code>AbstractSchemaManager&lt;T&gt;</code>
45+
</InvalidReturnType>
46+
</file>
2147
<file src="src/Tracing/Doctrine/DBAL/TracingStatementForV2.php">
2248
<InvalidReturnStatement occurrences="2">
2349
<code>$this-&gt;decoratedStatement</code>

src/EventListener/ErrorListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function __construct(HubInterface $hub)
3434
*/
3535
public function handleExceptionEvent(ErrorListenerExceptionEvent $event): void
3636
{
37-
/** @psalm-suppress RedundantCondition */
3837
if ($event instanceof ExceptionEvent) {
3938
$this->hub->captureException($event->getThrowable());
4039
} else {

src/EventListener/RequestListener.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Sentry\State\Scope;
99
use Sentry\UserDataBag;
1010
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1112
use Symfony\Component\Security\Core\User\UserInterface;
1213

1314
/**
@@ -67,7 +68,7 @@ public function handleKernelRequestEvent(RequestListenerRequestEvent $event): vo
6768
$token = $this->tokenStorage->getToken();
6869
}
6970

70-
if (null !== $token && $token->isAuthenticated() && null !== $token->getUser()) {
71+
if ($this->isTokenAuthenticated($token)) {
7172
$userData->setUsername($this->getUsername($token->getUser()));
7273
}
7374

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

125126
return null;
126127
}
128+
129+
private function isTokenAuthenticated(?TokenInterface $token): bool
130+
{
131+
if (null === $token) {
132+
return false;
133+
}
134+
135+
if (method_exists($token, 'isAuthenticated') && !$token->isAuthenticated(false)) {
136+
return false;
137+
}
138+
139+
return null !== $token->getUser();
140+
}
127141
}

src/Tracing/Cache/TraceableCacheAdapterTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Sentry\Tracing\SpanContext;
1010
use Symfony\Component\Cache\Adapter\AdapterInterface;
1111
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
12+
use Symfony\Component\Cache\CacheItem;
1213
use Symfony\Component\Cache\PruneableInterface;
1314
use Symfony\Component\Cache\ResettableInterface;
1415
use Symfony\Contracts\Cache\CacheInterface;
@@ -35,7 +36,7 @@ trait TraceableCacheAdapterTrait
3536
/**
3637
* {@inheritdoc}
3738
*/
38-
public function getItem($key)
39+
public function getItem($key): CacheItem
3940
{
4041
return $this->traceFunction('cache.get_item', function () use ($key) {
4142
return $this->decoratedAdapter->getItem($key);
@@ -45,7 +46,7 @@ public function getItem($key)
4546
/**
4647
* {@inheritdoc}
4748
*/
48-
public function getItems(array $keys = [])
49+
public function getItems(array $keys = []): iterable
4950
{
5051
return $this->traceFunction('cache.get_items', function () use ($keys) {
5152
return $this->decoratedAdapter->getItems($keys);
@@ -66,6 +67,8 @@ public function clear(string $prefix = ''): bool
6667
* {@inheritdoc}
6768
*
6869
* @param mixed[] $metadata
70+
*
71+
* @return mixed
6972
*/
7073
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
7174
{

src/Tracing/Doctrine/DBAL/TracingDriverConnection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public function query(?string $sql = null, ...$args): Result
106106

107107
/**
108108
* {@inheritdoc}
109+
*
110+
* @return mixed
109111
*/
110112
public function quote($value, $type = ParameterType::STRING)
111113
{
@@ -124,6 +126,8 @@ public function exec($sql): int
124126

125127
/**
126128
* {@inheritdoc}
129+
*
130+
* @return string|int|false
127131
*/
128132
public function lastInsertId($name = null)
129133
{

src/Tracing/Doctrine/DBAL/TracingDriverForV3.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public function getDatabasePlatform(): AbstractPlatform
6464

6565
/**
6666
* {@inheritdoc}
67+
*
68+
* @phpstan-template T of AbstractPlatform
69+
*
70+
* @phpstan-param T $platform
71+
*
72+
* @phpstan-return AbstractSchemaManager<T>
6773
*/
6874
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
6975
{

src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function query(?string $sql = null, ...$args): Result
5151

5252
/**
5353
* {@inheritdoc}
54+
*
55+
* @return mixed
5456
*/
5557
public function quote($value, $type = ParameterType::STRING)
5658
{
@@ -67,8 +69,10 @@ public function exec($sql): int
6769

6870
/**
6971
* {@inheritdoc}
72+
*
73+
* @return string|int|false
7074
*/
71-
public function lastInsertId($name = null): ?string
75+
public function lastInsertId($name = null)
7276
{
7377
return $this->decoratedConnection->lastInsertId($name);
7478
}

0 commit comments

Comments
 (0)