From a3bbb60beaaf44fe94c8d78783435c2c8884d094 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 26 Mar 2021 19:20:45 +0100 Subject: [PATCH] Drop old PHP versions (#26) * Drop old PHP versions * Add changelog * Apply CS fixes * Minors --- .gitattributes | 21 +++--- .github/workflows/checks.yml | 33 ++++++++++ .github/workflows/ci.yml | 37 +++++++++++ .github/workflows/continuous-integration.yml | 69 -------------------- .gitignore | 4 +- .php_cs | 24 ++++--- .scrutinizer.yml | 8 --- .styleci.yml | 12 ---- .travis.yml | 35 ---------- Changelog.md | 14 +++- Readme.md | 3 - composer.json | 4 +- phpstan-baseline.neon | 32 +++++++++ phpstan.neon.dist | 9 +++ src/Service/BingTranslator.php | 8 +-- src/Service/GoogleTranslator.php | 8 +-- src/Service/YandexTranslator.php | 6 +- src/Translator.php | 8 +-- 18 files changed, 158 insertions(+), 177 deletions(-) create mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .scrutinizer.yml delete mode 100644 .styleci.yml delete mode 100644 .travis.yml create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon.dist diff --git a/.gitattributes b/.gitattributes index 6994049..6ae144d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,12 +1,9 @@ -.editorconfig export-ignore -.gitattributes export-ignore -/.github/ export-ignore -.gitignore export-ignore -/.php_cs export-ignore -/.scrutinizer.yml export-ignore -/.styleci.yml export-ignore -/.travis.yml export-ignore -/behat.yml.dist export-ignore -/features/ export-ignore -/phpunit.xml.dist export-ignore -/Tests/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +/.github/ export-ignore +.gitignore export-ignore +/.php_cs export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore +/phpunit.xml.dist export-ignore +/tests/ export-ignore diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..d500afb --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,33 @@ +name: Static code analysis + +on: [pull_request] + +jobs: + phpstan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Run PHPStan + uses: docker://jakzal/phpqa:php7.3-alpine + with: + args: phpstan analyze + + php-cs-fixer: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Run PHP-CS-Fixer + uses: docker://jakzal/phpqa:php7.3-alpine + with: + args: php-cs-fixer fix --dry-run --diff-format udiff -vvv + + roave-bc-check: + name: Roave BC Check + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4fde49d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +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' ] + include: + - php: 7.4 + strategy: 'lowest' + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Download dependencies + uses: ramsey/composer-install@v1 + with: + dependency-versions: ${{ matrix.strategy }} + composer-options: --no-interaction --prefer-dist --optimize-autoloader + + - name: Run tests + run: ./vendor/bin/phpunit + diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml deleted file mode 100644 index 09e33c7..0000000 --- a/.github/workflows/continuous-integration.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: "Continuous Integration" - -on: - pull_request: - branches: - - "*" - - '!analysis-*' - push: - -env: - fail-fast: true - -jobs: - phpunit: - name: "PHPUnit" - runs-on: "ubuntu-20.04" - - strategy: - matrix: - php-version: - - "7.1" - - "7.2" - - "7.3" - - "7.4" - - "8.0" - coverage: - - "false" - dependencies: - - "highest" - include: - - dependencies: "lowest" - php-version: "7.3" - coverage: "true" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - with: - fetch-depth: 2 - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - ini-values: "zend.assertions=1" - - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "--prefer-dist" - - - name: "Run Tests" - if: matrix.coverage == 'false' - run: "composer test" - - - name: "Run Tests with coverage" - if: matrix.coverage == 'true' - run: "composer test-ci" - - - name: "Download ocular" - if: matrix.coverage == 'true' - run: "wget https://scrutinizer-ci.com/ocular.phar" - - - name: "Upload coverage" - if: matrix.coverage == 'true' - run: "php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml" - - diff --git a/.gitignore b/.gitignore index 16b4a20..ca07b30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -/behat.yml -/build/ +/.php_cs.cache /composer.lock -/phpspec.yml /phpunit.xml /vendor/ diff --git a/.php_cs b/.php_cs index 23ba165..2159fe4 100644 --- a/.php_cs +++ b/.php_cs @@ -1,13 +1,17 @@ setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->exclude(__DIR__.'/vendor') + ->name('*.php') + ) +; -use SLLH\StyleCIBridge\ConfigBridge; - -return ConfigBridge::create(); +return $config; diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index f7a088e..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,8 +0,0 @@ -filter: - excluded_paths: [vendor/*, Tests/*] -checks: - php: - code_rating: true - duplication: true -tools: - external_code_coverage: true diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 435b5fb..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,12 +0,0 @@ -preset: symfony - -finder: - exclude: - - "Resources" - - "vendor" - -enabled: - - short_array_syntax - -disabled: - - phpdoc_annotation_without_dot # This is still buggy: https://github.com/symfony/symfony/pull/19198 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0f64c04..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache - -branches: - except: - - /^analysis-.*$/ - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 -env: - global: - - TEST_COMMAND="composer test" - -matrix: - fast_finish: true - include: - - php: 7.3 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" - -install: - - travis_retry composer update --prefer-dist --no-interaction - -script: - - $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 47ba120..4d25b63 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,10 +1,20 @@ # Change Log -The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. + +## 1.2.0 + +### Added + +- Support for PHP 8 + +### Removed + +- Support for PHP < 7.2 ## 1.1.0 -### Added +### Added - Bing Translator - Support for HTTPlug 2.0 diff --git a/Readme.md b/Readme.md index b102081..98fa3d8 100644 --- a/Readme.md +++ b/Readme.md @@ -2,9 +2,6 @@ [![Latest Version](https://img.shields.io/github/release/php-translation/translator.svg?style=flat-square)](https://github.com/php-translation/translator/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -[![Build Status](https://img.shields.io/travis/php-translation/translator.svg?style=flat-square)](https://travis-ci.org/php-translation/translator) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-translation/translator.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-translation/translator) -[![Quality Score](https://img.shields.io/scrutinizer/g/php-translation/translator.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-translation/translator) [![Total Downloads](https://img.shields.io/packagist/dt/php-translation/translator.svg?style=flat-square)](https://packagist.org/packages/php-translation/translator) **Services that can be used to translate strings** diff --git a/composer.json b/composer.json index 476d669..29a1cf5 100644 --- a/composer.json +++ b/composer.json @@ -9,14 +9,14 @@ } ], "require": { - "php": "^5.6 || ^7.0 || ^8.0", + "php": "^7.2 || ^8.0", "php-http/httplug": "^1.0 || ^2.0", "php-http/client-implementation": "^1.0", "php-http/discovery": "^1.7", "psr/log": "~1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.2 || ^7.5 || ^8.4 || ^9.5", + "phpunit/phpunit": "^8.4", "nyholm/nsa": "^1.1", "php-http/curl-client": "^1.0 || ^2.0", "php-http/message": "^1.8", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..5076973 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,32 @@ +parameters: + ignoreErrors: + - + message: "#^Method Translation\\\\Translator\\\\Service\\\\BingTranslator\\:\\:getUrl\\(\\) invoked with 4 parameters, 2 required\\.$#" + count: 1 + path: src/Service/BingTranslator.php + + - + message: "#^Method Translation\\\\Translator\\\\Service\\\\BingTranslator\\:\\:translate\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: src/Service/BingTranslator.php + + - + message: "#^Method Translation\\\\Translator\\\\Service\\\\GoogleTranslator\\:\\:translate\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: src/Service/GoogleTranslator.php + + - + message: "#^Method Translation\\\\Translator\\\\Service\\\\YandexTranslator\\:\\:translate\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: src/Service/YandexTranslator.php + + - + message: "#^Method Translation\\\\Translator\\\\Translator\\:\\:translate\\(\\) should return string\\|null but empty return statement found\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^PHPDoc tag @throws with type Translation\\\\Translator\\\\Exception is not subtype of Throwable$#" + count: 1 + path: src/TranslatorService.php + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..d84c68a --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,9 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 3 + paths: + - src + excludes_analyse: + - vendor diff --git a/src/Service/BingTranslator.php b/src/Service/BingTranslator.php index de83dde..015793c 100644 --- a/src/Service/BingTranslator.php +++ b/src/Service/BingTranslator.php @@ -29,9 +29,7 @@ class BingTranslator extends HttpTranslator implements TranslatorService private $key; /** - * @param string $key Google API key - * @param HttpClient|null $httpClient - * @param RequestFactory|null $requestFactory + * @param string $key Google API key */ public function __construct($key, HttpClient $httpClient = null, RequestFactory $requestFactory = null) { @@ -56,7 +54,7 @@ public function translate($string, $from, $to) ->withHeader('Ocp-Apim-Subscription-Key', $this->key) ->withHeader('Content-Type', 'application/json') ->withHeader('X-ClientTraceId', $this->createGuid()) - ->withHeader('Content-length', strlen($body)); + ->withHeader('Content-length', \strlen($body)); /** @var ResponseInterface $response */ $response = $this->getHttpClient()->sendRequest($request); @@ -68,7 +66,7 @@ public function translate($string, $from, $to) $responseBody = $response->getBody()->__toString(); $data = json_decode($responseBody, true); - if (!is_array($data)) { + if (!\is_array($data)) { throw ResponseException::createUnexpectedResponse($url, $responseBody); } diff --git a/src/Service/GoogleTranslator.php b/src/Service/GoogleTranslator.php index 1067475..9c8e8d0 100644 --- a/src/Service/GoogleTranslator.php +++ b/src/Service/GoogleTranslator.php @@ -29,9 +29,7 @@ class GoogleTranslator extends HttpTranslator implements TranslatorService private $key; /** - * @param string $key Google API key - * @param HttpClient|null $httpClient - * @param RequestFactory|null $requestFactory + * @param string $key Google API key */ public function __construct($key, HttpClient $httpClient = null, RequestFactory $requestFactory = null) { @@ -61,7 +59,7 @@ public function translate($string, $from, $to) $responseBody = $response->getBody()->__toString(); $data = json_decode($responseBody, true); - if (!is_array($data)) { + if (!\is_array($data)) { throw ResponseException::createUnexpectedResponse($this->getUrl($string, $from, $to, '[key]'), $responseBody); } @@ -97,7 +95,7 @@ private function getUrl($string, $from, $to, $key) */ private function format($original, $translationHtmlEncoded) { - $translation = html_entity_decode($translationHtmlEncoded, ENT_QUOTES | ENT_HTML401, 'UTF-8'); + $translation = html_entity_decode($translationHtmlEncoded, \ENT_QUOTES | \ENT_HTML401, 'UTF-8'); // if capitalized, make sure we also capitalize. $firstChar = mb_substr($original, 0, 1); diff --git a/src/Service/YandexTranslator.php b/src/Service/YandexTranslator.php index b5dae91..a3ddb31 100644 --- a/src/Service/YandexTranslator.php +++ b/src/Service/YandexTranslator.php @@ -29,9 +29,7 @@ class YandexTranslator extends HttpTranslator implements TranslatorService private $key; /** - * @param string $key Google API key - * @param HttpClient|null $httpClient - * @param RequestFactory|null $requestFactory + * @param string $key Google API key */ public function __construct($key, HttpClient $httpClient = null, RequestFactory $requestFactory = null) { @@ -61,7 +59,7 @@ public function translate($string, $from, $to) $responseBody = $response->getBody()->__toString(); $data = json_decode($responseBody, true); - if (!is_array($data)) { + if (!\is_array($data)) { throw ResponseException::createUnexpectedResponse($this->getUrl($string, $from, $to, '[key]'), $responseBody); } diff --git a/src/Translator.php b/src/Translator.php index 2b34c69..5166875 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -39,7 +39,7 @@ final class Translator implements LoggerAwareInterface, TranslatorService * @param string $from * @param string $to * - * @return null|string Null is return when all translators failed. + * @return string|null null is return when all translators failed */ public function translate($string, $from, $to) { @@ -59,8 +59,6 @@ public function translate($string, $from, $to) } /** - * @param TranslatorService $thirdPartyService - * * @return Translator */ public function addTranslatorService(TranslatorService $thirdPartyService) @@ -75,7 +73,6 @@ public function addTranslatorService(TranslatorService $thirdPartyService) * * @param string $level * @param string $message - * @param array $context */ private function log($level, $message, array $context = []) { @@ -84,9 +81,6 @@ private function log($level, $message, array $context = []) } } - /** - * @param LoggerInterface $logger - */ public function setLogger(LoggerInterface $logger) { $this->logger = $logger;