Skip to content

Commit 0c442a4

Browse files
authored
chore: drop support for Symfony 4.4 and PHP 7.4, as they are not maintained since a long time (#36)
* chore: drop support for Symfony 4.4 and PHP 7.4, as they are not maintained since a long time * chore: update PHPStan and fix some errors * chore: setup Rector chore: setup Rector Revert "chore: setup Rector" This reverts commit 9689d95f5c14e19df1a821d6ba6f1644bd8dcbfb.
1 parent 6508ee4 commit 0c442a4

File tree

16 files changed

+327
-128
lines changed

16 files changed

+327
-128
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
PHPUNIT_FLAGS: -v
1212
COMPOSER_MEMORY_LIMIT: -1
1313

14-
PHP_VERSION_DEFAULT: 8.0
14+
PHP_VERSION_DEFAULT: 8.1
1515
NODE_VERSION: 14.x
1616

1717
jobs:
@@ -34,9 +34,11 @@ jobs:
3434

3535
- run: composer install --prefer-dist --no-interaction --no-progress
3636

37+
- run: composer ecs@ci
38+
3739
- run: composer phpstan
3840

39-
- run: composer ecs@ci
41+
- run: composer rector@ci
4042

4143
- run: yarn install --frozen-lockfile
4244

@@ -51,33 +53,45 @@ jobs:
5153
matrix:
5254
config:
5355
# Minimum supported dependencies with the latest and oldest PHP version
54-
- PHP_VERSION: 7.4
56+
- PHP_VERSION: 8.1
5557
COMPOSER_FLAGS: --prefer-stable --prefer-lowest
5658

5759
# Test the latest stable release
58-
- PHP_VERSION: 7.4
59-
- PHP_VERSION: 8.0
60+
- PHP_VERSION: 8.1
61+
- PHP_VERSION: 8.2
62+
- PHP_VERSION: 8.3
6063
COVERAGE: true
61-
PHPUNIT_FLAGS: -v --coverage-text
64+
PHPUNIT_FLAGS: --coverage-text
6265

6366
# Test specific Symfony versions
64-
- PHP_VERSION: 7.4
65-
SYMFONY_VERSION: 4.4.* # Last 4.x version
66-
- PHP_VERSION: 7.4
67+
- PHP_VERSION: 8.1
6768
SYMFONY_VERSION: 5.* # Last 5.x version
68-
- PHP_VERSION: 8.0
69-
SYMFONY_VERSION: 4.4.* # Last 4.x version
70-
- PHP_VERSION: 8.0
69+
- PHP_VERSION: 8.2
7170
SYMFONY_VERSION: 5.4.* # Last 5.4.x version
71+
- PHP_VERSION: 8.3
72+
SYMFONY_VERSION: 5.4.* # Last 5.4.x version
73+
7274
- PHP_VERSION: 8.1
7375
SYMFONY_VERSION: 6.4.* # Last 6.1.x version
74-
- PHP_VERSION: 8.1
75-
SYMFONY_VERSION: 6.* # Last 6.x version
7676
- PHP_VERSION: 8.2
77-
SYMFONY_VERSION: 7.0.* # Last 7.0.x version
77+
SYMFONY_VERSION: 6.4.* # Last 6.1.x version
78+
- PHP_VERSION: 8.3
79+
SYMFONY_VERSION: 6.4.* # Last 6.1.x version
80+
7881
- PHP_VERSION: 8.2
82+
SYMFONY_VERSION: 7.0.* # Last 7.0.x version
83+
- PHP_VERSION: 8.3
84+
SYMFONY_VERSION: 7.0.* # Last 7.0.x version
85+
86+
#- PHP_VERSION: 8.2
87+
# SYMFONY_VERSION: 7.1.* # Last 7.0.x version
88+
#- PHP_VERSION: 8.3
89+
# SYMFONY_VERSION: 7.1.* # Last 7.0.x version
90+
91+
# Test the latest Symfony development version with the latest PHP version
92+
- PHP_VERSION: 8.3
93+
SYMFONY_VERSION: 7.* # Last 7.x version
7994
STABILITY: dev
80-
SYMFONY_VERSION: 7.0.* # Last 7.x version
8195

8296
steps:
8397
- uses: actions/checkout@v4

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"scripts": {
2020
"bin": "echo 'bin not installed'",
2121
"phpstan": "phpstan analyze --ansi",
22+
"rector": "rector",
23+
"rector@ci": "rector --dry-run",
2224
"ecs": "ecs --fix -v",
2325
"ecs@ci": "ecs -v",
2426
"phpunit": "phpunit",
@@ -38,18 +40,18 @@
3840
]
3941
},
4042
"require": {
41-
"php": "^7.4 || ^8.0",
43+
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
4244
"ext-json": "*",
4345
"phpunit/phpunit": "^9.1 || ^10.0",
44-
"symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0",
45-
"symfony/mailer": "^4.4 || ^5.0 || ^6.0 || ^7.0"
46+
"symfony/console": "^5.4 || ^6.0 || ^7.0",
47+
"symfony/mailer": "^5.4 || ^6.0 || ^7.0"
4648
},
4749
"require-dev": {
4850
"bamarni/composer-bin-plugin": "^1.8",
4951
"behat/behat": "^3.6",
5052
"friends-of-behat/symfony-extension": "^2.2",
5153
"nyholm/psr7": "^1.8",
52-
"symfony/framework-bundle": "^4.4.14 || ^5.0 || ^6.0 || ^7.0",
54+
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
5355
"symfony/psr7-pack": "^1.0"
5456
},
5557
"autoload": {

phpstan-baseline.neon

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Method Kocal\\\\SymfonyMailerTesting\\\\Tests\\\\Bridge\\\\Behat\\\\EmailContext\\:\\:iSendAnEmail\\(\\) has parameter \\$table with no value type specified in iterable type Behat\\\\Gherkin\\\\Node\\\\TableNode\\.$#"
4+
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
5+
count: 2
6+
path: src/Bridge/Behat/MailerContext.php
7+
8+
-
9+
message: "#^Property Kocal\\\\SymfonyMailerTesting\\\\MailerLogger\\:\\:\\$events \\(Symfony\\\\Component\\\\Mailer\\\\Event\\\\MessageEvents\\) does not accept mixed\\.$#"
510
count: 1
6-
path: tests/Bridge/Behat/bootstrap/EmailContext.php
11+
path: src/MailerLogger.php
12+
13+
-
14+
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
15+
count: 4
16+
path: src/Test/MailerAssertions.php
717

818
-
919
message: "#^Access to an undefined static property static\\(Kocal\\\\SymfonyMailerTesting\\\\Tests\\\\Bridge\\\\Symfony\\\\EventListener\\\\MailerLoggerListenerTest\\)\\:\\:\\$container\\.$#"

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parameters:
1414
- src
1515
- tests
1616

17-
excludes_analyse:
17+
excludePaths:
1818
- fixtures/applications/Symfony
1919

2020
symfony:

rector.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
9+
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->paths([
12+
__DIR__ . '/src',
13+
__DIR__ . '/tests',
14+
]);
15+
16+
$rectorConfig->sets([
17+
SetList::PHP_81,
18+
SetList::CODE_QUALITY,
19+
SetList::CODING_STYLE,
20+
]);
21+
};

