From c5ab0bc4c44fd98397e9515186d181fc7f514a65 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Wed, 23 Oct 2024 13:42:39 +0200 Subject: [PATCH 1/3] refac: fix cs (#512) --- Command/CheckMissingCommand.php | 2 +- Command/DeleteEmptyCommand.php | 2 +- Command/DeleteObsoleteCommand.php | 2 +- Command/DownloadCommand.php | 2 +- Command/ExtractCommand.php | 2 +- Command/StatusCommand.php | 2 +- Controller/WebUIController.php | 2 +- Service/Importer.php | 2 +- Tests/Functional/app/Service/DummyMessageFactory.php | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Command/CheckMissingCommand.php b/Command/CheckMissingCommand.php index 1325897..7d00f46 100644 --- a/Command/CheckMissingCommand.php +++ b/Command/CheckMissingCommand.php @@ -47,7 +47,7 @@ public function __construct( ConfigurationManager $configurationManager, CatalogueFetcher $catalogueFetcher, Importer $importer, - CatalogueCounter $catalogueCounter + CatalogueCounter $catalogueCounter, ) { parent::__construct(); diff --git a/Command/DeleteEmptyCommand.php b/Command/DeleteEmptyCommand.php index c61523e..4eba260 100644 --- a/Command/DeleteEmptyCommand.php +++ b/Command/DeleteEmptyCommand.php @@ -55,7 +55,7 @@ public function __construct( StorageManager $storageManager, ConfigurationManager $configurationManager, CatalogueManager $catalogueManager, - CatalogueFetcher $catalogueFetcher + CatalogueFetcher $catalogueFetcher, ) { $this->storageManager = $storageManager; $this->configurationManager = $configurationManager; diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index b3cd57a..35e29a8 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -55,7 +55,7 @@ public function __construct( StorageManager $storageManager, ConfigurationManager $configurationManager, CatalogueManager $catalogueManager, - CatalogueFetcher $catalogueFetcher + CatalogueFetcher $catalogueFetcher, ) { $this->storageManager = $storageManager; $this->configurationManager = $configurationManager; diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index f36d053..8b7f6f1 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -43,7 +43,7 @@ public function __construct( StorageManager $storageManager, ConfigurationManager $configurationManager, CacheClearer $cacheCleaner, - CatalogueWriter $catalogueWriter + CatalogueWriter $catalogueWriter, ) { $this->storageManager = $storageManager; $this->configurationManager = $configurationManager; diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index e7b3b85..d4d03cc 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -67,7 +67,7 @@ public function __construct( CatalogueWriter $catalogueWriter, CatalogueCounter $catalogueCounter, Importer $importer, - ConfigurationManager $configurationManager + ConfigurationManager $configurationManager, ) { $this->catalogueFetcher = $catalogueFetcher; $this->catalogueWriter = $catalogueWriter; diff --git a/Command/StatusCommand.php b/Command/StatusCommand.php index 4c1a2bd..0f701b0 100644 --- a/Command/StatusCommand.php +++ b/Command/StatusCommand.php @@ -50,7 +50,7 @@ class StatusCommand extends Command public function __construct( CatalogueCounter $catalogueCounter, ConfigurationManager $configurationManager, - CatalogueFetcher $catalogueFetcher + CatalogueFetcher $catalogueFetcher, ) { $this->catalogueCounter = $catalogueCounter; $this->configurationManager = $configurationManager; diff --git a/Controller/WebUIController.php b/Controller/WebUIController.php index 493ef64..aa0c40f 100644 --- a/Controller/WebUIController.php +++ b/Controller/WebUIController.php @@ -58,7 +58,7 @@ public function __construct( bool $isWebUIEnabled, bool $isWebUIAllowCreate, bool $isWebUIAllowDelete, - string $fileBasePath + string $fileBasePath, ) { $this->configurationManager = $configurationManager; $this->catalogueFetcher = $catalogueFetcher; diff --git a/Service/Importer.php b/Service/Importer.php index ef0ec47..8213d53 100644 --- a/Service/Importer.php +++ b/Service/Importer.php @@ -131,7 +131,7 @@ public function extractToCatalogues(Finder $finder, array $catalogues, array $co private function convertSourceLocationsToMessages( MessageCatalogue $catalogue, SourceCollection $collection, - MessageCatalogue $currentCatalogue + MessageCatalogue $currentCatalogue, ): void { $currentMessages = NSA::getProperty($currentCatalogue, 'messages'); diff --git a/Tests/Functional/app/Service/DummyMessageFactory.php b/Tests/Functional/app/Service/DummyMessageFactory.php index d972edc..381e71d 100644 --- a/Tests/Functional/app/Service/DummyMessageFactory.php +++ b/Tests/Functional/app/Service/DummyMessageFactory.php @@ -22,7 +22,7 @@ public function createRequest( $uri, array $headers = [], $body = null, - $protocolVersion = '1.1' + $protocolVersion = '1.1', ) { return new Request($method, $uri); } @@ -32,7 +32,7 @@ public function createResponse( $reasonPhrase = null, array $headers = [], $body = null, - $protocolVersion = '1.1' + $protocolVersion = '1.1', ) { return new Response(200); } From 73bfeae8322fac9a0d5d6dc0889d8dacb4778354 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Thu, 27 Mar 2025 16:19:16 +0100 Subject: [PATCH 2/3] feat: add CI & static analysis badges (#517) --- .github/workflows/ci.yml | 3 +++ .github/workflows/static.yml | 7 +++++-- Readme.md | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9eece1f..3e87558 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,10 @@ name: CI on: + push: + branches: [ "master" ] pull_request: + branches: [ "master" ] jobs: build: diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index ea6822a..9402911 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,7 +1,10 @@ name: Static code analysis -on: [pull_request] - +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] jobs: phpstan: diff --git a/Readme.md b/Readme.md index cb35de1..389ec49 100644 --- a/Readme.md +++ b/Readme.md @@ -2,6 +2,8 @@ [![Latest Version](https://img.shields.io/github/release/php-translation/symfony-bundle.svg?style=flat-square)](https://github.com/php-translation/symfony-bundle/releases) [![Total Downloads](https://img.shields.io/packagist/dt/php-translation/symfony-bundle.svg?style=flat-square)](https://packagist.org/packages/php-translation/symfony-bundle) +[![CI](https://github.com/php-translation/symfony-bundle/actions/workflows/ci.yml/badge.svg)](https://github.com/php-translation/symfony-bundle/actions/workflows/ci.yml) +[![Static code analysis](https://github.com/php-translation/symfony-bundle/actions/workflows/static.yml/badge.svg)](https://github.com/php-translation/symfony-bundle/actions/workflows/static.yml) **Symfony integration for PHP Translation** From 553ea2bc07babe69505a94eddcc86639b7904014 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Thu, 27 Mar 2025 16:24:24 +0100 Subject: [PATCH 3/3] github: fix static workflows update dependencies (#516) * github: fix static workflows update dependencies * refac: use ConditionalTernary when possible * refac: use Nodes instate of Node * refac: set operator attribute on EqualBinary expression * refac: migrate phpunit.dist.xml and fix max deprecation setting * feat: remove twig 2.x support no more maintained * refac: fix Symfony\Component\HttpKernel\DependencyInjection\Extension deprecation * refac: fix self deprecation mb_convert_encoding --- .github/workflows/static.yml | 18 +++--- DependencyInjection/TranslationExtension.php | 2 +- .../Functional/Controller/EditInPlaceTest.php | 4 +- Twig/Visitor/DefaultApplyingNodeVisitor.php | 53 +++++++++++++---- composer.json | 2 +- phpunit.xml.dist | 59 ++++++++----------- 6 files changed, 76 insertions(+), 62 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9402911..f4b287d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -9,14 +9,14 @@ on: jobs: phpstan: name: PHPStan - runs-on: Ubuntu-20.04 + runs-on: Ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache PHPStan - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: .github/.cache/phpstan/ key: phpstan-${{ github.sha }} @@ -29,7 +29,7 @@ jobs: coverage: none - name: Download dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: --no-interaction --prefer-dist --optimize-autoloader @@ -43,7 +43,7 @@ jobs: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: @@ -51,13 +51,13 @@ jobs: psalm: name: Psalm - runs-on: Ubuntu-20.04 + runs-on: Ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache Psalm - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: .github/.cache/psalm/ key: psalm-${{ github.sha }} @@ -70,7 +70,7 @@ jobs: coverage: none - name: Download dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v3 with: composer-options: --no-interaction --prefer-dist --optimize-autoloader diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 1ba8fed..ede6351 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -16,9 +16,9 @@ use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\HttpKernel\Kernel; use Translation\Bundle\EventListener\AutoAddMissingTranslations; use Translation\Bundle\EventListener\EditInPlaceResponseListener; diff --git a/Tests/Functional/Controller/EditInPlaceTest.php b/Tests/Functional/Controller/EditInPlaceTest.php index 932af74..733a1e2 100644 --- a/Tests/Functional/Controller/EditInPlaceTest.php +++ b/Tests/Functional/Controller/EditInPlaceTest.php @@ -40,7 +40,7 @@ public function testActivatedTest(): void self::assertStringContainsString('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); + @$dom->loadHTML(mb_encode_numericentity($response->getContent(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8')); $xpath = new \DOMXPath($dom); // Check number of x-trans tags @@ -79,7 +79,7 @@ public function testIfUntranslatableLabelGetsDisabled(): void self::assertStringContainsString('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); + @$dom->loadHTML(mb_encode_numericentity($response->getContent(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8')); $xpath = new \DOMXPath($dom); // Check number of x-trans tags diff --git a/Twig/Visitor/DefaultApplyingNodeVisitor.php b/Twig/Visitor/DefaultApplyingNodeVisitor.php index 9c112a7..5be6d88 100644 --- a/Twig/Visitor/DefaultApplyingNodeVisitor.php +++ b/Twig/Visitor/DefaultApplyingNodeVisitor.php @@ -18,8 +18,11 @@ use Twig\Node\Expression\ConditionalExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\Ternary\ConditionalTernary; use Twig\Node\Node; +use Twig\Node\Nodes; use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\TwigFilter; /** * Applies the value of the "desc" filter if the "trans" filter has no @@ -93,22 +96,46 @@ public function doEnterNode(Node $node, Environment $env): Node $testNode->getNode('arguments')->setNode(0, new ArrayExpression([], $lineno)); // wrap the default node in a |replace filter - $defaultNode = new FilterExpression( - clone $node->getNode('arguments')->getNode(0), - new ConstantExpression('replace', $lineno), - new Node([ - clone $wrappingNode->getNode('arguments')->getNode(0), - ]), - $lineno + if (Environment::VERSION_ID >= 31500) { + $defaultNode = new FilterExpression( + clone $node->getNode('arguments')->getNode(0), + new TwigFilter('replace'), + new Nodes([ + clone $wrappingNode->getNode('arguments')->getNode(0), + ]), + $lineno + ); + } else { + $defaultNode = new FilterExpression( + clone $node->getNode('arguments')->getNode(0), + new ConstantExpression('replace', $lineno), + new Node([ + clone $wrappingNode->getNode('arguments')->getNode(0), + ]), + $lineno + ); + } + } + + $expr = new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine()); + if (Environment::VERSION_ID >= 31700) { + $expr->setAttribute('operator', 'binary_=='); + + $condition = new ConditionalTernary( + $expr, + $defaultNode, + clone $wrappingNode, + $wrappingNode->getTemplateLine() + ); + } else { + $condition = new ConditionalExpression( + $expr, + $defaultNode, + clone $wrappingNode, + $wrappingNode->getTemplateLine() ); } - $condition = new ConditionalExpression( - new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine()), - $defaultNode, - clone $wrappingNode, - $wrappingNode->getTemplateLine() - ); $node->setNode('node', $condition); return $node; diff --git a/composer.json b/composer.json index e28adc8..3dd11d3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php-translation/symfony-storage": "^2.1", "php-translation/extractor": "^2.0", "nyholm/nsa": "^1.1", - "twig/twig": "^2.14.4 || ^3.3", + "twig/twig": "^3.3", "symfony/asset": "^5.3 || ^6.0 || ^7.0" }, "require-dev": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0a4e149..5e2a761 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,38 +1,25 @@ - - - - - - - - - - - - - - - ./Tests - - - - - - ./ - - vendor - Tests - - - + + + + ./ + + + vendor + Tests + + + + + + + + + + + + + ./Tests + +