Skip to content

Commit 44d8690

Browse files
antiftwAntolin Janssen
andauthored
Symfony 7 support continuation (#175)
* initial commit migrating annotations to attributes * minor tweak in Translate attribute, so you dont have to pass a default translation domain * minor refactor entities so they use property promotion * remove some comments that werent supposed to be there * removed dependency on lower symfony versions + switched to deprecation annotations + bugfixes to pass some tests * replaced AnnotationLoader with AttributeLoader in some tests * changed php requirement, added ^7.2 back since the STAN and CSFixer tests run on PHP7.3 * bumped to 8.1 * reverted custom attribute changes, except the SymfonyValidation AnnotationReader which was deprecated in 6.4 * some more use statements that apparently did not influence the tests * all but one PHPSTAN tests passing * fixed last phpstan test? * weird issue * fixed errors that originated in bumping nikic/php-parser to 5.0 * removed support for 3.0 nikic/php-parser * removed superfluous test --------- Co-authored-by: Antolin Janssen <[email protected]>
1 parent d26fba7 commit 44d8690

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+113
-360
lines changed

.github/workflows/static.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
steps:
1010
- uses: actions/checkout@master
1111
- name: PHP-CS-Fixer
12-
uses: docker://jakzal/phpqa:php7.3-alpine
12+
uses: docker://jakzal/phpqa:php8.1-alpine
1313
with:
1414
args: php-cs-fixer fix --diff --dry-run -vvv
1515

@@ -19,6 +19,6 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@master
2121
- name: PHPStan
22-
uses: docker://jakzal/phpqa:php7.3-alpine
22+
uses: docker://jakzal/phpqa:php8.1-alpine
2323
with:
2424
args: phpstan analyze --no-progress

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
}
1010
],
1111
"require": {
12-
"php": "^7.2 || ^8.0",
13-
"nikic/php-parser": "^3.0 || ^4.0",
14-
"symfony/finder": "^3.4 || ^4.4 || ^5.0 || ^6.0",
12+
"php": "^8.1",
13+
"nikic/php-parser": "^4.0 || ^5.0",
14+
"symfony/finder": "^5.4 || ^6.4 || ^7.0",
1515
"twig/twig": "^2.0 || ^3.0",
1616
"doctrine/annotations": "^1.7 || ^2.0"
1717
},
1818
"require-dev": {
19-
"symfony/phpunit-bridge": "^5.0 || ^6.0",
20-
"symfony/translation": "^3.4 || ^4.4 || ^5.0 || ^6.0",
21-
"symfony/validator": "^3.4 || ^4.4 || ^5.0 || ^6.0",
22-
"symfony/twig-bridge": "^3.4 || ^4.4 || ^5.0 || ^6.0",
19+
"symfony/phpunit-bridge": "^5.4 || ^6.4 || ^7.0",
20+
"symfony/translation": "^5.4 || ^6.4 || ^7.0",
21+
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
22+
"symfony/twig-bridge": "^5.4 || ^6.4 || ^7.0",
2323
"knplabs/knp-menu": "^3.1"
2424
},
2525
"autoload": {

src/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class Extractor
2727
/**
2828
* @var FileExtractor[]
2929
*/
30-
private $fileExtractors = [];
30+
private array $fileExtractors = [];
3131

3232
public function extract(Finder $finder): SourceCollection
3333
{

src/FileExtractor/BladeFileExtractor.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
*/
2121
final class BladeFileExtractor implements FileExtractor
2222
{
23-
/**
24-
* {@inheritdoc}
25-
*/
2623
public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void
2724
{
2825
$realPath = $file->getRealPath();
@@ -64,9 +61,6 @@ public function findTranslations(SplFileInfo $file): array
6461
return $keys;
6562
}
6663

67-
/**
68-
* {@inheritdoc}
69-
*/
7064
public function supportsExtension(string $extension): bool
7165
{
7266
return 'blade.php' === $extension;

src/FileExtractor/PHPFileExtractor.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PhpParser\NodeTraverser;
1616
use PhpParser\NodeVisitor;
1717
use PhpParser\ParserFactory;
18+
use PhpParser\PhpVersion;
1819
use Symfony\Component\Finder\SplFileInfo;
1920
use Translation\Extractor\Model\SourceCollection;
2021
use Translation\Extractor\Visitor\Visitor;
@@ -27,15 +28,12 @@ final class PHPFileExtractor implements FileExtractor
2728
/**
2829
* @var Visitor[]|NodeVisitor[]
2930
*/
30-
private $visitors = [];
31+
private array $visitors = [];
3132

32-
/**
33-
* {@inheritdoc}
34-
*/
3533
public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void
3634
{
3735
$path = $file->getRelativePath();
38-
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
36+
$parser = (new ParserFactory())->createForVersion(PhpVersion::fromString('8.1'));
3937
$traverser = new NodeTraverser();
4038
foreach ($this->visitors as $v) {
4139
$v->init($collection, $file);
@@ -50,9 +48,6 @@ public function getSourceLocations(SplFileInfo $file, SourceCollection $collecti
5048
}
5149
}
5250

53-
/**
54-
* {@inheritdoc}
55-
*/
5651
public function supportsExtension(string $extension): bool
5752
{
5853
return \in_array($extension, ['php', 'php5', 'phtml']);

src/FileExtractor/TwigFileExtractor.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ final class TwigFileExtractor extends AbstractExtension implements FileExtractor
2727
/**
2828
* @var NodeVisitorInterface[]
2929
*/
30-
private $visitors = [];
31-
private $twig;
30+
private array $visitors = [];
3231

33-
public function __construct(Environment $twig)
32+
public function __construct(private readonly Environment $twig)
3433
{
35-
$this->twig = $twig;
3634
$twig->addExtension($this);
3735
}
3836

39-
/**
40-
* {@inheritdoc}
41-
*/
4237
public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void
4338
{
4439
foreach ($this->visitors as $v) {
@@ -53,9 +48,6 @@ public function getSourceLocations(SplFileInfo $file, SourceCollection $collecti
5348
$this->twig->parse($stream);
5449
}
5550

56-
/**
57-
* {@inheritdoc}
58-
*/
5951
public function supportsExtension(string $extension): bool
6052
{
6153
return 'twig' === $extension;
@@ -66,17 +58,11 @@ public function addVisitor(NodeVisitorInterface $visitor): void
6658
$this->visitors[] = $visitor;
6759
}
6860

69-
/**
70-
* {@inheritdoc}
71-
*/
7261
public function getNodeVisitors(): array
7362
{
7463
return $this->visitors;
7564
}
7665

77-
/**
78-
* {@inheritdoc}
79-
*/
8066
public function getName(): string
8167
{
8268
return 'php.translation';

src/Model/Error.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
*/
1919
final class Error
2020
{
21-
private $message;
22-
private $path;
23-
private $line;
24-
25-
public function __construct(string $message, string $path, int $line)
26-
{
27-
$this->message = $message;
28-
$this->path = (string) $path;
29-
$this->line = $line;
21+
public function __construct(
22+
private readonly string $message,
23+
private readonly string $path,
24+
private readonly int $line
25+
) {
3026
}
3127

3228
public function getMessage(): string

src/Model/SourceCollection.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,18 @@ final class SourceCollection implements \Countable, \IteratorAggregate
1919
/**
2020
* @var SourceLocation[]
2121
*/
22-
private $sourceLocations = [];
22+
private array $sourceLocations = [];
2323

2424
/**
2525
* @var Error[]
2626
*/
27-
private $errors = [];
27+
private array $errors = [];
2828

29-
/**
30-
* {@inheritdoc}
31-
*/
3229
public function getIterator(): \Traversable
3330
{
3431
return new \ArrayIterator($this->sourceLocations);
3532
}
3633

37-
/**
38-
* {@inheritdoc}
39-
*/
4034
public function count(): int
4135
{
4236
return \count($this->sourceLocations);

src/Model/SourceLocation.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,12 @@
1616
*/
1717
final class SourceLocation
1818
{
19-
/**
20-
* Translation key.
21-
*/
22-
private $message;
23-
private $path;
24-
private $line;
25-
private $context;
26-
27-
public function __construct(string $message, string $path, int $line, array $context = [])
28-
{
29-
$this->message = $message;
30-
$this->path = (string) $path;
31-
$this->line = $line;
32-
$this->context = $context;
19+
public function __construct(
20+
private readonly string $message, /** Translation key. */
21+
private readonly string $path,
22+
private readonly int $line,
23+
private readonly array $context = []
24+
) {
3325
}
3426

3527
/**

src/Twig/TranslationExtension.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
final class TranslationExtension extends AbstractExtension
1818
{
19-
/**
20-
* {@inheritdoc}
21-
*/
2219
public function getFilters(): array
2320
{
2421
return [
@@ -31,9 +28,6 @@ public function runDescFilter($v)
3128
return $v;
3229
}
3330

34-
/**
35-
* {@inheritdoc}
36-
*/
3731
public function getName(): string
3832
{
3933
return 'php-translation';

0 commit comments

Comments
 (0)