diff --git a/.gitattributes b/.gitattributes index a4f0f5b1..ef49f3fc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,8 +3,8 @@ .github export-ignore .gitignore export-ignore .php_cs export-ignore -.scrutinizer.yml export-ignore -.styleci.yml export-ignore -.travis.yml export-ignore -phpstan.neon.dist export-ignore +phpstan.neon.dist export-ignore +phpstan-baseline.neon export-ignore +psalm.baseline.xml export-ignore +psalm.xml export-ignore Tests export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..e6411bee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + pull_request: + +jobs: + build: + name: Test + runs-on: Ubuntu-20.04 + strategy: + fail-fast: false + matrix: + php: [ '7.2', '7.3', '7.4', '8.0' ] + strategy: [ 'highest' ] + sf_version: [''] + include: + - php: 7.4 + strategy: 'lowest' + - php: 7.3 + sf_version: '3.*' + - php: 7.3 + sf_version: '4.*' + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: flex + + - name: Download dependencies + uses: ramsey/composer-install@v1 + env: + SYMFONY_REQUIRE: ${{ matrix.sf_version }} + with: + dependency-versions: ${{ matrix.strategy }} + composer-options: --no-interaction --prefer-dist --optimize-autoloader + + - name: Install PHPUnit + run: ./vendor/bin/simple-phpunit install + + - name: Run tests + run: ./vendor/bin/simple-phpunit + diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 2480e638..a02e633e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -2,23 +2,99 @@ name: Static code analysis on: [pull_request] + jobs: phpstan: name: PHPStan - runs-on: ubuntu-latest + runs-on: Ubuntu-20.04 + steps: - - uses: actions/checkout@master - - name: Run PHPStan - uses: docker://jakzal/phpqa:php7.3-alpine + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache PHPStan + uses: actions/cache@v2 + with: + path: .github/.cache/phpstan/ + key: phpstan-${{ github.sha }} + restore-keys: phpstan- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + + - name: Download dependencies + uses: ramsey/composer-install@v1 with: - args: phpstan analyze + composer-options: --no-interaction --prefer-dist --optimize-autoloader + + - name: Download PHPStan + run: composer bin phpstan update --no-interaction --no-progress + + - name: Execute PHPStan + run: vendor/bin/phpstan analyze --no-progress php-cs-fixer: name: PHP-CS-Fixer - runs-on: ubuntu-latest + runs-on: Ubuntu-20.04 + steps: - - uses: actions/checkout@master - - name: Run PHP-CS-Fixer - uses: docker://jakzal/phpqa:php7.3-alpine + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache PhpCsFixer + uses: actions/cache@v2 with: - args: php-cs-fixer fix --dry-run --diff-format udiff -vvv + path: .github/.cache/php-cs-fixer/ + key: php-cs-fixer-${{ github.sha }} + restore-keys: php-cs-fixer- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + + - name: Download dependencies + uses: ramsey/composer-install@v1 + with: + composer-options: --no-interaction --prefer-dist --optimize-autoloader + + - name: Download PHP CS Fixer + run: composer bin php-cs-fixer update --no-interaction --no-progress + + - name: Execute PHP CS Fixer + run: vendor/bin/php-cs-fixer fix --diff-format udiff --dry-run + + psalm: + name: Psalm + runs-on: Ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache Psalm + uses: actions/cache@v2 + with: + path: .github/.cache/psalm/ + key: psalm-${{ github.sha }} + restore-keys: psalm- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + + - name: Download dependencies + uses: ramsey/composer-install@v1 + with: + composer-options: --no-interaction --prefer-dist --optimize-autoloader + + - name: Download Psalm + run: composer bin psalm update --no-interaction --no-progress + + - name: Execute Psalm + run: vendor/bin/psalm --no-progress --output-format=github diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 28ef3ae4..00000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,9 +0,0 @@ -filter: - excluded_paths: [vendor/*, Tests/*] -checks: - php: - code_rating: true - duplication: true -tools: - external_code_coverage: - timeout: 1800 # Timeout in seconds. diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 128e366c..00000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache - -branches: - except: - - /^analysis-.*$/ - - /^patch-.*$/ - -env: - global: - - TEST_COMMAND="composer test" - - SYMFONY_PHPUNIT_VERSION="6.5" - - COMPOSER_MEMORY_LIMIT=-1 - -matrix: - fast_finish: true - include: - # Run test with code coverage - - php: 7.3 - env: COVERAGE=true TEST_COMMAND="composer test-ci" - - # Test with lowest dependencies - - php: 7.2 - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak" - - # Test the latest stable release - - php: 7.3 - - php: 7.4 - - # Force some major versions of Symfony - - php: 7.3 - env: SYMFONY_VERSION="3.*" - - php: 7.3 - env: SYMFONY_VERSION="4.*" - - # Latest commit to master - - php: 7.3 - env: STABILITY="dev" - - allow_failures: - # Dev-master is allowed to fail. - - env: STABILITY="dev" - -before_install: - - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi - - if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi; - - composer require --no-update symfony/flex - - if ! [ -z "$SYMFONY_VERSION" ]; then composer config extra.symfony.require "${SYMFONY_VERSION}"; fi; - -install: - - composer update ${COMPOSER_FLAGS} --prefer-dist --prefer-stable --no-interaction - -script: - - composer validate --strict --no-check-lock - - $TEST_COMMAND - -after_success: - - if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi - diff --git a/Changelog.md b/Changelog.md index 9e2609b6..7f72c61b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## Unreleased + +### Removed + +- Support for PHP 7.1 + ## 0.12.1 ### Fixed diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php index c4532c0b..a64999d4 100644 --- a/Command/DownloadCommand.php +++ b/Command/DownloadCommand.php @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $message = 'The --cache option is deprecated as it\'s now the default behaviour of this command.'; $io->note($message); - @\trigger_error($message, E_USER_DEPRECATED); + @\trigger_error($message, \E_USER_DEPRECATED); } $configName = $input->getArgument('configuration'); diff --git a/Controller/WebUIController.php b/Controller/WebUIController.php index d099104b..4ef7daa7 100644 --- a/Controller/WebUIController.php +++ b/Controller/WebUIController.php @@ -271,7 +271,7 @@ private function validateMessage(MessageInterface $message, array $validationGro { $errors = $this->validator->validate($message, null, $validationGroups); if (\count($errors) > 0) { - throw MessageValidationException::create(); + throw MessageValidationException::create(); } } } diff --git a/Makefile b/Makefile index db6bcf45..9b8cb4d5 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,33 @@ .PHONY: ${TARGETS} -DIR := ${CURDIR} -QA_IMAGE := jakzal/phpqa:php7.3-alpine +# https://www.gnu.org/software/make/manual/html_node/Force-Targets.html +always: -cs-fix: - @docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff -vvv +cs-fix: vendor + vendor/bin/php-cs-fixer fix --diff-format udiff -vvv -cs-diff: - @docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff --dry-run -vvv +cs-diff: vendor + vendor/bin/php-cs-fixer fix --diff-format udiff --dry-run -vvv -phpstan: - @docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) phpstan analyze +phpstan: vendor + vendor/bin/phpstan analyze -phpunit: +psalm: vendor + vendor/bin/psalm + +phpunit: vendor @vendor/bin/phpunit +.PHONY: baseline +baseline: vendor ## Generate baseline files + vendor/bin/phpstan analyze --generate-baseline + vendor/bin/psalm --set-baseline=psalm.baseline.xml + static: cs-diff phpstan test: static phpunit + +vendor: always + composer update --no-interaction + composer bin all install --no-interaction + vendor/bin/simple-phpunit install diff --git a/Readme.md b/Readme.md index cab8dbd8..5fae742e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,13 +1,9 @@ # Translation Bundle [![Latest Version](https://img.shields.io/github/release/php-translation/symfony-bundle.svg?style=flat-square)](https://github.com/php-translation/symfony-bundle/releases) -[![Build Status](https://img.shields.io/travis/php-translation/symfony-bundle.svg?style=flat-square)](https://travis-ci.org/php-translation/symfony-bundle) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-translation/symfony-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-translation/symfony-bundle) -[![Quality Score](https://img.shields.io/scrutinizer/g/php-translation/symfony-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-translation/symfony-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/c289ebe2-41c4-429f-afba-de2f905b9bdb/mini.png)](https://insight.sensiolabs.com/projects/c289ebe2-41c4-429f-afba-de2f905b9bdb) [![Total Downloads](https://img.shields.io/packagist/dt/php-translation/symfony-bundle.svg?style=flat-square)](https://packagist.org/packages/php-translation/symfony-bundle) - **Symfony integration for PHP Translation** ## Install diff --git a/Tests/Unit/DependencyInjection/CompilerPass/ExternalTranslatorPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/ExternalTranslatorPassTest.php index ac512577..4630de0c 100644 --- a/Tests/Unit/DependencyInjection/CompilerPass/ExternalTranslatorPassTest.php +++ b/Tests/Unit/DependencyInjection/CompilerPass/ExternalTranslatorPassTest.php @@ -24,10 +24,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new ExternalTranslatorPass()); } - /** - * @test - */ - public function if_compiler_pass_collects_services_by_adding_method_calls_these_will_exist(): void + public function testIfCompilerPassCollectsServicesByAddingMethodCallsTheseWillExist(): void { $collectingService = new Definition(); $this->setDefinition('php_translation.translator_service.external_translator', $collectingService); diff --git a/Tests/Unit/DependencyInjection/CompilerPass/ExtractorPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/ExtractorPassTest.php index 6415147f..e8d19c7c 100644 --- a/Tests/Unit/DependencyInjection/CompilerPass/ExtractorPassTest.php +++ b/Tests/Unit/DependencyInjection/CompilerPass/ExtractorPassTest.php @@ -25,10 +25,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new ExtractorPass()); } - /** - * @test - */ - public function if_compiler_pass_collects_services_by_adding_method_calls_these_will_exist(): void + public function testIfCompilerPassCollectsServicesByAddingMethodCallsTheseWillExist(): void { $collectingService = new Definition(); $this->setDefinition(Extractor::class, $collectingService); diff --git a/Tests/Unit/DependencyInjection/CompilerPass/StoragePassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/StoragePassTest.php index b9e50ccc..0b1bd923 100644 --- a/Tests/Unit/DependencyInjection/CompilerPass/StoragePassTest.php +++ b/Tests/Unit/DependencyInjection/CompilerPass/StoragePassTest.php @@ -24,10 +24,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new StoragePass()); } - /** - * @test - */ - public function if_compiler_pass_collects_services_by_adding_method_calls_these_will_exist(): void + public function testIfCompilerPassCollectsServicesByAddingMethodCallsTheseWillExist(): void { $collectingService = new Definition(); $this->setDefinition('php_translation.storage.foobar', $collectingService); diff --git a/Twig/Visitor/DefaultApplyingNodeVisitor.php b/Twig/Visitor/DefaultApplyingNodeVisitor.php index a88d01f0..9c112a7f 100644 --- a/Twig/Visitor/DefaultApplyingNodeVisitor.php +++ b/Twig/Visitor/DefaultApplyingNodeVisitor.php @@ -59,7 +59,7 @@ public function doEnterNode(Node $node, Environment $env): Node } if (!$transNode instanceof FilterExpression) { - throw new \RuntimeException(\sprintf('The "desc" filter must be applied after a "trans", or "transchoice" filter.')); + throw new \RuntimeException('The "desc" filter must be applied after a "trans", or "transchoice" filter.'); } $wrappingNode = $node->getNode('node'); diff --git a/composer.json b/composer.json index 57309126..65f822e1 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "symfony/framework-bundle": "^3.4 || ^4.3 || ^5.0", "symfony/validator": "^3.4 || ^4.3 || ^5.0", "symfony/translation": "^3.4 || ^4.3 || ^5.0", @@ -24,7 +24,8 @@ "twig/twig": "^2.11 || ^3.0" }, "require-dev": { - "symfony/phpunit-bridge": "^4.4 || ^5.0", + "symfony/phpunit-bridge": "^5.2", + "bamarni/composer-bin-plugin": "^1.3", "php-translation/translator": "^1.0", "php-http/curl-client": "^1.7", "php-http/message": "^1.6", @@ -37,8 +38,7 @@ "matthiasnoback/symfony-dependency-injection-test": "^4.1", "matthiasnoback/symfony-config-test": "^4.1", "nyholm/psr7": "^1.1", - "nyholm/symfony-bundle-test": "^1.6.1", - "phpunit/phpunit": "^8.4" + "nyholm/symfony-bundle-test": "^1.6.1" }, "conflict": { "symfony/config": "<3.4.31" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index be1f1d6d..2dd6a23d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -50,16 +50,6 @@ parameters: count: 1 path: DependencyInjection/Configuration.php - - - message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\PostResponseEvent not found\\.$#" - count: 2 - path: EventListener/AutoAddMissingTranslations.php - - - - message: "#^Class Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\FilterResponseEvent not found\\.$#" - count: 2 - path: EventListener/EditInPlaceResponseListener.php - - message: "#^Class Symfony\\\\Component\\\\Translation\\\\TranslatorInterface not found\\.$#" count: 1 diff --git a/psalm.baseline.xml b/psalm.baseline.xml new file mode 100644 index 00000000..267f5f29 --- /dev/null +++ b/psalm.baseline.xml @@ -0,0 +1,136 @@ + + + + + !\is_array($source) + !\is_array($target) + + + + + getKernel + + + + + $messages + $messages->getValue(true) + + + array + + + $messages->getValue(true) + + + + + Intl::getLocaleBundle() + + + + + \array_keys($bundles) + + + fixXmlConfig + root + + + + + $container->getParameter('kernel.project_dir') + + + + + PostResponseEvent + + + + + FilterResponseEvent + + + + + LegacyTranslatorInterface + + + + + getNodeVisitors + + + + + $this->translator + $this->translator + + + $this->translator + $this->translator + $this->translator + $this->translator + $this->translator + LegacyTranslatorInterface|NewTranslatorInterface + LegacyTranslatorInterface|NewTranslatorInterface + + + getCatalogue + getLocale + getLocale + setLocale + transChoice + + + + + (string) $id + + + $this->symfonyTranslator + $this->symfonyTranslator + $this->symfonyTranslator + $this->symfonyTranslator + $this->symfonyTranslator + $this->symfonyTranslator + $this->symfonyTranslator + LegacyTranslatorInterface|NewTranslatorInterface + LegacyTranslatorInterface|NewTranslatorInterface + + + getCatalogue + getLocale + setLocale + transChoice + transChoice + + + + + + + + [$this->extension, 'transchoice'] + + + + + LegacyTranslatorInterface + + + transChoice + transChoice + + + + + 0 + 0 + 0 + 0 + 0 + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..669678fa --- /dev/null +++ b/psalm.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/vendor-bin/php-cs-fixer/composer.json b/vendor-bin/php-cs-fixer/composer.json new file mode 100644 index 00000000..3adf5f5c --- /dev/null +++ b/vendor-bin/php-cs-fixer/composer.json @@ -0,0 +1,9 @@ +{ + "require": { + "php": "^7.2.5 || ^8.0", + "friendsofphp/php-cs-fixer": "2.18.3" + }, + "config": { + "preferred-install": "dist" + } +} diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json new file mode 100644 index 00000000..bfbc7273 --- /dev/null +++ b/vendor-bin/phpstan/composer.json @@ -0,0 +1,10 @@ +{ + "require": { + "php": "^7.2.5 || ^8.0", + "phpstan/phpstan": "0.12.81", + "phpstan/phpstan-deprecation-rules": "0.12.6" + }, + "config": { + "preferred-install": "dist" + } +} diff --git a/vendor-bin/psalm/composer.json b/vendor-bin/psalm/composer.json new file mode 100644 index 00000000..611c2942 --- /dev/null +++ b/vendor-bin/psalm/composer.json @@ -0,0 +1,9 @@ +{ + "require": { + "php": "^7.2.5 || ^8.0", + "vimeo/psalm": "4.6.4" + }, + "config": { + "preferred-install": "dist" + } +}