src/Bridge/Behat/MailerContextTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function iDebugThisEmail(): void
101101
$io->writeln((string) $email->getHtmlBody() ?? '');
102102

103103
$io->section('Attachments');
104-
$io->listing(array_map(function (DataPart $attachment): string {
104+
$io->listing(array_map(static function (DataPart $attachment): string {
105105
return $attachment->asDebugString();
106106
}, $email->getAttachments()));
107107
}

src/MailerLogger.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111

1212
class MailerLogger implements ResetInterface
1313
{
14-
private $cache;
14+
private MessageEvents $events;
1515

16-
/**
17-
* @var MessageEvents
18-
*/
19-
private $events;
20-
21-
public function __construct(CacheItemPoolInterface $cache)
22-
{
23-
$this->cache = $cache;
16+
public function __construct(
17+
private readonly CacheItemPoolInterface $cache
18+
) {
2419
$this->cacheGet();
2520
}
2621

src/Normalizer/EmailNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public function normalize(Email $email): array
2929
{
3030
return [
3131
'headers' => $this->headersNormalizer->normalize($email->getHeaders()),
32-
'from' => array_map(function (Address $address): string {
32+
'from' => array_map(static function (Address $address): string {
3333
return $address->toString();
3434
}, $email->getFrom()),
35-
'to' => array_map(function (Address $address): string {
35+
'to' => array_map(static function (Address $address): string {
3636
return $address->toString();
3737
}, $email->getTo()),
38-
'cc' => array_map(function (Address $address): string {
38+
'cc' => array_map(static function (Address $address): string {
3939
return $address->toString();
4040
}, $email->getCc()),
41-
'bcc' => array_map(function (Address $address): string {
41+
'bcc' => array_map(static function (Address $address): string {
4242
return $address->toString();
4343
}, $email->getBcc()),
4444
'subject' => $email->getSubject(),
@@ -50,7 +50,7 @@ public function normalize(Email $email): array
5050
'body' => $email->getHtmlBody(),
5151
'charset' => $email->getHtmlCharset(),
5252
],
53-
'attachments' => array_map(function (DataPart $dataPart): string {
53+
'attachments' => array_map(static function (DataPart $dataPart): string {
5454
return $dataPart->asDebugString();
5555
}, $email->getAttachments()),
5656
];

src/Normalizer/HeadersNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public function normalize(Headers $headers): array
1919

2020
/** @var string $header */
2121
foreach ($headers->toArray() as $header) {
22-
if (false === $i = strpos($header, static::DELIMITER)) {
22+
if (false === $i = strpos($header, self::DELIMITER)) {
2323
throw new \RuntimeException('Invalid header name/value delimiter, this should not happens.');
2424
}
2525

2626
$ret[] = [
2727
'name' => substr($header, 0, $i),
28-
'body' => substr($header, $i + strlen(static::DELIMITER)),
28+
'body' => substr($header, $i + strlen(self::DELIMITER)),
2929
];
3030
}
3131

src/Normalizer/MessageNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function normalize(Message $message): array
2727
{
2828
return [
2929
'headers' => $this->headersNormalizer->normalize($message->getHeaders()),
30-
'body' => null === $message->getBody() ? null : [
30+
'body' => $message->getBody() instanceof \Symfony\Component\Mime\Part\AbstractPart ? [
3131
'headers' => $this->headersNormalizer->normalize($message->getBody()->getHeaders()),
3232
'body' => $message->getBody()->bodyToString(),
33-
],
33+
] : null,
3434
];
3535
}
3636
}

src/Test/MailerAssertions.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ class MailerAssertions
2626
public function __construct(MailerLogger $mailerLogger)
2727
{
2828
// By doing this, we can import and use methods from \Symfony\Bundle\FrameworkBundle\Test\MailerAssertionsTrait
29-
static::$container = new Container();
30-
static::$container->set('mailer.logger_message_listener', $mailerLogger); // Symfony <5.2
31-
static::$container->set('mailer.message_logger_listener', $mailerLogger); // Symfony >=5.2
29+
self::$container = new Container();
30+
self::$container->set('mailer.logger_message_listener', $mailerLogger); // Symfony <5.2
31+
self::$container->set('mailer.message_logger_listener', $mailerLogger); // Symfony >=5.2
3232
}
3333

3434
/**
35-
* For Symfony 5.3 and more, "static::getContainer()" is now called in MailerAssertionsTrait instead of "static::$container".
35+
* For Symfony 5.3 and more, "self::getContainer()" is now called in MailerAssertionsTrait instead of "self::$container".
3636
*
3737
* @see https://github.com/symfony/symfony/pull/40366
3838
*/
3939
public static function getContainer(): ContainerInterface
4040
{
41-
return static::$container;
41+
return self::$container;
4242
}
4343

4444
/**
@@ -129,7 +129,7 @@ public static function assertEmailAttachmentNameSame(RawMessage $email, string $
129129
{
130130
Assert::assertInstanceOf(Email::class, $email);
131131

132-
$matches = (function () use ($email, $attachmentName): bool {
132+
$matches = (static function () use ($email, $attachmentName): bool {
133133
/** @var DataPart $attachment */
134134
foreach ($email->getAttachments() as $attachment) {
135135
if ($attachmentName === $attachment->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename')) {
@@ -150,7 +150,7 @@ public static function assertEmailAttachmentNameMatches(RawMessage $email, strin
150150
{
151151
Assert::assertInstanceOf(Email::class, $email);
152152

153-
$matches = (function () use ($email, $attachmentNamePattern): bool {
153+
$matches = (static function () use ($email, $attachmentNamePattern): bool {
154154
/** @var DataPart $attachment */
155155
foreach ($email->getAttachments() as $attachment) {
156156
if (1 === preg_match($attachmentNamePattern, $attachment->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename') ?? '')) {

tests/Bridge/Behat/bootstrap/EmailContext.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,26 @@ public function __construct(MailerInterface $mailer)
2323
*/
2424
public function iSendAnEmail(TableNode $table): void
2525
{
26+
/**
27+
* @var array{
28+
* from: string,
29+
* to: string,
30+
* subject: string,
31+
* text: string|null,
32+
* html: string|null,
33+
* cc?: string,
34+
* bcc?: string,
35+
* attachments?: string,
36+
* } $params
37+
*/
2638
$params = $table->getRowsHash();
2739

2840
$email = (new Email())
2941
->from($params['from'])
3042
->to($params['to'])
3143
->subject($params['subject'])
3244
->text($params['text'] ?? null)
33-
->html($params['html'] ?? null)
34-
;
45+
->html($params['html'] ?? null);
3546

3647
if (array_key_exists('cc', $params)) {
3748
$email->cc($params['cc']);
@@ -42,7 +53,10 @@ public function iSendAnEmail(TableNode $table): void
4253
}
4354

4455
if (array_key_exists('attachments', $params)) {
45-
foreach (json_decode($params['attachments'], true, 5, JSON_THROW_ON_ERROR) as $attachment) {
56+
/** @var list<array{ body: string, name: string|null, contentType: string|null }> */
57+
$attachments = json_decode($params['attachments'], true, 5, JSON_THROW_ON_ERROR);
58+
59+
foreach ($attachments as $attachment) {
4660
$email->attach($attachment['body'], $attachment['name'] ?? null, $attachment['contentType'] ?? null);
4761
}
4862
}

tools/phpstan/composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"require": {
3-
"phpstan/phpstan": "^0.12.23",
4-
"phpstan/phpstan-phpunit": "^0.12.8",
5-
"phpstan/phpstan-strict-rules": "^0.12.2",
6-
"phpstan/phpstan-symfony": "^0.12.6",
7-
"phpstan/phpstan-webmozart-assert": "^0.12.4"
3+
"phpstan/phpstan": "^1.10.57",
4+
"phpstan/phpstan-phpunit": "^1.3.15",
5+
"phpstan/phpstan-strict-rules": "^1.5.2",
6+
"phpstan/phpstan-symfony": "^1.3.7",
7+
"phpstan/phpstan-webmozart-assert": "^1.2.4"
88
}
99
}

0 commit comments

Comments
 (0)