diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 907b42d4..26c58025 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -4,30 +4,8 @@ on: pull_request: push: branches: - - '[0-9]+.[0-9]+.x' - - 'refs/pull/*' tags: jobs: - matrix: - name: Generate job matrix - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.matrix.outputs.matrix }} - steps: - - name: Gather CI configuration - id: matrix - uses: laminas/laminas-ci-matrix-action@v1 - - qa: - name: QA Checks - needs: [matrix] - runs-on: ${{ matrix.operatingSystem }} - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }} - steps: - - name: ${{ matrix.name }} - uses: laminas/laminas-continuous-integration-action@v1 - with: - job: ${{ matrix.job }} + ci: + uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index 6066f8b2..350ec35e 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -1,9 +1,3 @@ -# Alternate workflow example. -# This one is identical to the one in release-on-milestone.yml, with one change: -# the Release step uses the ORGANIZATION_ADMIN_TOKEN instead, to allow it to -# trigger a release workflow event. This is useful if you have other actions -# that intercept that event. - name: "Automatic Releases" on: @@ -13,59 +7,9 @@ on: jobs: release: - name: "GIT tag, release & create merge-up PR" - runs-on: ubuntu-latest - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Release" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:release" - env: - "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Create Merge-Up Pull Request" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:create-merge-up-pull-request" - env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Create and/or Switch to new Release Branch" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" - env: - "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Bump Changelog Version On Originating Release Branch" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:bump-changelog" - env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Create new milestones" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:create-milestones" - env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + uses: laminas/workflow-automatic-releases/.github/workflows/release-on-milestone-closed.yml@1.x + secrets: + GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} + GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} + ORGANIZATION_ADMIN_TOKEN: ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} + SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }} diff --git a/.gitignore b/.gitignore index a0c8ed86..d6ab07f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.phpunit.result.cache +/.phpcs-cache /clover.xml /coveralls-upload.json /docs/html/ diff --git a/composer.json b/composer.json index 84773b06..151b1a8b 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,13 @@ "forum": "https://discourse.laminas.dev" }, "config": { - "sort-packages": true + "sort-packages": true, + "platform": { + "php": "7.4.99" + }, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "extra": { "laminas": { @@ -25,7 +31,7 @@ } }, "require": { - "php": "^7.3 || ~8.0.0 || ~8.1.0", + "php": "^7.4 || ~8.0.0 || ~8.1.0", "ext-intl": "*", "laminas/laminas-stdlib": "^2.7 || ^3.0" }, @@ -33,13 +39,14 @@ "laminas/laminas-cache": "^3.1.2", "laminas/laminas-cache-storage-adapter-memory": "^2.0.0", "laminas/laminas-cache-storage-deprecated-factory": "^1.0.0", - "laminas/laminas-coding-standard": "~1.0.0", + "laminas/laminas-coding-standard": "~2.3.0", "laminas/laminas-config": "^3.4.0", "laminas/laminas-eventmanager": "^3.4.0", "laminas/laminas-filter": "^2.10.0", "laminas/laminas-servicemanager": "^3.7.0", "laminas/laminas-validator": "^2.14.0", "laminas/laminas-view": "^2.12.0", + "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.3", "psalm/plugin-phpunit": "^0.16.1", "vimeo/psalm": "^4.21" diff --git a/composer.lock b/composer.lock index b54044bf..3baa2457 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "109455d44aa71326cb7bc1e99b17ce86", + "content-hash": "8d30243037088a115387177bd3f315d1", "packages": [ { "name": "laminas/laminas-stdlib", - "version": "3.6.1", + "version": "3.7.1", "source": { "type": "git", "url": "https://github.com/laminas/laminas-stdlib.git", - "reference": "db581851a092246ad99e12d4fddf105184924c71" + "reference": "bcd869e2fe88d567800057c1434f2380354fe325" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/db581851a092246ad99e12d4fddf105184924c71", - "reference": "db581851a092246ad99e12d4fddf105184924c71", + "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/bcd869e2fe88d567800057c1434f2380354fe325", + "reference": "bcd869e2fe88d567800057c1434f2380354fe325", "shasum": "" }, "require": { @@ -28,8 +28,8 @@ }, "require-dev": { "laminas/laminas-coding-standard": "~2.3.0", - "phpbench/phpbench": "^0.17.1", - "phpunit/phpunit": "~9.3.7", + "phpbench/phpbench": "^1.0", + "phpunit/phpunit": "^9.3.7", "psalm/plugin-phpunit": "^0.16.0", "vimeo/psalm": "^4.7" }, @@ -63,7 +63,7 @@ "type": "community_bridge" } ], - "time": "2021-11-10T11:33:52+00:00" + "time": "2022-01-21T15:50:46+00:00" } ], "packages-dev": [ @@ -560,6 +560,81 @@ "abandoned": "psr/container", "time": "2017-02-14T19:40:03+00:00" }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.2", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2022-02-04T12:51:07+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "v0.1.1", @@ -993,31 +1068,36 @@ }, { "name": "laminas/laminas-coding-standard", - "version": "1.0.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-coding-standard.git", - "reference": "08880ce2fbfe62d471cd3cb766a91da630b32539" + "reference": "bcf6e07fe4690240be7beb6d884d0b0fafa6a251" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/08880ce2fbfe62d471cd3cb766a91da630b32539", - "reference": "08880ce2fbfe62d471cd3cb766a91da630b32539", + "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/bcf6e07fe4690240be7beb6d884d0b0fafa6a251", + "reference": "bcf6e07fe4690240be7beb6d884d0b0fafa6a251", "shasum": "" }, "require": { - "laminas/laminas-zendframework-bridge": "^1.0", - "squizlabs/php_codesniffer": "^2.7" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "php": "^7.3 || ^8.0", + "slevomat/coding-standard": "^7.0", + "squizlabs/php_codesniffer": "^3.6", + "webimpress/coding-standard": "^1.2" }, - "replace": { - "zendframework/zend-coding-standard": "self.version" + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "LaminasCodingStandard\\": "src/LaminasCodingStandard/" + } }, - "type": "library", "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], - "description": "Laminas coding standard", + "description": "Laminas Coding Standard", "homepage": "https://laminas.dev", "keywords": [ "Coding Standard", @@ -1031,42 +1111,44 @@ "rss": "https://github.com/laminas/laminas-coding-standard/releases.atom", "source": "https://github.com/laminas/laminas-coding-standard" }, - "time": "2019-12-31T16:28:26+00:00" + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2021-05-29T15:53:59+00:00" }, { "name": "laminas/laminas-config", - "version": "3.4.0", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-config.git", - "reference": "0bce6f5abab41dc673196741883b19018a2b5994" + "reference": "e43d13dcfc273d4392812eb395ce636f73f34dfd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-config/zipball/0bce6f5abab41dc673196741883b19018a2b5994", - "reference": "0bce6f5abab41dc673196741883b19018a2b5994", + "url": "https://api.github.com/repos/laminas/laminas-config/zipball/e43d13dcfc273d4392812eb395ce636f73f34dfd", + "reference": "e43d13dcfc273d4392812eb395ce636f73f34dfd", "shasum": "" }, "require": { "ext-json": "*", - "laminas/laminas-stdlib": "^2.7.7 || ^3.1", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.3 || ^8.0", + "laminas/laminas-stdlib": "^3.6", + "php": "^7.3 || ~8.0.0 || ~8.1.0", "psr/container": "^1.0" }, "conflict": { - "container-interop/container-interop": "<1.2.0" - }, - "replace": { - "zendframework/zend-config": "^3.3.0" + "container-interop/container-interop": "<1.2.0", + "zendframework/zend-config": "*" }, "require-dev": { "laminas/laminas-coding-standard": "~1.0.0", "laminas/laminas-filter": "^2.7.2", "laminas/laminas-i18n": "^2.10.3", - "laminas/laminas-servicemanager": "^3.4.1", - "malukenho/docheader": "^0.1.6", - "phpunit/phpunit": "^8.5.8" + "laminas/laminas-servicemanager": "^3.7", + "phpunit/phpunit": "^9.5.5" }, "suggest": { "laminas/laminas-filter": "^2.7.2; install if you want to use the Filter processor", @@ -1074,12 +1156,6 @@ "laminas/laminas-servicemanager": "^2.7.8 || ^3.3; if you need an extensible plugin manager for use with the Config Factory" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4.x-dev", - "dev-develop": "3.5.x-dev" - } - }, "autoload": { "psr-4": { "Laminas\\Config\\": "src/" @@ -1109,7 +1185,7 @@ "type": "community_bridge" } ], - "time": "2020-08-25T11:56:37+00:00" + "time": "2021-10-01T16:07:46+00:00" }, { "name": "laminas/laminas-eventmanager", @@ -1179,38 +1255,37 @@ }, { "name": "laminas/laminas-filter", - "version": "2.10.0", + "version": "2.13.2", "source": { "type": "git", "url": "https://github.com/laminas/laminas-filter.git", - "reference": "cfb40b104e92a0b52bee696b74f958798ad8faa4" + "reference": "3da1df596b023fb0387a1dbb0e77e536afd9d1af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-filter/zipball/cfb40b104e92a0b52bee696b74f958798ad8faa4", - "reference": "cfb40b104e92a0b52bee696b74f958798ad8faa4", + "url": "https://api.github.com/repos/laminas/laminas-filter/zipball/3da1df596b023fb0387a1dbb0e77e536afd9d1af", + "reference": "3da1df596b023fb0387a1dbb0e77e536afd9d1af", "shasum": "" }, "require": { - "laminas/laminas-stdlib": "^3.3", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.3 || ~8.0.0" + "laminas/laminas-stdlib": "^3.6.1", + "php": "^7.4 || ~8.0.0 || ~8.1.0" }, "conflict": { - "laminas/laminas-validator": "<2.10.1" - }, - "replace": { - "zendframework/zend-filter": "^2.9.2" + "laminas/laminas-validator": "<2.10.1", + "zendframework/zend-filter": "*" }, "require-dev": { - "laminas/laminas-coding-standard": "~1.0.0", - "laminas/laminas-crypt": "^3.2.1", - "laminas/laminas-servicemanager": "^3.3", - "laminas/laminas-uri": "^2.6", - "pear/archive_tar": "^1.4.3", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.3", - "psr/http-factory": "^1.0" + "laminas/laminas-coding-standard": "^2.3.0", + "laminas/laminas-crypt": "^3.5.1", + "laminas/laminas-servicemanager": "^3.7.0", + "laminas/laminas-uri": "^2.9.1", + "pear/archive_tar": "^1.4.14", + "phpspec/prophecy-phpunit": "^2.0.1", + "phpunit/phpunit": "^9.5.10", + "psalm/plugin-phpunit": "^0.15.2", + "psr/http-factory": "^1.0.1", + "vimeo/psalm": "^4.13.1" }, "suggest": { "laminas/laminas-crypt": "Laminas\\Crypt component, for encryption filters", @@ -1255,50 +1330,38 @@ "type": "community_bridge" } ], - "time": "2021-01-01T14:37:45+00:00" + "time": "2022-02-07T13:14:03+00:00" }, { "name": "laminas/laminas-json", - "version": "2.6.1", + "version": "3.3.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-json.git", - "reference": "db58425b7f0eba44a7539450cc926af80915951a" + "reference": "9a0ce9f330b7d11e70c4acb44d67e8c4f03f437f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-json/zipball/db58425b7f0eba44a7539450cc926af80915951a", - "reference": "db58425b7f0eba44a7539450cc926af80915951a", + "url": "https://api.github.com/repos/laminas/laminas-json/zipball/9a0ce9f330b7d11e70c4acb44d67e8c4f03f437f", + "reference": "9a0ce9f330b7d11e70c4acb44d67e8c4f03f437f", "shasum": "" }, "require": { - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^5.5 || ^7.0" + "php": "^7.3 || ~8.0.0 || ~8.1.0" }, - "replace": { - "zendframework/zend-json": "self.version" + "conflict": { + "zendframework/zend-json": "*" }, "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", - "laminas/laminas-http": "^2.5.4", - "laminas/laminas-server": "^2.6.1", - "laminas/laminas-stdlib": "^2.5 || ^3.0", - "laminas/laminas-xml": "^1.0.2", - "phpunit/phpunit": "~4.0" + "laminas/laminas-coding-standard": "~2.2.1", + "laminas/laminas-stdlib": "^2.7.7 || ^3.1", + "phpunit/phpunit": "^9.3" }, "suggest": { - "laminas/laminas-http": "Laminas\\Http component, required to use Laminas\\Json\\Server", - "laminas/laminas-server": "Laminas\\Server component, required to use Laminas\\Json\\Server", - "laminas/laminas-stdlib": "Laminas\\Stdlib component, for use with caching Laminas\\Json\\Server responses", - "laminas/laminas-xml": "To support Laminas\\Json\\Json::fromXml() usage" + "laminas/laminas-json-server": "For implementing JSON-RPC servers", + "laminas/laminas-xml2json": "For converting XML documents to JSON" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev", - "dev-develop": "2.7-dev" - } - }, "autoload": { "psr-4": { "Laminas\\Json\\": "src/" @@ -1322,106 +1385,53 @@ "rss": "https://github.com/laminas/laminas-json/releases.atom", "source": "https://github.com/laminas/laminas-json" }, - "time": "2019-12-31T17:15:00+00:00" - }, - { - "name": "laminas/laminas-loader", - "version": "2.5.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-loader.git", - "reference": "2a4e1442507e950a114d3752a848b52ace9f0ad2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-loader/zipball/2a4e1442507e950a114d3752a848b52ace9f0ad2", - "reference": "2a4e1442507e950a114d3752a848b52ace9f0ad2", - "shasum": "" - }, - "require": { - "laminas/laminas-zendframework-bridge": "^1.0", - "php": ">=5.3.23" - }, - "replace": { - "zendframework/zend-loader": "self.version" - }, - "require-dev": { - "fabpot/php-cs-fixer": "1.7.*", - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.5-dev", - "dev-develop": "2.6-dev" - } - }, - "autoload": { - "psr-4": { - "Laminas\\Loader\\": "src/" + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" ], - "homepage": "https://laminas.dev", - "keywords": [ - "laminas", - "loader" - ], - "support": { - "chat": "https://laminas.dev/chat", - "docs": "https://docs.laminas.dev/laminas-loader/", - "forum": "https://discourse.laminas.dev", - "issues": "https://github.com/laminas/laminas-loader/issues", - "rss": "https://github.com/laminas/laminas-loader/releases.atom", - "source": "https://github.com/laminas/laminas-loader" - }, - "time": "2019-12-31T17:18:24+00:00" + "time": "2021-09-02T18:02:31+00:00" }, { "name": "laminas/laminas-servicemanager", - "version": "3.7.0", + "version": "3.10.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-servicemanager.git", - "reference": "2b0aee477fdbd3191af7c302b93dbc5fda0626f4" + "reference": "e52b985909e0940bf22d34f322eb3f48bbef6bd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/2b0aee477fdbd3191af7c302b93dbc5fda0626f4", - "reference": "2b0aee477fdbd3191af7c302b93dbc5fda0626f4", + "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/e52b985909e0940bf22d34f322eb3f48bbef6bd1", + "reference": "e52b985909e0940bf22d34f322eb3f48bbef6bd1", "shasum": "" }, "require": { "container-interop/container-interop": "^1.2", "laminas/laminas-stdlib": "^3.2.1", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.3 || ~8.0.0", + "php": "~7.4.0 || ~8.0.0 || ~8.1.0", "psr/container": "^1.0" }, "conflict": { "laminas/laminas-code": "<3.3.1", - "zendframework/zend-code": "<3.3.1" + "zendframework/zend-code": "<3.3.1", + "zendframework/zend-servicemanager": "*" }, "provide": { "container-interop/container-interop-implementation": "^1.2", "psr/container-implementation": "^1.0" }, - "replace": { - "zendframework/zend-servicemanager": "^3.4.0" - }, "require-dev": { "composer/package-versions-deprecated": "^1.0", - "laminas/laminas-coding-standard": "~2.2.0", + "laminas/laminas-coding-standard": "~2.2.1", "laminas/laminas-container-config-test": "^0.3", "laminas/laminas-dependency-plugin": "^2.1.2", - "mikey179/vfsstream": "^1.6.8", - "ocramius/proxy-manager": "^2.2.3", - "phpbench/phpbench": "^1.0.4", + "mikey179/vfsstream": "^1.6.10@alpha", + "ocramius/proxy-manager": "^2.11", + "phpbench/phpbench": "^1.1", "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.4", + "phpunit/phpunit": "^9.5.5", "psalm/plugin-phpunit": "^0.16.1", "vimeo/psalm": "^4.8" }, @@ -1467,35 +1477,33 @@ "type": "community_bridge" } ], - "time": "2021-07-24T19:33:07+00:00" + "time": "2021-09-18T20:19:36+00:00" }, { "name": "laminas/laminas-validator", - "version": "2.14.0", + "version": "2.16.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-validator.git", - "reference": "8da5e20ed7b2b8101c1de68ca8dc0180210ed23e" + "reference": "329900ab7674c198e91e85b2e09080cdf493ce07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/8da5e20ed7b2b8101c1de68ca8dc0180210ed23e", - "reference": "8da5e20ed7b2b8101c1de68ca8dc0180210ed23e", + "url": "https://api.github.com/repos/laminas/laminas-validator/zipball/329900ab7674c198e91e85b2e09080cdf493ce07", + "reference": "329900ab7674c198e91e85b2e09080cdf493ce07", "shasum": "" }, "require": { "container-interop/container-interop": "^1.1", - "laminas/laminas-stdlib": "^3.3", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.3 || ~8.0.0" + "laminas/laminas-stdlib": "^3.6", + "php": "^7.3 || ~8.0.0 || ~8.1.0" }, - "replace": { - "zendframework/zend-validator": "^2.13.0" + "conflict": { + "zendframework/zend-validator": "*" }, "require-dev": { "laminas/laminas-cache": "^2.6.1", - "laminas/laminas-coding-standard": "~1.0.0", - "laminas/laminas-config": "^2.6", + "laminas/laminas-coding-standard": "~2.2.1", "laminas/laminas-db": "^2.7", "laminas/laminas-filter": "^2.6", "laminas/laminas-http": "^2.14.2", @@ -1505,7 +1513,7 @@ "laminas/laminas-session": "^2.8", "laminas/laminas-uri": "^2.7", "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": "^9.5.5", "psalm/plugin-phpunit": "^0.15.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", @@ -1559,61 +1567,61 @@ "type": "community_bridge" } ], - "time": "2021-01-07T16:07:31+00:00" + "time": "2022-01-21T14:30:01+00:00" }, { "name": "laminas/laminas-view", - "version": "2.12.0", + "version": "2.19.1", "source": { "type": "git", "url": "https://github.com/laminas/laminas-view.git", - "reference": "3ef103da6887809f08ecf52f42c31a76c9bf08b1" + "reference": "5f2ed1af896543e986090afb6433e32409c99d4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-view/zipball/3ef103da6887809f08ecf52f42c31a76c9bf08b1", - "reference": "3ef103da6887809f08ecf52f42c31a76c9bf08b1", + "url": "https://api.github.com/repos/laminas/laminas-view/zipball/5f2ed1af896543e986090afb6433e32409c99d4d", + "reference": "5f2ed1af896543e986090afb6433e32409c99d4d", "shasum": "" }, "require": { - "laminas/laminas-eventmanager": "^3.0", - "laminas/laminas-json": "^2.6.1 || ^3.0", - "laminas/laminas-loader": "^2.5", - "laminas/laminas-stdlib": "^3.2.1", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.3 || ~8.0.0" + "ext-json": "*", + "laminas/laminas-eventmanager": "^3.4", + "laminas/laminas-json": "^3.3", + "laminas/laminas-stdlib": "^3.6", + "php": "^7.4 || ~8.0.0 || ~8.1.0" }, "conflict": { - "laminas/laminas-servicemanager": "<3.3" - }, - "replace": { - "zendframework/zend-view": "^2.11.4" + "container-interop/container-interop": "<1.2", + "laminas/laminas-router": "<3.0.1", + "laminas/laminas-servicemanager": "<3.3", + "laminas/laminas-session": "<2.12", + "zendframework/zend-view": "*" }, "require-dev": { + "ext-dom": "*", "laminas/laminas-authentication": "^2.5", - "laminas/laminas-cache": "^2.6.1", - "laminas/laminas-coding-standard": "~1.0.0", - "laminas/laminas-config": "^2.6", + "laminas/laminas-coding-standard": "~2.3.0", "laminas/laminas-console": "^2.6", "laminas/laminas-escaper": "^2.5", - "laminas/laminas-feed": "^2.7", - "laminas/laminas-filter": "^2.6.1", - "laminas/laminas-http": "^2.5.4", + "laminas/laminas-feed": "^2.15", + "laminas/laminas-filter": "^2.13.0", + "laminas/laminas-http": "^2.15", "laminas/laminas-i18n": "^2.6", - "laminas/laminas-log": "^2.7", "laminas/laminas-modulemanager": "^2.7.1", - "laminas/laminas-mvc": "^2.7.14 || ^3.0", - "laminas/laminas-navigation": "^2.5", - "laminas/laminas-paginator": "^2.5", + "laminas/laminas-mvc": "^3.0", + "laminas/laminas-mvc-i18n": "^1.1", + "laminas/laminas-mvc-plugin-flashmessenger": "^1.5.0", + "laminas/laminas-navigation": "^2.13.1", + "laminas/laminas-paginator": "^2.11.0", "laminas/laminas-permissions-acl": "^2.6", "laminas/laminas-router": "^3.0.1", - "laminas/laminas-serializer": "^2.6.1", - "laminas/laminas-servicemanager": "^3.3", - "laminas/laminas-session": "^2.8.1", + "laminas/laminas-servicemanager": "^3.4", "laminas/laminas-uri": "^2.5", "phpspec/prophecy": "^1.12", "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.5.5", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.10" }, "suggest": { "laminas/laminas-authentication": "Laminas\\Authentication component", @@ -1663,69 +1671,7 @@ "type": "community_bridge" } ], - "time": "2021-01-01T14:07:41+00:00" - }, - { - "name": "laminas/laminas-zendframework-bridge", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-zendframework-bridge.git", - "reference": "bf180a382393e7db5c1e8d0f2ec0c4af9c724baf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/bf180a382393e7db5c1e8d0f2ec0c4af9c724baf", - "reference": "bf180a382393e7db5c1e8d0f2ec0c4af9c724baf", - "shasum": "" - }, - "require": { - "php": "^7.3 || ~8.0.0 || ~8.1.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.3", - "psalm/plugin-phpunit": "^0.15.1", - "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "^4.6" - }, - "type": "library", - "extra": { - "laminas": { - "module": "Laminas\\ZendFrameworkBridge" - } - }, - "autoload": { - "files": [ - "src/autoload.php" - ], - "psr-4": { - "Laminas\\ZendFrameworkBridge\\": "src//" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Alias legacy ZF class names to Laminas Project equivalents.", - "keywords": [ - "ZendFramework", - "autoloading", - "laminas", - "zf" - ], - "support": { - "forum": "https://discourse.laminas.dev/", - "issues": "https://github.com/laminas/laminas-zendframework-bridge/issues", - "rss": "https://github.com/laminas/laminas-zendframework-bridge/releases.atom", - "source": "https://github.com/laminas/laminas-zendframework-bridge" - }, - "funding": [ - { - "url": "https://funding.communitybridge.org/projects/laminas-project", - "type": "community_bridge" - } - ], - "time": "2021-09-03T17:53:30+00:00" + "time": "2022-01-12T16:20:05+00:00" }, { "name": "myclabs/deep-copy", @@ -1744,9 +1690,6 @@ "require": { "php": "^7.1 || ^8.0" }, - "replace": { - "myclabs/deep-copy": "self.version" - }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", @@ -1754,12 +1697,12 @@ }, "type": "library", "autoload": { - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - }, "files": [ "src/DeepCopy/deep_copy.php" - ] + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1947,16 +1890,16 @@ }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { @@ -2001,22 +1944,22 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/master" + "source": "https://github.com/phar-io/manifest/tree/2.0.3" }, - "time": "2020-06-27T14:33:11+00:00" + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", - "version": "3.1.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "bae7c545bef187884426f042434e561ab1ddb182" + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", - "reference": "bae7c545bef187884426f042434e561ab1ddb182", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", "shasum": "" }, "require": { @@ -2052,9 +1995,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.1.0" + "source": "https://github.com/phar-io/version/tree/3.2.1" }, - "time": "2021-02-23T14:00:09+00:00" + "time": "2022-02-21T01:04:05+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -2218,33 +2161,33 @@ }, { "name": "phpspec/prophecy", - "version": "1.13.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.1", + "php": "^7.2 || ~8.0, <8.2", "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^6.0", + "phpspec/phpspec": "^6.0 || ^7.0", "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { @@ -2279,29 +2222,130 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.13.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" + }, + "time": "2021-12-08T12:19:24+00:00" + }, + { + "name": "phpspec/prophecy-phpunit", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy-phpunit.git", + "reference": "2d7a9df55f257d2cba9b1d0c0963a54960657177" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/2d7a9df55f257d2cba9b1d0c0963a54960657177", + "reference": "2d7a9df55f257d2cba9b1d0c0963a54960657177", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8", + "phpspec/prophecy": "^1.3", + "phpunit/phpunit": "^9.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\PhpUnit\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + } + ], + "description": "Integrating the Prophecy mocking library in PHPUnit test cases", + "homepage": "http://phpspec.net", + "keywords": [ + "phpunit", + "prophecy" + ], + "support": { + "issues": "https://github.com/phpspec/prophecy-phpunit/issues", + "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.0.1" + }, + "time": "2020-07-09T08:33:42+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.2.0" }, - "time": "2021-03-17T13:42:18+00:00" + "time": "2021-09-16T20:46:02+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.6", + "version": "9.2.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f6293e1b30a2354e8428e004689671b83871edde" + "reference": "665a1ac0a763c51afc30d6d130dac0813092b17f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", - "reference": "f6293e1b30a2354e8428e004689671b83871edde", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/665a1ac0a763c51afc30d6d130dac0813092b17f", + "reference": "665a1ac0a763c51afc30d6d130dac0813092b17f", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.10.2", + "nikic/php-parser": "^4.13.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -2350,7 +2394,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.11" }, "funding": [ { @@ -2358,20 +2402,20 @@ "type": "github" } ], - "time": "2021-03-28T07:26:59+00:00" + "time": "2022-02-18T12:46:09+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.5", + "version": "3.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", "shasum": "" }, "require": { @@ -2410,7 +2454,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" }, "funding": [ { @@ -2418,7 +2462,7 @@ "type": "github" } ], - "time": "2020-09-28T05:57:25+00:00" + "time": "2021-12-02T12:48:52+00:00" }, { "name": "phpunit/php-invoker", @@ -2603,16 +2647,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.4", + "version": "9.5.14", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c73c6737305e779771147af66c96ca6a7ed8a741" + "reference": "1883687169c017d6ae37c58883ca3994cfc34189" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", - "reference": "c73c6737305e779771147af66c96ca6a7ed8a741", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1883687169c017d6ae37c58883ca3994cfc34189", + "reference": "1883687169c017d6ae37c58883ca3994cfc34189", "shasum": "" }, "require": { @@ -2624,11 +2668,11 @@ "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.1", + "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.3", + "phpunit/php-code-coverage": "^9.2.7", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -2642,7 +2686,7 @@ "sebastian/global-state": "^5.0.1", "sebastian/object-enumerator": "^4.0.3", "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^2.3", + "sebastian/type": "^2.3.4", "sebastian/version": "^3.0.2" }, "require-dev": { @@ -2663,11 +2707,11 @@ } }, "autoload": { - "classmap": [ - "src/" - ], "files": [ "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -2690,11 +2734,11 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.14" }, "funding": [ { - "url": "https://phpunit.de/donate.html", + "url": "https://phpunit.de/sponsors.html", "type": "custom" }, { @@ -2702,7 +2746,7 @@ "type": "github" } ], - "time": "2021-03-23T07:16:29+00:00" + "time": "2022-02-18T12:54:07+00:00" }, { "name": "psalm/plugin-phpunit", @@ -2815,20 +2859,20 @@ }, { "name": "psr/container", - "version": "1.1.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/php-fig/container.git", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf" + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf", + "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", "shasum": "" }, "require": { - "php": ">=7.2.0" + "php": ">=7.4.0" }, "type": "library", "autoload": { @@ -2857,9 +2901,9 @@ ], "support": { "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.1" + "source": "https://github.com/php-fig/container/tree/1.1.2" }, - "time": "2021-03-05T17:36:06+00:00" + "time": "2021-11-05T16:50:12+00:00" }, { "name": "psr/log", @@ -2913,16 +2957,16 @@ }, { "name": "psr/simple-cache", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/simple-cache.git", - "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24" + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/753fa598e8f3b9966c886fe13f370baa45ef0e24", - "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", "shasum": "" }, "require": { @@ -2958,9 +3002,9 @@ "simple-cache" ], "support": { - "source": "https://github.com/php-fig/simple-cache/tree/1.0.0" + "source": "https://github.com/php-fig/simple-cache/tree/master" }, - "time": "2017-01-02T13:31:39+00:00" + "time": "2017-10-23T01:57:42+00:00" }, { "name": "sebastian/cli-parser", @@ -3391,16 +3435,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65" + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9", + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9", "shasum": "" }, "require": { @@ -3449,14 +3493,14 @@ } ], "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", + "homepage": "https://www.github.com/sebastianbergmann/exporter", "keywords": [ "export", "exporter" ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4" }, "funding": [ { @@ -3464,20 +3508,20 @@ "type": "github" } ], - "time": "2020-09-28T05:24:23+00:00" + "time": "2021-11-11T14:18:36+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.2", + "version": "5.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "a90ccbddffa067b51f574dea6eb25d5680839455" + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/a90ccbddffa067b51f574dea6eb25d5680839455", - "reference": "a90ccbddffa067b51f574dea6eb25d5680839455", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", "shasum": "" }, "require": { @@ -3520,7 +3564,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.2" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" }, "funding": [ { @@ -3528,7 +3572,7 @@ "type": "github" } ], - "time": "2020-10-26T15:55:19+00:00" + "time": "2022-02-14T08:28:10+00:00" }, { "name": "sebastian/lines-of-code", @@ -3819,16 +3863,16 @@ }, { "name": "sebastian/type", - "version": "2.3.1", + "version": "2.3.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2" + "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/81cd61ab7bbf2de744aba0ea61fae32f721df3d2", - "reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914", + "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914", "shasum": "" }, "require": { @@ -3863,7 +3907,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/2.3.1" + "source": "https://github.com/sebastianbergmann/type/tree/2.3.4" }, "funding": [ { @@ -3871,7 +3915,7 @@ "type": "github" } ], - "time": "2020-10-26T13:18:59+00:00" + "time": "2021-06-15T12:49:02+00:00" }, { "name": "sebastian/version", @@ -3926,66 +3970,100 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "7.0.18", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "reference": "b81ac84f41a4797dc25c8ede1b0718e2a74be0fc", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.1 || ^8.0", + "phpstan/phpdoc-parser": "^1.0.0", + "squizlabs/php_codesniffer": "^3.6.1" + }, + "require-dev": { + "phing/phing": "2.17.0", + "php-parallel-lint/php-parallel-lint": "1.3.1", + "phpstan/phpstan": "1.2.0", + "phpstan/phpstan-deprecation-rules": "1.0.0", + "phpstan/phpstan-phpunit": "1.0.0", + "phpstan/phpstan-strict-rules": "1.1.0", + "phpunit/phpunit": "7.5.20|8.5.21|9.5.10" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/7.0.18" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2021-12-07T17:19:06+00:00" + }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.2", + "version": "3.6.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "2acf168de78487db620ab4bc524135a13cfe6745" + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745", - "reference": "2acf168de78487db620ab4bc524135a13cfe6745", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", + "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -3997,7 +4075,7 @@ } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", "standards" @@ -4007,7 +4085,7 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2018-11-07T22:31:41+00:00" + "time": "2021-12-12T21:44:58+00:00" }, { "name": "symfony/console", @@ -4838,16 +4916,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -4876,7 +4954,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/master" + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" }, "funding": [ { @@ -4884,7 +4962,7 @@ "type": "github" } ], - "time": "2020-07-12T23:59:07+00:00" + "time": "2021-07-28T10:34:58+00:00" }, { "name": "vimeo/psalm", @@ -4992,6 +5070,61 @@ }, "time": "2022-02-18T04:34:15+00:00" }, + { + "name": "webimpress/coding-standard", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/webimpress/coding-standard.git", + "reference": "cd0c4b0b97440c337c1f7da17b524674ca2f9ca9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webimpress/coding-standard/zipball/cd0c4b0b97440c337c1f7da17b524674ca2f9ca9", + "reference": "cd0c4b0b97440c337c1f7da17b524674ca2f9ca9", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "squizlabs/php_codesniffer": "^3.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.13" + }, + "type": "phpcodesniffer-standard", + "extra": { + "dev-master": "1.2.x-dev", + "dev-develop": "1.3.x-dev" + }, + "autoload": { + "psr-4": { + "WebimpressCodingStandard\\": "src/WebimpressCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "description": "Webimpress Coding Standard", + "keywords": [ + "Coding Standard", + "PSR-2", + "phpcs", + "psr-12", + "webimpress" + ], + "support": { + "issues": "https://github.com/webimpress/coding-standard/issues", + "source": "https://github.com/webimpress/coding-standard/tree/1.2.4" + }, + "funding": [ + { + "url": "https://github.com/michalbundyra", + "type": "github" + } + ], + "time": "2022-02-15T19:52:12+00:00" + }, { "name": "webmozart/assert", "version": "1.10.0", @@ -5108,9 +5241,12 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.3 || ~8.0.0 || ~8.1.0", + "php": "^7.4 || ~8.0.0 || ~8.1.0", "ext-intl": "*" }, "platform-dev": [], + "platform-overrides": { + "php": "7.4.99" + }, "plugin-api-version": "2.2.0" } diff --git a/phpcs.xml b/phpcs.xml index 594b9f78..8e914eb2 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,10 +1,24 @@  - - + + + + + + + + + + src test src/Validator/PhoneNumber/* */_files/* - \ No newline at end of file + + + src/ + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9b70c896..53f16c60 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="./vendor/autoload.php" + convertDeprecationsToExceptions="true" colors="true"> @@ -24,10 +25,5 @@ - - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 15630b88..26661a56 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,29 @@ + + + + \Zend\I18n\Filter\Alnum + \Zend\I18n\Filter\Alpha + \Zend\I18n\Filter\NumberFormat + \Zend\I18n\Filter\NumberParse + \Zend\I18n\Translator\LoaderPluginManager + \Zend\I18n\Translator\TranslatorInterface + \Zend\I18n\Validator\Alnum + \Zend\I18n\Validator\Alpha + \Zend\I18n\Validator\DateTime + \Zend\I18n\Validator\IsFloat + \Zend\I18n\Validator\IsInt + \Zend\I18n\Validator\PhoneNumber + \Zend\I18n\Validator\PostCode + \Zend\I18n\View\Helper\CurrencyFormat + \Zend\I18n\View\Helper\DateFormat + \Zend\I18n\View\Helper\NumberFormat + \Zend\I18n\View\Helper\Plural + \Zend\I18n\View\Helper\Translate + \Zend\I18n\View\Helper\TranslatePlural + + string @@ -29,8 +53,9 @@ $allowWhiteSpaceOrOptions $allowWhiteSpaceOrOptions - + (bool) $flag + (string) $value @@ -56,31 +81,24 @@ $this->formatter === null - - $value - - - $this->options['style'] - $this->options['type'] - - - $this->options['locale'] + $this->options['style'] $this->options['type'] - - - $this->options - $this->options - $this->options - - + + int int - - + + + $value + + + $options + + $this->options['style'] $this->options['type'] - + null null @@ -95,7 +113,7 @@ - \Laminas\ModuleManager\ModuleManager + ModuleManager @@ -178,9 +196,6 @@ is_array($this->messages) - - $messages - $textDomain['']['plural_forms'] $this->messages[$textDomain][$locale] @@ -189,29 +204,36 @@ $textDomain['']['plural_forms'] $this->messages[$textDomain][$locale] - - $this->messages - validatePlugin + + + + $aliases + $factories + $plugin + + Gettext + Ini + PhpArray + LoaderPluginManagerFactory - - $creationOptions - - + $config['translator_plugins'] - $this->creationOptions + + $options + $container @@ -393,6 +415,8 @@ $file['filename'] $file['filename'] $file['filename'] + $file['locale'] ?? null + $file['text_domain'] ?? 'default' $file['type'] $file['type'] $loaderType @@ -400,15 +424,13 @@ $pattern['base_dir'] $pattern['pattern'] $pattern['pattern'] + $pattern['text_domain'] ?? 'default' $pattern['type'] $pattern['type'] + $remote['text_domain'] ?? 'default' $remote['type'] array_shift($locales) array_shift($locales) - isset($file['locale']) ? $file['locale'] : null - isset($file['text_domain']) ? $file['text_domain'] : 'default' - isset($pattern['text_domain']) ? $pattern['text_domain'] : 'default' - isset($remote['text_domain']) ? $remote['text_domain'] : 'default' $file['filename'] @@ -548,9 +570,6 @@ $value - - $this->pattern - $formatter @@ -584,10 +603,6 @@ is_bool($strict) - - $value - $value - $options['locale'] $options['strict'] @@ -648,8 +663,7 @@ ! is_string($value) && ! is_int($value) - - $value + $value $value @@ -683,6 +697,11 @@ $this->locale === null + + $currencyCode + $currencyPattern + $locale + $formattedNumber $this->formatters[$formatterId] @@ -704,11 +723,6 @@ $formattedNumber - - $currencyCode - $currencyPattern - $locale - (bool) $showDecimals (string) $locale @@ -721,32 +735,12 @@ $this->locale === null - - $formatter - - - string - - - $setTimeZoneMethodName - format - - - $this->formatters[$formatterId]->format($date) - - - $pattern - - - $pattern - - + $locale $timezone - - + + (string) $locale - (string) $timezone @@ -755,6 +749,12 @@ null === $this->formatStyle null === $this->formatType + + $decimals + $formatStyle + $formatType + $locale + $value @@ -774,12 +774,6 @@ $formatter->format($number, $formatType) - - $decimals - $formatStyle - $formatType - $locale - (int) $formatStyle (int) $formatType @@ -793,25 +787,30 @@ null === $this->getPluralRule() + + $rule + string $strings[$pluralIndex] - - $rule - + + array + $factory $target - + $alias $name + $this->toArray() + $factory $target @@ -819,83 +818,25 @@ method_exists($serviceManager, 'configure') + + \Zend\I18n\View\Helper\CurrencyFormat + \Zend\I18n\View\Helper\DateFormat + \Zend\I18n\View\Helper\NumberFormat + \Zend\I18n\View\Helper\Plural + \Zend\I18n\View\Helper\Translate + \Zend\I18n\View\Helper\TranslatePlural + - - $input - - - returnUnfilteredDataProvider - testFilterSupportArray - $input - - $input - - - returnUnfilteredDataProvider - testFilterSupportArray - $input - - - $expected - $expected - $input - $locale - $locale - $style - $style - $type - $type - $value - $value - - - formattedToNumberProvider - numberToFormattedProvider - returnUnfilteredDataProvider - testConstructWithOptions - testConstructWithParameters - testFormattedToNumber - testNumberToFormatted - - - $locale - $locale - $style - $style - $type - $type - - - - - $expected - $locale - $style - $type - $value - - - formattedToNumberProvider - testConstructWithOptions - testConstructWithParameters - testFormattedToNumber - - - $locale - $style - $type - - testConfigReturnsExpectedKeys @@ -914,10 +855,6 @@ - - $default - $name - getParam @@ -932,42 +869,12 @@ addServiceManager + + + assertNotNull + + - - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Translator\TextDomain' - 'Laminas\I18n\Translator\TextDomain' - - - $originalIncludePath - $originalLocale - $testFilesDir - - - testLoaderFailsToLoadBadFile - testLoaderFailsToLoadMissingFile - testLoaderLoadsBigEndianFile - testLoaderLoadsEmptyFile - testLoaderLoadsFromIncludePath - testLoaderLoadsFromPhar - testLoaderLoadsPlural - testLoaderLoadsPluralRules - testLoaderReturnsValidTextDomain - - - $this->originalIncludePath - $this->originalLocale - - - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - evaluate evaluate @@ -976,42 +883,6 @@ - - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Translator\TextDomain' - - - $originalIncludePath - $originalLocale - $testFilesDir - - - testLoaderFailsToLoadBadSyntax - testLoaderFailsToLoadMissingFile - testLoaderFailsToLoadNonArray - testLoaderLoadsEmptyFile - testLoaderLoadsFromIncludePath - testLoaderLoadsFromPhar - testLoaderLoadsPluralRules - testLoaderReturnsValidTextDomain - testLoaderReturnsValidTextDomainWithFileWithoutPlural - testLoaderReturnsValidTextDomainWithSimpleSyntax - - - $this->originalIncludePath - - - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - evaluate evaluate @@ -1020,36 +891,6 @@ - - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Translator\TextDomain' - - - $originalIncludePath - $originalLocale - $testFilesDir - - - testLoaderFailsToLoadMissingFile - testLoaderFailsToLoadNonArray - testLoaderLoadsEmptyArray - testLoaderLoadsFromIncludePath - testLoaderLoadsFromPhar - testLoaderLoadsPluralRules - testLoaderReturnsValidTextDomain - - - $this->originalIncludePath - $this->originalLocale - - - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - evaluate evaluate @@ -1058,33 +899,14 @@ - - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Exception\InvalidArgumentException' - 'Laminas\I18n\Translator\TextDomain' - - - $originalIncludePath - $originalLocale - $testFilesDir - - - testLoaderFailsToLoadMissingTextDomain - testLoaderFailsToLoadNonArray - testLoaderFailsToLoadNonArrayLocale - testLoaderLoadsEmptyArray - testLoaderLoadsPluralRules - testLoaderReturnsValidTextDomain - - - $this->originalLocale + + 'foo' + + + include $this->testFilesDir . '/translation_empty.php' + include $this->testFilesDir . '/translation_en.php' + include $this->testFilesDir . '/translation_en.php' - - $this->testFilesDir - $this->testFilesDir - $this->testFilesDir - evaluate evaluate @@ -1097,11 +919,6 @@ include $this->testFilesDir . '/translation_en.php' - - - testInstanceOfMatches - - $container @@ -1111,21 +928,6 @@ static function ($container) use ($translator) { static function ($container) use ($translator) { - - $loader - $loader - - - provideLoader - testConfiguresTranslatorServicesWhenFound - testCreateServiceCanConfigurePluginManagerViaOptions - testCreateServiceReturnsUnconfiguredPluginManagerWhenNoOptionsPresent - testDoesNotConfigureTranslatorServicesWhenConfigServiceDoesNotContainTranslatorsConfig - testDoesNotConfigureTranslatorServicesWhenConfigServiceNotPresent - testDoesNotConfigureTranslatorServicesWhenServiceListenerPresent - testFactoryCanConfigurePluginManagerViaOptions - testFactoryReturnsUnconfiguredPluginManagerWhenNoOptionsPresent - $container $container @@ -1134,53 +936,16 @@ $config - - - $expectedValue - $expectedValues - $rule - $rule - - - completeRuleProvider - parseRuleProvider - testCompleteRules - testGetNumPlurals - testParseRules - - - $expectedValues[$i] - - - $rule - $rule - - - - TextDomain|null - - + $textDomain - - - TextDomain|null - - - $this->textDomain - + $filename $locale - - TextDomain|null - - - 'Laminas\I18n\Exception\RuntimeException' - testArrayAccess testInstantiation @@ -1204,14 +969,14 @@ - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' - '\Laminas\I18n\Translator\TranslatorAwareTrait' + TranslatorAwareTrait::class + TranslatorAwareTrait::class + TranslatorAwareTrait::class + TranslatorAwareTrait::class + TranslatorAwareTrait::class + TranslatorAwareTrait::class + TranslatorAwareTrait::class + TranslatorAwareTrait::class testGetTranslator @@ -1261,54 +1026,6 @@ - - 'Laminas\Cache\Storage\StorageInterface' - 'Laminas\EventManager\Event' - 'Laminas\EventManager\Event' - 'Laminas\I18n\Translator\TextDomain' - 'Laminas\I18n\Translator\Translator' - 'Laminas\I18n\Translator\Translator' - 'Laminas\I18n\Translator\Translator' - - - testClearCacheReturnsFalseIfNoCacheIsPresent - testDefaultLocale - testEnableDisableEventManger - testEnableEventMangerViaFactory - testFactoryCreatesTranslator - testFactoryCreatesTranslatorWithCache - testForcedLocale - testGetAllMessagesLoadedInTranslator - testGetAllMessagesReturnsNullWhenGivenLocaleNotExist - testGetAllMessagesReturnsNullWhenGivenTextDomainIsNotFound - testListenerOnMissingTranslationEventCanReturnString - testListenerOnNoMessagesLoadedEventCanReturnTextDomainObject - testMissingTranslationEvent - testNoMessagesLoadedEvent - testNullMessageArgumentShouldReturnAnEmptyString - testTranslate - testTranslateNoPlurals - testTranslateNonExistantLocale - testTranslateNonExistantTranslation - testTranslatePlurals - testTranslatePluralsNonExistantLocale - testTranslatePluralsNonExistantTranslation - testTranslationFromDifferentSourceTypes - testTranslationFromSeveralTranslationFiles - testTranslationsAreClearedFromCache - testTranslationsAreStoredInCache - testTranslationsLoadedFromCache - - - $item['foo'] - - - $item - - - getParams - getParams - null null @@ -1336,11 +1053,6 @@ [1 => 1] - - testEqualsMessageTemplates - testIntegerValidation - testNonStringValidation - @@ -1349,29 +1061,11 @@ [1 => 1] - - testEqualsMessageTemplates - testNonStringValidation - - - $this->locale - $this->timezone - - - $this->locale - $this->timezone - - - Locale::getDefault() - date_default_timezone_get() - - - basicProvider + testApplicationOptionLocale testApplicationOptionTimezone - testBasic testMultipleIsValidCalls testOptionLocale testOptionPattern @@ -1392,136 +1086,25 @@ [1 => 1] - - $type - - - floatAndIntegerProvider - lookAlikeProvider - testEqualsMessageTemplates - testNonStringValidation - testNotFloat - testSettingLocales - testUsingApplicationLocale - validationFailureProvider - $message['notFloat'] - $type + $value + + $value + - - getLocale - getMessageTemplates - getMessages - getOption - getStrict - getStrict - isValid - isValid - isValid - isValid - isValid - setLocale - setLocale - setLocale - setStrict - setStrict - setStrict - - - new IsIntValidator() - - - $expected - $intVal - - - intDataProvider - testEqualsMessageTemplates - testGetStrict - testLocaleDetectsNoEnglishLocaleOnOtherSetLocale - testNonStringValidation - testSetStrictThrowsInvalidArgumentException - testSettingLocales - testUsingApplicationLocale - - - $validator->getOption('messageTemplates') - - - array - array - - - - - addToAssertionCount - - - constructDataProvider - numbersDataProvider - testAllowPossibleSetterGetter - testCanSpecifyCountryWithContext - testConstruct - testCountryIsCaseInsensitive - testExampleNumbers - testExampleNumbersAgainstPossible - testInvalidTypes - + + [1 => 1] + - $value - $value - $value + $intVal + $intVal + $strict - - [$type] - [$type] - [$type] - - - $parameters['code'] - $parameters['patterns'] - - - $parameters - $type - $type - $type - $value - $value - $value - $values - $values - $values - - - $value - $value - $value - $value - $value - $value - $value - $value - $value - $value - $value - $value - $value - - - 'Laminas\Validator\Exception\InvalidArgumentException' - 'Laminas\Validator\Exception\InvalidArgumentException' - 'Laminas\Validator\Exception\InvalidArgumentException' - 'Laminas\Validator\Exception\InvalidArgumentException' - - - new PostCodeValidator(['locale' => 'de_AT']) - $value $value @@ -1530,289 +1113,31 @@ static function ($value) use ($params) { static function ($value) use ($params) { - - $expected - $expected - $postCode - $postCode - - - UKPostCodesDataProvider - liPostCode - postCodesDataProvider - testEqualsMessageTemplates - testErrorMessageText - testFrPostCodes - testGettingLocale - testLiPostCodes - testLvPostCodes - testNoPostCodes - testServiceClass - testSetGetFormat - testSetGetFormatThrowsExceptionOnEmptyFormat - testSetGetFormatThrowsExceptionOnNullFormat - testSettingLocalesWithoutPostalCodes - testSettingLocalesWithoutRegion - testUKBasic - - + $message['postcodeNoMatch'] $message['postcodeService'] $postCode - $validator->getOption('messageTemplates') - - $message['postcodeNoMatch'] - $message['postcodeService'] - - - $message - $message - - - isValid - isValid - isValid - isValid - setFormat - setFormat - - - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $this->validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - $validator - PostCode - - - $currencyCode - $currencyCode - $currencyPattern - $currencyPattern - $expected - $expected - $expected - $locale - $locale - $message - $number - $number - $showDecimals - $showDecimals - $test - - - assertMbStringEquals - currencyProvider - testBasic - testDefaultLocale - testSettersProvideDefaults - testViewhelperExecutedSequentially - - - $currencyCode - $currencyCode - $currencyPattern + $currencyPattern - $expected - $locale - $locale - $message - $number - $number - $showDecimals - $showDecimals - $test - + - - $date - $date - $date - $dateType - $dateType - $dateType - $dateType - $expected - $locale - $locale - $locale - $locale - $message - $pattern - $pattern - $test - $timeType - $timeType - $timeType - $timeType - $timezone - $timezone - $timezone - $timezone - - - assertMbStringEquals - dateTestsDataProvider - dateTestsDataProviderWithPattern - getIntlDateFormatter - testBasic - testBugTwoPatternOnSameHelperInstance - testDefaultLocale - testDifferentTimezone - testIntlCalendarIsHandledAsWell - testSettersProvideDefaults - testUseCustomPattern - - - $date - $date - $date - $dateType - $dateType - $dateType - $dateType - $expected - $locale - $locale - $locale - $locale - $message - $pattern - $pattern - $test - $timeType - $timeType - $timeType - $timeType - $timezone - $timezone - $timezone - $timezone - - - $expected - $expected - $expected - - - format - format - format - getTimestamp - getTimestamp - getTimestamp - new IntlGregorianCalendar(2013, 6, 1) - - $decimals - $decimals - $expected - $expected - $expected - $formatStyle - $formatStyle - $formatType - $formatType - $locale - $locale - $message - $number - $number - $test - $textAttributes - $textAttributes - - - assertMbStringEquals - currencyTestsDataProvider + testBasic - testDefaultLocale - testSettersProvideDefaults - - $decimals + $decimals - $expected - $formatStyle - $formatStyle - $formatType - $formatType - $locale - $locale - $message - $number - $number - $test - $textAttributes - $textAttributes - - - - - $expected - $number - $pluralRule - $strings - - - testGetCorrectPlurals - - - $number - $pluralRule - $strings - - - array - + - - 'Laminas\I18n\Exception\RuntimeException' - testCustomInvokeArguments testDefaultInvokeArguments @@ -1820,9 +1145,6 @@ - - 'Laminas\I18n\Exception\RuntimeException' - testCustomInvokeArguments testDefaultInvokeArguments diff --git a/psalm.xml b/psalm.xml index c4e98ee1..624e9a6d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -26,6 +26,11 @@ + + + + + diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 51c1d4e5..bade3531 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -29,12 +29,14 @@ public function __invoke() public function getDependencyConfig() { return [ - 'aliases' => [ + 'aliases' => [ 'TranslatorPluginManager' => Translator\LoaderPluginManager::class, // Legacy Zend Framework aliases + // @codingStandardsIgnoreStart \Zend\I18n\Translator\TranslatorInterface::class => Translator\TranslatorInterface::class, \Zend\I18n\Translator\LoaderPluginManager::class => Translator\LoaderPluginManager::class, + // @codingStandardsIgnoreEnd ], 'factories' => [ Translator\TranslatorInterface::class => Translator\TranslatorServiceFactory::class, @@ -51,7 +53,7 @@ public function getDependencyConfig() public function getFilterConfig() { return [ - 'aliases' => [ + 'aliases' => [ 'alnum' => Filter\Alnum::class, 'Alnum' => Filter\Alnum::class, 'alpha' => Filter\Alpha::class, @@ -64,10 +66,12 @@ public function getFilterConfig() 'NumberParse' => Filter\NumberParse::class, // Legacy Zend Framework aliases + // @codingStandardsIgnoreStart \Zend\I18n\Filter\Alnum::class => Filter\Alnum::class, \Zend\I18n\Filter\Alpha::class => Filter\Alpha::class, \Zend\I18n\Filter\NumberFormat::class => Filter\NumberFormat::class, \Zend\I18n\Filter\NumberParse::class => Filter\NumberParse::class, + // @codingStandardsIgnoreEnd ], 'factories' => [ Filter\Alnum::class => InvokableFactory::class, @@ -86,7 +90,7 @@ public function getFilterConfig() public function getValidatorConfig() { return [ - 'aliases' => [ + 'aliases' => [ 'alnum' => Validator\Alnum::class, 'Alnum' => Validator\Alnum::class, 'alpha' => Validator\Alpha::class, @@ -112,6 +116,7 @@ public function getValidatorConfig() 'PostCode' => Validator\PostCode::class, // Legacy Zend Framework aliases + // @codingStandardsIgnoreStart \Zend\I18n\Validator\Alnum::class => Validator\Alnum::class, \Zend\I18n\Validator\Alpha::class => Validator\Alpha::class, \Zend\I18n\Validator\DateTime::class => Validator\DateTime::class, @@ -119,6 +124,7 @@ public function getValidatorConfig() \Zend\I18n\Validator\IsInt::class => Validator\IsInt::class, \Zend\I18n\Validator\PhoneNumber::class => Validator\PhoneNumber::class, \Zend\I18n\Validator\PostCode::class => Validator\PostCode::class, + // @codingStandardsIgnoreEnd ], 'factories' => [ Validator\Alnum::class => InvokableFactory::class, @@ -142,7 +148,7 @@ public function getValidatorConfig() public function getViewHelperConfig() { return [ - 'aliases' => [ + 'aliases' => [ 'currencyformat' => View\Helper\CurrencyFormat::class, 'currencyFormat' => View\Helper\CurrencyFormat::class, 'CurrencyFormat' => View\Helper\CurrencyFormat::class, @@ -161,12 +167,14 @@ public function getViewHelperConfig() 'TranslatePlural' => View\Helper\TranslatePlural::class, // Legacy Zend Framework aliases + // @codingStandardsIgnoreStart \Zend\I18n\View\Helper\CurrencyFormat::class => View\Helper\CurrencyFormat::class, \Zend\I18n\View\Helper\DateFormat::class => View\Helper\DateFormat::class, \Zend\I18n\View\Helper\NumberFormat::class => View\Helper\NumberFormat::class, \Zend\I18n\View\Helper\Plural::class => View\Helper\Plural::class, \Zend\I18n\View\Helper\Translate::class => View\Helper\Translate::class, \Zend\I18n\View\Helper\TranslatePlural::class => View\Helper\TranslatePlural::class, + // @codingStandardsIgnoreEnd ], 'factories' => [ View\Helper\CurrencyFormat::class => InvokableFactory::class, diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 37018b53..9d7cb4d5 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -2,6 +2,8 @@ namespace Laminas\I18n\Exception; -interface ExceptionInterface +use Throwable; + +interface ExceptionInterface extends Throwable { } diff --git a/src/Filter/AbstractLocale.php b/src/Filter/AbstractLocale.php index b383c8c4..239d7e0e 100644 --- a/src/Filter/AbstractLocale.php +++ b/src/Filter/AbstractLocale.php @@ -3,22 +3,12 @@ namespace Laminas\I18n\Filter; use Laminas\Filter\AbstractFilter; -use Laminas\I18n\Exception; use Locale; abstract class AbstractLocale extends AbstractFilter { - /** - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present - */ public function __construct() { - if (! extension_loaded('intl')) { - throw new Exception\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } } /** diff --git a/src/Filter/Alnum.php b/src/Filter/Alnum.php index 19a29d9b..1dce4230 100644 --- a/src/Filter/Alnum.php +++ b/src/Filter/Alnum.php @@ -6,11 +6,14 @@ use Locale; use Traversable; +use function in_array; +use function is_array; +use function is_scalar; +use function preg_replace; + class Alnum extends AbstractLocale { - /** - * @var array - */ + /** @var array */ protected $options = [ 'locale' => null, 'allow_white_space' => false, @@ -79,12 +82,14 @@ public function filter($value) $pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/'; } elseif (in_array($language, ['ja', 'ko', 'zh'], true)) { // Use english alphabet - $pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/u'; + $pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/u'; } else { // Use native language alphabet $pattern = '/[^\p{L}\p{N}' . $whiteSpace . ']/u'; } + $value = is_scalar($value) ? (string) $value : $value; + return preg_replace($pattern, '', $value); } } diff --git a/src/Filter/Alpha.php b/src/Filter/Alpha.php index a4a29fcb..5f786893 100644 --- a/src/Filter/Alpha.php +++ b/src/Filter/Alpha.php @@ -5,6 +5,11 @@ use Laminas\Stdlib\StringUtils; use Locale; +use function in_array; +use function is_array; +use function is_scalar; +use function preg_replace; + class Alpha extends Alnum { /** @@ -29,7 +34,7 @@ public function filter($value) $pattern = '/[^a-zA-Z' . $whiteSpace . ']/'; } elseif (in_array($language, ['ja', 'ko', 'zh'], true)) { // Use english alphabet - $pattern = '/[^a-zA-Z' . $whiteSpace . ']/u'; + $pattern = '/[^a-zA-Z' . $whiteSpace . ']/u'; } else { // Use native language alphabet $pattern = '/[^\p{L}' . $whiteSpace . ']/u'; diff --git a/src/Filter/NumberFormat.php b/src/Filter/NumberFormat.php index 7d8c9dfc..8f750315 100644 --- a/src/Filter/NumberFormat.php +++ b/src/Filter/NumberFormat.php @@ -4,12 +4,17 @@ use Laminas\Stdlib\ErrorHandler; +use function is_float; +use function is_int; +use function is_scalar; + class NumberFormat extends NumberParse { /** * Defined by Laminas\Filter\FilterInterface * * @see \Laminas\Filter\FilterInterface::filter() + * * @param mixed $value * @return mixed */ diff --git a/src/Filter/NumberParse.php b/src/Filter/NumberParse.php index 3054d3f1..e87fe0ab 100644 --- a/src/Filter/NumberParse.php +++ b/src/Filter/NumberParse.php @@ -7,17 +7,22 @@ use NumberFormatter; use Traversable; +use function intl_get_error_message; +use function is_array; +use function is_float; +use function is_int; +use function iterator_to_array; + class NumberParse extends AbstractLocale { + /** @var array */ protected $options = [ 'locale' => null, 'style' => NumberFormatter::DEFAULT_STYLE, - 'type' => NumberFormatter::TYPE_DOUBLE + 'type' => NumberFormatter::TYPE_DOUBLE, ]; - /** - * @var NumberFormatter - */ + /** @var NumberFormatter */ protected $formatter; /** @@ -53,7 +58,7 @@ public function __construct( public function setLocale($locale = null) { $this->options['locale'] = $locale; - $this->formatter = null; + $this->formatter = null; return $this; } @@ -64,7 +69,7 @@ public function setLocale($locale = null) public function setStyle($style) { $this->options['style'] = (int) $style; - $this->formatter = null; + $this->formatter = null; return $this; } @@ -95,7 +100,6 @@ public function getType() } /** - * @param NumberFormatter $formatter * @return $this */ public function setFormatter(NumberFormatter $formatter) @@ -128,12 +132,14 @@ public function getFormatter() * Defined by Laminas\Filter\FilterInterface * * @see \Laminas\Filter\FilterInterface::filter() + * * @param mixed $value * @return mixed */ public function filter($value) { - if (! is_int($value) + if ( + ! is_int($value) && ! is_float($value) ) { ErrorHandler::start(); diff --git a/src/Module.php b/src/Module.php index 539a6bd2..0d4ff8a1 100644 --- a/src/Module.php +++ b/src/Module.php @@ -2,6 +2,8 @@ namespace Laminas\I18n; +use Laminas\ModuleManager\ModuleManager; + class Module { /** @@ -23,13 +25,13 @@ public function getConfig() /** * Register a specification for the TranslatorPluginManager with the ServiceListener. * - * @param \Laminas\ModuleManager\ModuleManager $moduleManager + * @param ModuleManager $moduleManager * @return void */ public function init($moduleManager) { - $event = $moduleManager->getEvent(); - $container = $event->getParam('ServiceManager'); + $event = $moduleManager->getEvent(); + $container = $event->getParam('ServiceManager'); $serviceListener = $container->get('ServiceListener'); $serviceListener->addServiceManager( diff --git a/src/Translator/Loader/AbstractFileLoader.php b/src/Translator/Loader/AbstractFileLoader.php index 5b9ceb31..1f23d9c1 100644 --- a/src/Translator/Loader/AbstractFileLoader.php +++ b/src/Translator/Loader/AbstractFileLoader.php @@ -2,6 +2,10 @@ namespace Laminas\I18n\Translator\Loader; +use function is_file; +use function is_readable; +use function stream_resolve_include_path; + /** * Abstract file loader implementation; provides facilities around resolving * files via the include_path. diff --git a/src/Translator/Loader/Gettext.php b/src/Translator/Loader/Gettext.php index 88ed514d..6a494d8c 100644 --- a/src/Translator/Loader/Gettext.php +++ b/src/Translator/Loader/Gettext.php @@ -7,6 +7,17 @@ use Laminas\I18n\Translator\TextDomain; use Laminas\Stdlib\ErrorHandler; +use function array_shift; +use function explode; +use function fclose; +use function fopen; +use function fread; +use function fseek; +use function sprintf; +use function strtolower; +use function trim; +use function unpack; + /** * Gettext loader. */ @@ -30,6 +41,7 @@ class Gettext extends AbstractFileLoader * load(): defined by FileLoaderInterface. * * @see FileLoaderInterface::load() + * * @param string $locale * @param string $filename * @return TextDomain @@ -49,7 +61,7 @@ public function load($locale, $filename) ErrorHandler::start(); $this->file = fopen($resolvedFile, 'rb'); - $error = ErrorHandler::stop(); + $error = ErrorHandler::stop(); if (false === $this->file) { throw new Exception\InvalidArgumentException(sprintf( 'Could not open file %s for reading', @@ -73,7 +85,7 @@ public function load($locale, $filename) } // Verify major revision (only 0 and 1 supported) - $majorRevision = ($this->readInteger() >> 16); + $majorRevision = $this->readInteger() >> 16; if ($majorRevision !== 0 && $majorRevision !== 1) { fclose($this->file); @@ -136,7 +148,7 @@ public function load($locale, $filename) $rawHeaders = explode("\n", trim($textDomain[''])); foreach ($rawHeaders as $rawHeader) { - list($header, $content) = explode(':', $rawHeader, 2); + [$header, $content] = explode(':', $rawHeader, 2); if (strtolower(trim($header)) === 'plural-forms') { $textDomain->setPluralRule(PluralRule::fromString($content)); diff --git a/src/Translator/Loader/Ini.php b/src/Translator/Loader/Ini.php index 846c7858..9c20a352 100644 --- a/src/Translator/Loader/Ini.php +++ b/src/Translator/Loader/Ini.php @@ -7,6 +7,15 @@ use Laminas\I18n\Translator\Plural\Rule as PluralRule; use Laminas\I18n\Translator\TextDomain; +use function array_shift; +use function count; +use function gettype; +use function is_array; +use function is_file; +use function is_readable; +use function sprintf; +use function stream_resolve_include_path; + /** * PHP INI format loader. */ @@ -16,6 +25,7 @@ class Ini extends AbstractFileLoader * load(): defined by FileLoaderInterface. * * @see FileLoaderInterface::load() + * * @param string $locale * @param string $filename * @return TextDomain @@ -24,7 +34,7 @@ class Ini extends AbstractFileLoader public function load($locale, $filename) { $resolvedIncludePath = stream_resolve_include_path($filename); - $fromIncludePath = ($resolvedIncludePath !== false) ? $resolvedIncludePath : $filename; + $fromIncludePath = $resolvedIncludePath !== false ? $resolvedIncludePath : $filename; if (! $fromIncludePath || ! is_file($fromIncludePath) || ! is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( 'Could not find or open file %s for reading', diff --git a/src/Translator/Loader/PhpArray.php b/src/Translator/Loader/PhpArray.php index 4b15df99..681ca189 100644 --- a/src/Translator/Loader/PhpArray.php +++ b/src/Translator/Loader/PhpArray.php @@ -6,6 +6,13 @@ use Laminas\I18n\Translator\Plural\Rule as PluralRule; use Laminas\I18n\Translator\TextDomain; +use function gettype; +use function is_array; +use function is_file; +use function is_readable; +use function sprintf; +use function stream_resolve_include_path; + /** * PHP array loader. */ @@ -15,6 +22,7 @@ class PhpArray extends AbstractFileLoader * load(): defined by FileLoaderInterface. * * @see FileLoaderInterface::load() + * * @param string $locale * @param string $filename * @return TextDomain @@ -23,7 +31,7 @@ class PhpArray extends AbstractFileLoader public function load($locale, $filename) { $resolvedIncludePath = stream_resolve_include_path($filename); - $fromIncludePath = ($resolvedIncludePath !== false) ? $resolvedIncludePath : $filename; + $fromIncludePath = $resolvedIncludePath !== false ? $resolvedIncludePath : $filename; if (! $fromIncludePath || ! is_file($fromIncludePath) || ! is_readable($fromIncludePath)) { throw new Exception\InvalidArgumentException(sprintf( 'Could not find or open file %s for reading', diff --git a/src/Translator/Loader/PhpMemoryArray.php b/src/Translator/Loader/PhpMemoryArray.php index 3e5c2357..7c61e056 100644 --- a/src/Translator/Loader/PhpMemoryArray.php +++ b/src/Translator/Loader/PhpMemoryArray.php @@ -6,16 +6,19 @@ use Laminas\I18n\Translator\Plural\Rule as PluralRule; use Laminas\I18n\Translator\TextDomain; +use function gettype; +use function is_array; +use function sprintf; + /** * PHP Memory array loader. */ class PhpMemoryArray implements RemoteLoaderInterface { - /** - * @var array - */ + /** @var array */ protected $messages; + /** @param array $messages */ public function __construct($messages) { $this->messages = $messages; diff --git a/src/Translator/LoaderPluginManager.php b/src/Translator/LoaderPluginManager.php index b4b8b45d..6d01a761 100644 --- a/src/Translator/LoaderPluginManager.php +++ b/src/Translator/LoaderPluginManager.php @@ -6,6 +6,14 @@ use Laminas\ServiceManager\AbstractPluginManager; use Laminas\ServiceManager\Exception\InvalidServiceException; use Laminas\ServiceManager\Factory\InvokableFactory; +use Zend\I18n\Translator\Loader\Gettext; +use Zend\I18n\Translator\Loader\Ini; +use Zend\I18n\Translator\Loader\PhpArray; + +use function get_class; +use function gettype; +use function is_object; +use function sprintf; /** * Plugin manager implementation for translation loaders. @@ -49,6 +57,7 @@ */ class LoaderPluginManager extends AbstractPluginManager { + /** @var array */ protected $aliases = [ 'gettext' => Loader\Gettext::class, 'getText' => Loader\Gettext::class, @@ -59,16 +68,17 @@ class LoaderPluginManager extends AbstractPluginManager 'PhpArray' => Loader\PhpArray::class, // Legacy Zend Framework aliases - \Zend\I18n\Translator\Loader\Gettext::class => Loader\Gettext::class, - \Zend\I18n\Translator\Loader\Ini::class => Loader\Ini::class, - \Zend\I18n\Translator\Loader\PhpArray::class => Loader\PhpArray::class, + Gettext::class => Loader\Gettext::class, + Ini::class => Loader\Ini::class, + PhpArray::class => Loader\PhpArray::class, // v2 normalized FQCNs - 'zendi18ntranslatorloadergettext' => Loader\Gettext::class, - 'zendi18ntranslatorloaderini' => Loader\Ini::class, + 'zendi18ntranslatorloadergettext' => Loader\Gettext::class, + 'zendi18ntranslatorloaderini' => Loader\Ini::class, 'zendi18ntranslatorloaderphparray' => Loader\PhpArray::class, ]; + /** @var array */ protected $factories = [ Loader\Gettext::class => InvokableFactory::class, Loader\Ini::class => InvokableFactory::class, @@ -78,7 +88,7 @@ class LoaderPluginManager extends AbstractPluginManager // resolved alias is used as the requested name passed to the factory. 'laminasi18ntranslatorloadergettext' => InvokableFactory::class, 'laminasi18ntranslatorloaderini' => InvokableFactory::class, - 'laminasi18ntranslatorloaderphparray' => InvokableFactory::class + 'laminasi18ntranslatorloaderphparray' => InvokableFactory::class, ]; /** @@ -89,7 +99,7 @@ class LoaderPluginManager extends AbstractPluginManager * * @param mixed $plugin * @return void - * @throws Exception\RuntimeException if invalid + * @throws Exception\RuntimeException If invalid. */ public function validate($plugin) { @@ -101,7 +111,7 @@ public function validate($plugin) throw new InvalidServiceException(sprintf( 'Plugin of type %s is invalid; must implement %s\Loader\FileLoaderInterface ' . 'or %s\Loader\RemoteLoaderInterface', - (is_object($plugin) ? get_class($plugin) : gettype($plugin)), + is_object($plugin) ? get_class($plugin) : gettype($plugin), __NAMESPACE__, __NAMESPACE__ )); @@ -123,7 +133,7 @@ public function validatePlugin($plugin) throw new Exception\RuntimeException(sprintf( 'Plugin of type %s is invalid; must implement %s\Loader\FileLoaderInterface ' . 'or %s\Loader\RemoteLoaderInterface', - (is_object($plugin) ? get_class($plugin) : gettype($plugin)), + is_object($plugin) ? get_class($plugin) : gettype($plugin), __NAMESPACE__, __NAMESPACE__ )); diff --git a/src/Translator/LoaderPluginManagerFactory.php b/src/Translator/LoaderPluginManagerFactory.php index 66465221..5f4d404f 100644 --- a/src/Translator/LoaderPluginManagerFactory.php +++ b/src/Translator/LoaderPluginManagerFactory.php @@ -7,26 +7,27 @@ use Laminas\ServiceManager\FactoryInterface; use Laminas\ServiceManager\ServiceLocatorInterface; +use function is_array; + class LoaderPluginManagerFactory implements FactoryInterface { /** * laminas-servicemanager v2 options passed to factory. * - * @param array + * @var array */ protected $creationOptions = []; /** * Create and return a LoaderPluginManager. * - * @param ContainerInterface $container * @param string $name * @param null|array $options * @return LoaderPluginManager */ - public function __invoke(ContainerInterface $container, $name, array $options = null) + public function __invoke(ContainerInterface $container, $name, ?array $options = null) { - $options = $options ?: []; + $options = $options ?: []; $pluginManager = new LoaderPluginManager($container, $options); // If this is in a laminas-mvc application, the ServiceListener will inject @@ -56,7 +57,6 @@ public function __invoke(ContainerInterface $container, $name, array $options = /** * laminas-servicemanager v2 factory to return LoaderPluginManager * - * @param ServiceLocatorInterface $container * @return LoaderPluginManager */ public function createService(ServiceLocatorInterface $container) diff --git a/src/Translator/Plural/Parser.php b/src/Translator/Plural/Parser.php index 575f10db..54d0952e 100644 --- a/src/Translator/Plural/Parser.php +++ b/src/Translator/Plural/Parser.php @@ -4,6 +4,10 @@ use Laminas\I18n\Exception; +use function ctype_digit; +use function max; +use function sprintf; + /** * Plural rule parser. * @@ -42,7 +46,6 @@ class Parser /** * Create a new plural parser. - * */ public function __construct() { @@ -198,13 +201,13 @@ static function (Symbol $self) use ($leftBindingPower) { protected function registerSymbol($id, $leftBindingPower = 0) { if (isset($this->symbolTable[$id])) { - $symbol = $this->symbolTable[$id]; + $symbol = $this->symbolTable[$id]; $symbol->leftBindingPower = max( $symbol->leftBindingPower, $leftBindingPower ); } else { - $symbol = new Symbol($this, $id, $leftBindingPower); + $symbol = new Symbol($this, $id, $leftBindingPower); $this->symbolTable[$id] = $symbol; } @@ -219,7 +222,7 @@ protected function registerSymbol($id, $leftBindingPower = 0) */ protected function getSymbol($id) { - if (! isset($this->symbolTable[$id])) { + if (! isset($this->symbolTable[$id])) { // phpcs:ignore // Unknown symbol exception } @@ -320,7 +323,7 @@ protected function getNextToken() if ($this->string[$this->currentPos] === $result) { $this->currentPos++; $id = $result . $result; - } else { + } else { // phpcs:ignore // Yield error } break; @@ -363,7 +366,7 @@ protected function getNextToken() )); } - $token = $this->getSymbol($id); + $token = $this->getSymbol($id); $token->value = $value; return $token; diff --git a/src/Translator/Plural/Rule.php b/src/Translator/Plural/Rule.php index 415745c2..00d82777 100644 --- a/src/Translator/Plural/Rule.php +++ b/src/Translator/Plural/Rule.php @@ -4,6 +4,11 @@ use Laminas\I18n\Exception; +use function abs; +use function floor; +use function preg_match; +use function sprintf; + /** * Plural rule evaluator. */ @@ -55,7 +60,7 @@ public function evaluate($number) if ($result < 0 || $result >= $this->numPlurals) { throw new Exception\RangeException( - sprintf('Calculated result %s is between 0 and %d', $result, ($this->numPlurals - 1)) + sprintf('Calculated result %s is between 0 and %d', $result, $this->numPlurals - 1) ); } @@ -133,6 +138,7 @@ protected function evaluateAstPart(array $ast, $number) ? 1 : 0; case '==': + // @codingStandardsIgnoreStart return $this->evaluateAstPart($ast['arguments'][0], $number) == $this->evaluateAstPart($ast['arguments'][1], $number) ? 1 : 0; @@ -141,6 +147,7 @@ protected function evaluateAstPart(array $ast, $number) return $this->evaluateAstPart($ast['arguments'][0], $number) != $this->evaluateAstPart($ast['arguments'][1], $number) ? 1 : 0; + // @codingStandardsIgnoreEnd case '&&': return $this->evaluateAstPart($ast['arguments'][0], $number) @@ -210,7 +217,6 @@ public static function fromString($string) * Theoretically we could just use the given Symbol, but that one is not * so easy to serialize and also takes up more memory. * - * @param Symbol $symbol * @return array */ protected static function createAst(Symbol $symbol) diff --git a/src/Translator/Plural/Symbol.php b/src/Translator/Plural/Symbol.php index 9683dea7..7317a89d 100644 --- a/src/Translator/Plural/Symbol.php +++ b/src/Translator/Plural/Symbol.php @@ -5,6 +5,8 @@ use Closure; use Laminas\I18n\Exception; +use function sprintf; + /** * Parser symbol. * @@ -81,21 +83,19 @@ class Symbol /** * Create a new symbol. * - * @param Parser $parser * @param string $id * @param int $leftBindingPower */ public function __construct(Parser $parser, $id, $leftBindingPower) { - $this->parser = $parser; - $this->id = $id; - $this->leftBindingPower = $leftBindingPower; + $this->parser = $parser; + $this->id = $id; + $this->leftBindingPower = $leftBindingPower; } /** * Set the null denotation getter. * - * @param Closure $getter * @return $this */ public function setNullDenotationGetter(Closure $getter) @@ -107,7 +107,6 @@ public function setNullDenotationGetter(Closure $getter) /** * Set the left denotation getter. * - * @param Closure $getter * @return $this */ public function setLeftDenotationGetter(Closure $getter) diff --git a/src/Translator/TextDomain.php b/src/Translator/TextDomain.php index 66bab9a8..78cbd77f 100644 --- a/src/Translator/TextDomain.php +++ b/src/Translator/TextDomain.php @@ -6,6 +6,8 @@ use Laminas\I18n\Exception; use Laminas\I18n\Translator\Plural\Rule as PluralRule; +use function array_replace; + /** * Text domain. */ @@ -28,7 +30,6 @@ class TextDomain extends ArrayObject /** * Set the plural rule * - * @param PluralRule $rule * @return $this */ public function setPluralRule(PluralRule $rule) @@ -59,7 +60,7 @@ public function getPluralRule($fallbackToDefaultRule = true) */ public function hasPluralRule() { - return ($this->pluralRule !== null); + return $this->pluralRule !== null; } /** @@ -83,7 +84,6 @@ public static function getDefaultPluralRule() * merge. We are only validating the number of plural forms though, as the * same rule could be made up with different expression. * - * @param TextDomain $textDomain * @return $this * @throws Exception\RuntimeException */ diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index c9a9ee0d..bd4ce113 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -15,6 +15,17 @@ use Locale; use Traversable; +use function array_shift; +use function get_class; +use function gettype; +use function is_array; +use function is_file; +use function is_object; +use function is_string; +use function md5; +use function rtrim; +use function sprintf; + /** * Translator. */ @@ -23,12 +34,12 @@ class Translator implements TranslatorInterface /** * Event fired when the translation for a message is missing. */ - const EVENT_MISSING_TRANSLATION = 'missingTranslation'; + public const EVENT_MISSING_TRANSLATION = 'missingTranslation'; /** * Event fired when no messages were loaded for a locale/text-domain combination. */ - const EVENT_NO_MESSAGES_LOADED = 'noMessagesLoaded'; + public const EVENT_NO_MESSAGES_LOADED = 'noMessagesLoaded'; /** * Messages loaded by the translator. @@ -115,7 +126,7 @@ public static function factory($options) throw new Exception\InvalidArgumentException(sprintf( '%s expects an array or Traversable object; received "%s"', __METHOD__, - (is_object($options) ? get_class($options) : gettype($options)) + is_object($options) ? get_class($options) : gettype($options) )); } @@ -152,7 +163,7 @@ public static function factory($options) $pattern['type'], $pattern['base_dir'], $pattern['pattern'], - isset($pattern['text_domain']) ? $pattern['text_domain'] : 'default' + $pattern['text_domain'] ?? 'default' ); } } @@ -178,8 +189,8 @@ public static function factory($options) $translator->addTranslationFile( $file['type'], $file['filename'], - isset($file['text_domain']) ? $file['text_domain'] : 'default', - isset($file['locale']) ? $file['locale'] : null + $file['text_domain'] ?? 'default', + $file['locale'] ?? null ); } } @@ -204,7 +215,7 @@ public static function factory($options) $translator->addRemoteTranslations( $remote['type'], - isset($remote['text_domain']) ? $remote['text_domain'] : 'default' + $remote['text_domain'] ?? 'default' ); } } @@ -243,17 +254,10 @@ public function setLocale($locale) * Get the default locale. * * @return string - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present and no locale set */ public function getLocale() { if ($this->locale === null) { - if (! extension_loaded('intl')) { - throw new Exception\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } $this->locale = Locale::getDefault(); } @@ -286,10 +290,9 @@ public function getFallbackLocale() /** * Sets a cache * - * @param CacheStorage|null $cache * @return $this */ - public function setCache(CacheStorage $cache = null) + public function setCache(?CacheStorage $cache = null) { $this->cache = $cache; @@ -309,7 +312,6 @@ public function getCache() /** * Set the plugin manager for translation loaders * - * @param LoaderPluginManager $pluginManager * @return $this */ public function setPluginManager(LoaderPluginManager $pluginManager) @@ -329,7 +331,7 @@ public function setPluginManager(LoaderPluginManager $pluginManager) public function getPluginManager() { if (! $this->pluginManager instanceof LoaderPluginManager) { - $this->setPluginManager(new LoaderPluginManager(new ServiceManager)); + $this->setPluginManager(new LoaderPluginManager(new ServiceManager())); } return $this->pluginManager; @@ -345,14 +347,15 @@ public function getPluginManager() */ public function translate($message, $textDomain = 'default', $locale = null) { - $locale = ($locale ?: $this->getLocale()); + $locale = $locale ?: $this->getLocale(); $translation = $this->getTranslatedMessage($message, $locale, $textDomain); if ($translation !== null && $translation !== '') { return $translation; } - if (null !== ($fallbackLocale = $this->getFallbackLocale()) + if ( + null !== ($fallbackLocale = $this->getFallbackLocale()) && $locale !== $fallbackLocale ) { return $this->translate($message, $textDomain, $fallbackLocale); @@ -386,7 +389,7 @@ public function translatePlural( $translation = [$translation]; } - $index = ($number === 1) ? 0 : 1; // en_EN Plural rule + $index = $number === 1 ? 0 : 1; // en_EN Plural rule if ($this->messages[$textDomain][$locale] instanceof TextDomain) { $index = $this->messages[$textDomain][$locale] ->getPluralRule() @@ -397,7 +400,8 @@ public function translatePlural( return $translation[$index]; } - if (null !== ($fallbackLocale = $this->getFallbackLocale()) + if ( + null !== ($fallbackLocale = $this->getFallbackLocale()) && $locale !== $fallbackLocale ) { return $this->translatePlural( @@ -438,7 +442,6 @@ protected function getTranslatedMessage( return $this->messages[$textDomain][$locale][$message]; } - /** * issue https://github.com/zendframework/zend-i18n/issues/53 * @@ -500,7 +503,7 @@ public function addTranslationFile( } $this->files[$textDomain][$locale][] = [ - 'type' => $type, + 'type' => $type, 'filename' => $filename, ]; @@ -614,7 +617,7 @@ protected function loadMessages($textDomain, $locale) $discoveredTextDomain = null; if ($this->isEventManagerEnabled()) { $until = static function ($r) { - return ($r instanceof TextDomain); + return $r instanceof TextDomain; }; $event = new Event(self::EVENT_NO_MESSAGES_LOADED, $this, [ @@ -631,7 +634,7 @@ protected function loadMessages($textDomain, $locale) } $this->messages[$textDomain][$locale] = $discoveredTextDomain; - $messagesLoaded = true; + $messagesLoaded = true; } if ($messagesLoaded && $cache !== null) { @@ -645,7 +648,7 @@ protected function loadMessages($textDomain, $locale) * @param string $textDomain * @param string $locale * @return bool - * @throws Exception\RuntimeException When specified loader is not a remote loader + * @throws Exception\RuntimeException When specified loader is not a remote loader. */ protected function loadMessagesFromRemote($textDomain, $locale) { @@ -678,7 +681,7 @@ protected function loadMessagesFromRemote($textDomain, $locale) * @param string $textDomain * @param string $locale * @return bool - * @throws Exception\RuntimeException When specified loader is not a file loader + * @throws Exception\RuntimeException When specified loader is not a file loader. */ protected function loadMessagesFromPatterns($textDomain, $locale) { @@ -715,7 +718,7 @@ protected function loadMessagesFromPatterns($textDomain, $locale) * @param string $textDomain * @param string $locale * @return bool - * @throws Exception\RuntimeException When specified loader is not a file loader + * @throws Exception\RuntimeException When specified loader is not a file loader. */ protected function loadMessagesFromFiles($textDomain, $locale) { @@ -783,14 +786,13 @@ public function getEventManager() /** * Set the event manager instance used by this translator. * - * @param EventManagerInterface $events * @return $this */ public function setEventManager(EventManagerInterface $events) { $events->setIdentifiers([ - __CLASS__, - get_class($this), + self::class, + static::class, 'translator', ]); $this->events = $events; diff --git a/src/Translator/TranslatorAwareInterface.php b/src/Translator/TranslatorAwareInterface.php index 6b1e83b7..47c5a0b7 100644 --- a/src/Translator/TranslatorAwareInterface.php +++ b/src/Translator/TranslatorAwareInterface.php @@ -11,7 +11,7 @@ interface TranslatorAwareInterface * @param string|null $textDomain Default is null, which skips setTranslatorTextDomain * @return $this */ - public function setTranslator(TranslatorInterface $translator = null, $textDomain = null); + public function setTranslator(?TranslatorInterface $translator = null, $textDomain = null); /** * Returns translator used in object diff --git a/src/Translator/TranslatorAwareTrait.php b/src/Translator/TranslatorAwareTrait.php index 3afcef1c..7387e7b0 100644 --- a/src/Translator/TranslatorAwareTrait.php +++ b/src/Translator/TranslatorAwareTrait.php @@ -4,29 +4,22 @@ trait TranslatorAwareTrait { - /** - * @var TranslatorInterface|null - */ + /** @var TranslatorInterface|null */ protected $translator; - /** - * @var bool - */ + /** @var bool */ protected $translatorEnabled = true; - /** - * @var string - */ + /** @var string */ protected $translatorTextDomain = 'default'; /** * Sets translator to use in helper * - * @param TranslatorInterface|null $translator * @param string|null $textDomain * @return $this */ - public function setTranslator(TranslatorInterface $translator = null, $textDomain = null) + public function setTranslator(?TranslatorInterface $translator = null, $textDomain = null) { $this->translator = $translator; @@ -54,7 +47,7 @@ public function getTranslator() */ public function hasTranslator() { - return (null !== $this->translator); + return null !== $this->translator; } /** diff --git a/src/Translator/TranslatorServiceFactory.php b/src/Translator/TranslatorServiceFactory.php index f6b2c6bf..fa6dc783 100644 --- a/src/Translator/TranslatorServiceFactory.php +++ b/src/Translator/TranslatorServiceFactory.php @@ -14,16 +14,15 @@ class TranslatorServiceFactory implements FactoryInterface /** * Create a Translator instance. * - * @param ContainerInterface $container * @param string $requestedName * @param null|array $options * @return Translator */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null) { // Configure the translator $config = $container->get('config'); - $trConfig = isset($config['translator']) ? $config['translator'] : []; + $trConfig = $config['translator'] ?? []; $translator = Translator::factory($trConfig); if ($container->has('TranslatorPluginManager')) { $translator->setPluginManager($container->get('TranslatorPluginManager')); @@ -36,7 +35,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o * * Proxies to `__invoke()`. * - * @param ServiceLocatorInterface $serviceLocator * @return Translator */ public function createService(ServiceLocatorInterface $serviceLocator) diff --git a/src/Validator/Alnum.php b/src/Validator/Alnum.php index 2c91c66d..f5f4b464 100644 --- a/src/Validator/Alnum.php +++ b/src/Validator/Alnum.php @@ -5,11 +5,17 @@ use Laminas\I18n\Filter\Alnum as AlnumFilter; use Laminas\Validator\AbstractValidator; +use function is_array; +use function is_float; +use function is_int; +use function is_scalar; +use function is_string; + class Alnum extends AbstractValidator { - const INVALID = 'alnumInvalid'; - const NOT_ALNUM = 'notAlnum'; - const STRING_EMPTY = 'alnumStringEmpty'; + public const INVALID = 'alnumInvalid'; + public const NOT_ALNUM = 'notAlnum'; + public const STRING_EMPTY = 'alnumStringEmpty'; /** * Alphanumeric filter used for validation @@ -35,7 +41,7 @@ class Alnum extends AbstractValidator * @var array */ protected $options = [ - 'allowWhiteSpace' => false, // Whether to allow white space characters; off by default + 'allowWhiteSpace' => false, // Whether to allow white space characters; off by default ]; /** @@ -100,7 +106,7 @@ public function isValid($value) static::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']); - if ($value != static::$filter->filter($value)) { + if ($value != static::$filter->filter($value)) { // phpcs:ignore $this->error(self::NOT_ALNUM); return false; } diff --git a/src/Validator/Alpha.php b/src/Validator/Alpha.php index b86ffd01..7a5c3803 100644 --- a/src/Validator/Alpha.php +++ b/src/Validator/Alpha.php @@ -4,11 +4,13 @@ use Laminas\I18n\Filter\Alpha as AlphaFilter; +use function is_string; + class Alpha extends Alnum { - const INVALID = 'alphaInvalid'; - const NOT_ALPHA = 'notAlpha'; - const STRING_EMPTY = 'alphaStringEmpty'; + public const INVALID = 'alphaInvalid'; + public const NOT_ALPHA = 'notAlpha'; + public const STRING_EMPTY = 'alphaStringEmpty'; /** * Alphabetic filter used for validation @@ -25,7 +27,7 @@ class Alpha extends Alnum protected $messageTemplates = [ self::INVALID => 'Invalid type given. String expected', self::NOT_ALPHA => 'The input contains non alphabetic characters', - self::STRING_EMPTY => 'The input is an empty string' + self::STRING_EMPTY => 'The input is an empty string', ]; /** @@ -34,7 +36,7 @@ class Alpha extends Alnum * @var array */ protected $options = [ - 'allowWhiteSpace' => false, // Whether to allow white space characters; off by default + 'allowWhiteSpace' => false, // Whether to allow white space characters; off by default ]; /** diff --git a/src/Validator/DateTime.php b/src/Validator/DateTime.php index fba9b22e..4814d84e 100644 --- a/src/Validator/DateTime.php +++ b/src/Validator/DateTime.php @@ -4,21 +4,24 @@ use IntlDateFormatter; use IntlException; -use Laminas\I18n\Exception as I18nException; use Laminas\Validator\AbstractValidator; use Laminas\Validator\Exception as ValidatorException; use Locale; use Traversable; +use function date_default_timezone_get; +use function intl_is_failure; +use function is_string; + class DateTime extends AbstractValidator { - const INVALID = 'datetimeInvalid'; - const INVALID_DATETIME = 'datetimeInvalidDateTime'; + public const INVALID = 'datetimeInvalid'; + public const INVALID_DATETIME = 'datetimeInvalidDateTime'; /** * Validation failure message template definitions * - * @var string[] + * @var array */ protected $messageTemplates = [ self::INVALID => 'Invalid type given. String expected', @@ -32,14 +35,10 @@ class DateTime extends AbstractValidator */ protected $locale; - /** - * @var int|null - */ + /** @var int|null */ protected $dateType; - /** - * @var int|null - */ + /** @var int|null */ protected $timeType; /** @@ -49,19 +48,13 @@ class DateTime extends AbstractValidator */ protected $timezone; - /** - * @var string|null - */ + /** @var string|null */ protected $pattern; - /** - * @var int|null - */ + /** @var int|null */ protected $calendar; - /** - * @var IntlDateFormatter - */ + /** @var IntlDateFormatter */ protected $formatter; /** @@ -76,16 +69,9 @@ class DateTime extends AbstractValidator * Constructor for the Date validator * * @param array|Traversable $options - * @throws I18nException\ExtensionNotLoadedException if ext/intl is not present */ public function __construct($options = []) { - if (! extension_loaded('intl')) { - throw new I18nException\ExtensionNotLoadedException( - sprintf('%s component requires the intl PHP extension', __NAMESPACE__) - ); - } - // Delaying initialization until we know ext/intl is available $this->dateType = IntlDateFormatter::NONE; $this->timeType = IntlDateFormatter::NONE; @@ -312,7 +298,7 @@ protected function getIntlDateFormatter() $this->getTimeType(), $this->timezone, $this->calendar, - $this->pattern + $this->pattern ?? '' ); $this->formatter->setLenient(false); diff --git a/src/Validator/IsFloat.php b/src/Validator/IsFloat.php index 274e57aa..6c15e801 100644 --- a/src/Validator/IsFloat.php +++ b/src/Validator/IsFloat.php @@ -3,7 +3,6 @@ namespace Laminas\I18n\Validator; use IntlException; -use Laminas\I18n\Exception as I18nException; use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\StringUtils; use Laminas\Stdlib\StringWrapper\StringWrapperInterface; @@ -13,10 +12,19 @@ use NumberFormatter; use Traversable; +use function intl_is_failure; +use function is_bool; +use function is_float; +use function is_int; +use function is_scalar; +use function preg_match; +use function preg_quote; +use function str_replace; + class IsFloat extends AbstractValidator { - const INVALID = 'floatInvalid'; - const NOT_FLOAT = 'notFloat'; + public const INVALID = 'floatInvalid'; + public const NOT_FLOAT = 'notFloat'; /** * Validation failure message template definitions @@ -46,16 +54,9 @@ class IsFloat extends AbstractValidator * Constructor for the integer validator * * @param array|Traversable $options - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present */ public function __construct($options = []) { - if (! extension_loaded('intl')) { - throw new I18nException\ExtensionNotLoadedException( - sprintf('%s component requires the intl PHP extension', __NAMESPACE__) - ); - } - $this->wrapper = StringUtils::getWrapper(); if ($options instanceof Traversable) { @@ -128,10 +129,10 @@ public function isValid($value) if (StringUtils::hasPcreUnicodeSupport()) { $exponentialSymbols = '[Ee' . $formatter->getSymbol(NumberFormatter::EXPONENTIAL_SYMBOL) . ']+'; - $search = '/' . $exponentialSymbols . '/u'; + $search = '/' . $exponentialSymbols . '/u'; } else { $exponentialSymbols = '[Ee]'; - $search = '/' . $exponentialSymbols . '/'; + $search = '/' . $exponentialSymbols . '/'; } if (! preg_match($search, $value)) { @@ -169,7 +170,7 @@ public function isValid($value) } //If we have Unicode support, we can use the real graphemes, otherwise, just the ASCII characters - $decimal = '['. preg_quote($decSeparator, '/') . ']'; + $decimal = '[' . preg_quote($decSeparator, '/') . ']'; $prefix = '[+-]'; $exp = $exponentialSymbols; $numberRange = '0-9'; @@ -177,31 +178,33 @@ public function isValid($value) $suffix = ''; if (StringUtils::hasPcreUnicodeSupport()) { - $prefix = '[' - . preg_quote( + $prefix = '[' + . preg_quote( $formatter->getTextAttribute(NumberFormatter::POSITIVE_PREFIX) - . $formatter->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX) - . $formatter->getSymbol(NumberFormatter::PLUS_SIGN_SYMBOL) - . $formatter->getSymbol(NumberFormatter::MINUS_SIGN_SYMBOL), + . $formatter->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX) + . $formatter->getSymbol(NumberFormatter::PLUS_SIGN_SYMBOL) + . $formatter->getSymbol(NumberFormatter::MINUS_SIGN_SYMBOL), '/' ) . ']{0,3}'; - $suffix = ($formatter->getTextAttribute(NumberFormatter::NEGATIVE_SUFFIX)) + $suffix = $formatter->getTextAttribute(NumberFormatter::NEGATIVE_SUFFIX) ? '[' - . preg_quote( + . preg_quote( $formatter->getTextAttribute(NumberFormatter::POSITIVE_SUFFIX) - . $formatter->getTextAttribute(NumberFormatter::NEGATIVE_SUFFIX) - . $formatter->getSymbol(NumberFormatter::PLUS_SIGN_SYMBOL) - . $formatter->getSymbol(NumberFormatter::MINUS_SIGN_SYMBOL), + . $formatter->getTextAttribute(NumberFormatter::NEGATIVE_SUFFIX) + . $formatter->getSymbol(NumberFormatter::PLUS_SIGN_SYMBOL) + . $formatter->getSymbol(NumberFormatter::MINUS_SIGN_SYMBOL), '/' ) . ']{0,3}' : ''; $numberRange = '\p{N}'; - $useUnicode = 'u'; + $useUnicode = 'u'; } /** + * @see https://www.php.net/float + * * @desc Match against the formal definition of a float. The * exponential number check is modified for RTL non-Latin number * systems (Arabic-Indic numbering). I'm also switching out the period @@ -209,7 +212,6 @@ public function isValid($value) * the integer and decimal notations so add that. This also checks * that a grouping sperator is not in the last GROUPING_SIZE graphemes * of the string - i.e. 10,6 is not valid for en-US. - * @see https://www.php.net/float */ $lnum = '[' . $numberRange . ']+'; @@ -220,20 +222,21 @@ public function isValid($value) // LEFT-TO-RIGHT MARK (U+200E) is messing up everything for the handful // of locales that have it - $lnumSearch = str_replace("\xE2\x80\x8E", '', '/^' .$prefix . $lnum . $suffix . '$/' . $useUnicode); - $dnumSearch = str_replace("\xE2\x80\x8E", '', '/^' .$prefix . $dnum . $suffix . '$/' . $useUnicode); + $lnumSearch = str_replace("\xE2\x80\x8E", '', '/^' . $prefix . $lnum . $suffix . '$/' . $useUnicode); + $dnumSearch = str_replace("\xE2\x80\x8E", '', '/^' . $prefix . $dnum . $suffix . '$/' . $useUnicode); $expDnumSearch = str_replace("\xE2\x80\x8E", '', '/^' . $expDnum . '$/' . $useUnicode); $value = str_replace("\xE2\x80\x8E", '', $value); $unGroupedValue = str_replace($groupSeparator, '', $value); // No strrpos() in wrappers yet. ICU 4.x doesn't have grouping size for // everything. ICU 52 has 3 for ALL locales. - $groupSize = $formatter->getAttribute(NumberFormatter::GROUPING_SIZE) ?: 3; + $groupSize = $formatter->getAttribute(NumberFormatter::GROUPING_SIZE) ?: 3; $lastStringGroup = $this->wrapper->strlen($value) > $groupSize ? $this->wrapper->substr($value, -$groupSize) : $value; - if ((preg_match($lnumSearch, $unGroupedValue) + if ( + (preg_match($lnumSearch, $unGroupedValue) || preg_match($dnumSearch, $unGroupedValue) || preg_match($expDnumSearch, $unGroupedValue)) && false === $this->wrapper->strpos($lastStringGroup, $groupSeparator) diff --git a/src/Validator/IsInt.php b/src/Validator/IsInt.php index 01940358..de343d87 100644 --- a/src/Validator/IsInt.php +++ b/src/Validator/IsInt.php @@ -3,7 +3,6 @@ namespace Laminas\I18n\Validator; use IntlException; -use Laminas\I18n\Exception as I18nException; use Laminas\Stdlib\ArrayUtils; use Laminas\Validator\AbstractValidator; use Laminas\Validator\Exception; @@ -11,11 +10,19 @@ use NumberFormatter; use Traversable; +use function array_key_exists; +use function intl_is_failure; +use function is_bool; +use function is_float; +use function is_int; +use function is_string; +use function strtr; + class IsInt extends AbstractValidator { - const INVALID = 'intInvalid'; - const NOT_INT = 'notInt'; - const NOT_INT_STRICT = 'notIntStrict'; + public const INVALID = 'intInvalid'; + public const NOT_INT = 'notInt'; + public const NOT_INT_STRICT = 'notIntStrict'; /** * Validation failure message template definitions @@ -47,17 +54,9 @@ class IsInt extends AbstractValidator * Constructor for the integer validator * * @param array|Traversable $options - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present */ public function __construct($options = []) { - if (! extension_loaded('intl')) { - throw new I18nException\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } - if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } @@ -161,7 +160,7 @@ public function isValid($value) } try { - $parsedInt = $format->parse($value, NumberFormatter::TYPE_INT64); + $parsedInt = $format->parse((string) $value, NumberFormatter::TYPE_INT64); if (intl_is_failure($format->getErrorCode())) { $this->error(self::NOT_INT); return false; @@ -174,9 +173,9 @@ public function isValid($value) $decimalSep = $format->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); $groupingSep = $format->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); - $valueFiltered = strtr($value, [ + $valueFiltered = strtr((string) $value, [ $groupingSep => '', - $decimalSep => '.', + $decimalSep => '.', ]); if ((string) $parsedInt !== $valueFiltered) { diff --git a/src/Validator/PhoneNumber.php b/src/Validator/PhoneNumber.php index 4b751d7c..4ef31732 100644 --- a/src/Validator/PhoneNumber.php +++ b/src/Validator/PhoneNumber.php @@ -7,11 +7,21 @@ use Locale; use Traversable; +use function array_key_exists; +use function file_exists; +use function in_array; +use function is_scalar; +use function preg_match; +use function strlen; +use function strpos; +use function strtoupper; +use function substr; + class PhoneNumber extends AbstractValidator { - const NO_MATCH = 'phoneNumberNoMatch'; - const UNSUPPORTED = 'phoneNumberUnsupported'; - const INVALID = 'phoneNumberInvalid'; + public const NO_MATCH = 'phoneNumberNoMatch'; + public const UNSUPPORTED = 'phoneNumberUnsupported'; + public const INVALID = 'phoneNumberInvalid'; /** * Validation failure message template definitions @@ -28,6 +38,7 @@ class PhoneNumber extends AbstractValidator * Phone Number Patterns * * @link http://code.google.com/p/libphonenumber/source/browse/trunk/resources/PhoneNumberMetadata.xml + * * @var array */ protected static $phone = []; @@ -101,7 +112,7 @@ public function __construct($options = []) * @param string[]|null $types * @return $this|string[] */ - public function allowedTypes(array $types = null) + public function allowedTypes(?array $types = null) { if (null !== $types) { $this->allowedTypes = $types; diff --git a/src/Validator/PostCode.php b/src/Validator/PostCode.php index 9b513e5e..4fddfbc2 100644 --- a/src/Validator/PostCode.php +++ b/src/Validator/PostCode.php @@ -2,7 +2,6 @@ namespace Laminas\I18n\Validator; -use Laminas\I18n\Exception as I18nException; use Laminas\Stdlib\ArrayUtils; use Laminas\Validator\AbstractValidator; use Laminas\Validator\Callback; @@ -10,12 +9,19 @@ use Locale; use Traversable; +use function array_key_exists; +use function is_callable; +use function is_int; +use function is_string; +use function preg_match; +use function strlen; + class PostCode extends AbstractValidator { - const INVALID = 'postcodeInvalid'; - const NO_MATCH = 'postcodeNoMatch'; - const SERVICE = 'postcodeService'; - const SERVICEFAILURE = 'postcodeServiceFailure'; + public const INVALID = 'postcodeInvalid'; + public const NO_MATCH = 'postcodeNoMatch'; + public const SERVICE = 'postcodeService'; + public const SERVICEFAILURE = 'postcodeServiceFailure'; /** * Validation failure message template definitions @@ -225,17 +231,9 @@ class PostCode extends AbstractValidator * Accepts a string locale and/or "format". * * @param array|Traversable $options - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present */ public function __construct($options = []) { - if (! extension_loaded('intl')) { - throw new I18nException\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } - if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } @@ -387,7 +385,7 @@ public function isValid($value) } } - if (! preg_match($format, $value)) { + if (! preg_match($format, (string) $value)) { $this->error(self::NO_MATCH); return false; } diff --git a/src/View/Helper/AbstractTranslatorHelper.php b/src/View/Helper/AbstractTranslatorHelper.php index d71ceeaa..45c94ff8 100644 --- a/src/View/Helper/AbstractTranslatorHelper.php +++ b/src/View/Helper/AbstractTranslatorHelper.php @@ -37,7 +37,7 @@ abstract class AbstractTranslatorHelper extends AbstractHelper implements * @param string|null $textDomain Default is null, which skips setTranslatorTextDomain * @return $this */ - public function setTranslator(Translator $translator = null, $textDomain = null) + public function setTranslator(?Translator $translator = null, $textDomain = null) { $this->translator = $translator; if (null !== $textDomain) { diff --git a/src/View/Helper/CurrencyFormat.php b/src/View/Helper/CurrencyFormat.php index f4fda047..7bfb412a 100644 --- a/src/View/Helper/CurrencyFormat.php +++ b/src/View/Helper/CurrencyFormat.php @@ -2,11 +2,15 @@ namespace Laminas\I18n\View\Helper; -use Laminas\I18n\Exception; use Laminas\View\Helper\AbstractHelper; use Locale; use NumberFormatter; +use function md5; +use function preg_quote; +use function preg_replace; +use function sprintf; + /** * View helper for formatting currency. */ @@ -55,19 +59,6 @@ class CurrencyFormat extends AbstractHelper */ protected $correctionNeeded = false; - /** - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present - */ - public function __construct() - { - if (! extension_loaded('intl')) { - throw new Exception\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } - } - /** * Format a number * @@ -136,7 +127,7 @@ protected function formatCurrency( $this->correctionNeeded = false; } else { $this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 0); - $defaultCurrencyCode = $this->formatters[$formatterId]->getTextAttribute(NumberFormatter::CURRENCY_CODE); + $defaultCurrencyCode = $this->formatters[$formatterId]->getTextAttribute(NumberFormatter::CURRENCY_CODE); $this->correctionNeeded = $defaultCurrencyCode !== $currencyCode; } @@ -248,7 +239,6 @@ public function shouldShowDecimals() /** * @param string $formattedNumber - * @param NumberFormatter $formatter * @param string $locale * @param string $currencyCode * @return string diff --git a/src/View/Helper/DateFormat.php b/src/View/Helper/DateFormat.php index b2780a54..0089313c 100644 --- a/src/View/Helper/DateFormat.php +++ b/src/View/Helper/DateFormat.php @@ -5,10 +5,12 @@ use DateTimeInterface; use IntlCalendar; use IntlDateFormatter; -use Laminas\I18n\Exception; use Laminas\View\Helper\AbstractHelper; use Locale; +use function date_default_timezone_get; +use function md5; + /** * View helper for formatting dates. */ @@ -31,23 +33,10 @@ class DateFormat extends AbstractHelper /** * Formatter instances * - * @var array + * @var array */ protected $formatters = []; - /** - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present - */ - public function __construct() - { - if (! extension_loaded('intl')) { - throw new Exception\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } - } - /** * Format a date * @@ -70,7 +59,7 @@ public function __invoke( } $timezone = $this->getTimezone(); - $formatterId = md5($dateType . "\0" . $timeType . "\0" . $locale . "\0" . $pattern . "\0" . $timezone); + $formatterId = md5($dateType . "\0" . $timeType . "\0" . $locale . "\0" . (string) $pattern . "\0" . $timezone); if (! isset($this->formatters[$formatterId])) { $this->formatters[$formatterId] = new IntlDateFormatter( @@ -79,7 +68,7 @@ public function __invoke( $timeType, $timezone, IntlDateFormatter::GREGORIAN, - $pattern + $pattern ?? '' ); } @@ -120,13 +109,9 @@ public function getLocale() */ public function setTimezone($timezone) { - $this->timezone = (string) $timezone; - - // The method setTimeZoneId is deprecated as of PHP 5.5.0 - $setTimeZoneMethodName = (PHP_VERSION_ID < 50500) ? 'setTimeZoneId' : 'setTimeZone'; - + $this->timezone = $timezone; foreach ($this->formatters as $formatter) { - $formatter->$setTimeZoneMethodName($this->timezone); + $formatter->setTimeZone($this->timezone); } return $this; diff --git a/src/View/Helper/NumberFormat.php b/src/View/Helper/NumberFormat.php index b0d0866d..0ccde6cf 100644 --- a/src/View/Helper/NumberFormat.php +++ b/src/View/Helper/NumberFormat.php @@ -2,11 +2,15 @@ namespace Laminas\I18n\View\Helper; -use Laminas\I18n\Exception; use Laminas\View\Helper\AbstractHelper; use Locale; use NumberFormatter; +use function is_array; +use function is_int; +use function md5; +use function serialize; + /** * View helper for formatting dates. */ @@ -54,19 +58,6 @@ class NumberFormat extends AbstractHelper */ protected $locale; - /** - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present - */ - public function __construct() - { - if (! extension_loaded('intl')) { - throw new Exception\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } - } - /** * Format a number * @@ -84,7 +75,7 @@ public function __invoke( $formatType = null, $locale = null, $decimals = null, - array $textAttributes = null + ?array $textAttributes = null ) { if (null === $locale) { $locale = $this->getLocale(); diff --git a/src/View/Helper/Plural.php b/src/View/Helper/Plural.php index 53bea389..8874bde4 100644 --- a/src/View/Helper/Plural.php +++ b/src/View/Helper/Plural.php @@ -6,6 +6,9 @@ use Laminas\I18n\Translator\Plural\Rule as PluralRule; use Laminas\View\Helper\AbstractHelper; +use function is_array; +use function sprintf; + /** * Helper for rendering text based on a count number (like the I18n plural translation helper, but when translation * is not needed). @@ -27,19 +30,6 @@ class Plural extends AbstractHelper */ protected $rule; - /** - * @throws Exception\ExtensionNotLoadedException if ext/intl is not present - */ - public function __construct() - { - if (! extension_loaded('intl')) { - throw new Exception\ExtensionNotLoadedException(sprintf( - '%s component requires the intl PHP extension', - __NAMESPACE__ - )); - } - } - /** * Given an array of strings, a number and, if wanted, an optional locale (the default one is used * otherwise), this picks the right string according to plural rules of the locale diff --git a/src/View/HelperConfig.php b/src/View/HelperConfig.php index 9a8ed4ff..99ae00aa 100644 --- a/src/View/HelperConfig.php +++ b/src/View/HelperConfig.php @@ -6,6 +6,8 @@ use Laminas\ServiceManager\Factory\InvokableFactory; use Laminas\ServiceManager\ServiceManager; +use function method_exists; + /** * Service manager configuration for i18n view helpers. * @@ -15,62 +17,66 @@ class HelperConfig implements ConfigInterface { /** * Common aliases for helpers + * * @var array */ protected $aliases = [ - 'currencyformat' => Helper\CurrencyFormat::class, - 'currencyFormat' => Helper\CurrencyFormat::class, - 'CurrencyFormat' => Helper\CurrencyFormat::class, - 'dateformat' => Helper\DateFormat::class, - 'dateFormat' => Helper\DateFormat::class, - 'DateFormat' => Helper\DateFormat::class, - 'numberformat' => Helper\NumberFormat::class, - 'numberFormat' => Helper\NumberFormat::class, - 'NumberFormat' => Helper\NumberFormat::class, - 'plural' => Helper\Plural::class, - 'Plural' => Helper\Plural::class, - 'translate' => Helper\Translate::class, - 'Translate' => Helper\Translate::class, + 'currencyformat' => Helper\CurrencyFormat::class, + 'currencyFormat' => Helper\CurrencyFormat::class, + 'CurrencyFormat' => Helper\CurrencyFormat::class, + 'dateformat' => Helper\DateFormat::class, + 'dateFormat' => Helper\DateFormat::class, + 'DateFormat' => Helper\DateFormat::class, + 'numberformat' => Helper\NumberFormat::class, + 'numberFormat' => Helper\NumberFormat::class, + 'NumberFormat' => Helper\NumberFormat::class, + 'plural' => Helper\Plural::class, + 'Plural' => Helper\Plural::class, + 'translate' => Helper\Translate::class, + 'Translate' => Helper\Translate::class, 'translateplural' => Helper\TranslatePlural::class, 'translatePlural' => Helper\TranslatePlural::class, 'TranslatePlural' => Helper\TranslatePlural::class, // Legacy Zend Framework aliases + // @codingStandardsIgnoreStart \Zend\I18n\View\Helper\CurrencyFormat::class => Helper\CurrencyFormat::class, \Zend\I18n\View\Helper\DateFormat::class => Helper\DateFormat::class, \Zend\I18n\View\Helper\NumberFormat::class => Helper\NumberFormat::class, \Zend\I18n\View\Helper\Plural::class => Helper\Plural::class, \Zend\I18n\View\Helper\Translate::class => Helper\Translate::class, \Zend\I18n\View\Helper\TranslatePlural::class => Helper\TranslatePlural::class, + // @codingStandardsIgnoreEnd // v2 normalized FQCNs - 'zendi18nviewhelpercurrencyformat' => Helper\CurrencyFormat::class, - 'zendi18nviewhelperdateformat' => Helper\DateFormat::class, - 'zendi18nviewhelpernumberformat' => Helper\NumberFormat::class, - 'zendi18nviewhelperplural' => Helper\Plural::class, - 'zendi18nviewhelpertranslate' => Helper\Translate::class, + 'zendi18nviewhelpercurrencyformat' => Helper\CurrencyFormat::class, + 'zendi18nviewhelperdateformat' => Helper\DateFormat::class, + 'zendi18nviewhelpernumberformat' => Helper\NumberFormat::class, + 'zendi18nviewhelperplural' => Helper\Plural::class, + 'zendi18nviewhelpertranslate' => Helper\Translate::class, 'zendi18nviewhelpertranslateplural' => Helper\TranslatePlural::class, ]; /** * Factories for included helpers. + * * @var array */ protected $factories = [ - Helper\CurrencyFormat::class => InvokableFactory::class, - Helper\DateFormat::class => InvokableFactory::class, - Helper\NumberFormat::class => InvokableFactory::class, - Helper\Plural::class => InvokableFactory::class, - Helper\Translate::class => InvokableFactory::class, + Helper\CurrencyFormat::class => InvokableFactory::class, + Helper\DateFormat::class => InvokableFactory::class, + Helper\NumberFormat::class => InvokableFactory::class, + Helper\Plural::class => InvokableFactory::class, + Helper\Translate::class => InvokableFactory::class, Helper\TranslatePlural::class => InvokableFactory::class, // Legacy (v2) due to alias resolution; canonical form of resolved // alias is used to look up the factory, while the non-normalized // resolved alias is used as the requested name passed to the factory. - 'laminasi18nviewhelpercurrencyformat' => InvokableFactory::class, - 'laminasi18nviewhelperdateformat' => InvokableFactory::class, - 'laminasi18nviewhelpernumberformat' => InvokableFactory::class, - 'laminasi18nviewhelperplural' => InvokableFactory::class, - 'laminasi18nviewhelpertranslate' => InvokableFactory::class, + 'laminasi18nviewhelpercurrencyformat' => InvokableFactory::class, + 'laminasi18nviewhelperdateformat' => InvokableFactory::class, + 'laminasi18nviewhelpernumberformat' => InvokableFactory::class, + 'laminasi18nviewhelperplural' => InvokableFactory::class, + 'laminasi18nviewhelpertranslate' => InvokableFactory::class, 'laminasi18nviewhelpertranslateplural' => InvokableFactory::class, ]; @@ -78,7 +84,6 @@ class HelperConfig implements ConfigInterface * Configure the provided service manager instance with the configuration * in this class. * - * @param ServiceManager $serviceManager * @return ServiceManager */ public function configureServiceManager(ServiceManager $serviceManager) @@ -108,7 +113,7 @@ public function configureServiceManager(ServiceManager $serviceManager) public function toArray() { return [ - 'aliases' => $this->aliases, + 'aliases' => $this->aliases, 'factories' => $this->factories, ]; } diff --git a/test/Filter/AlnumTest.php b/test/Filter/AlnumTest.php index 6b6da6c6..32250d84 100644 --- a/test/Filter/AlnumTest.php +++ b/test/Filter/AlnumTest.php @@ -1,69 +1,48 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->filter = new AlnumFilter(); - - $this->locale = Locale::getDefault(); - $language = Locale::getPrimaryLanguage($this->locale); + parent::setUp(); + $this->filter = new AlnumFilter(); + $language = Locale::getPrimaryLanguage(Locale::getDefault()); static::$meansEnglishAlphabet = $language === 'ja'; static::$unicodeEnabled = (bool) @preg_match('/\pL/u', 'a'); } /** * Ensures that the filter follows expected behavior - * - * @return void */ - public function testBasic() + public function testBasic(): void { if (! static::$unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match @@ -72,7 +51,7 @@ public function testBasic() 'abc 123' => 'abc123', 'abcxyz' => 'abcxyz', 'AZ@#4.3' => 'AZ43', - '' => '' + '' => '', ]; } elseif (static::$meansEnglishAlphabet) { // The Alphabet means english alphabet. @@ -85,20 +64,20 @@ public function testBasic() * The third contains various multibyte or singebyte characters. */ $valuesExpected = [ - 'aABb3456' => 'aB35', - 'z7 Y8 x9' => 'z8x', + 'aABb3456' => 'aB35', + 'z7 Y8 x9' => 'z8x', ',s1.2r3#:q,' => 's12rq', ]; } else { //The Alphabet means each language's alphabet. $valuesExpected = [ - 'abc123' => 'abc123', - 'abc 123' => 'abc123', - 'abcxyz' => 'abcxyz', - 'če2t3ně' => 'če2t3ně', - 'grz5e4gżółka' => 'grz5e4gżółka', - 'Be3l5gië' => 'Be3l5gië', - '' => '' + 'abc123' => 'abc123', + 'abc 123' => 'abc123', + 'abcxyz' => 'abcxyz', + 'če2t3ně' => 'če2t3ně', + 'grz5e4gżółka' => 'grz5e4gżółka', + 'Be3l5gië' => 'Be3l5gië', + '' => '', ]; } @@ -110,10 +89,8 @@ public function testBasic() /** * Ensures that the allowWhiteSpace option works as expected - * - * @return void */ - public function testAllowWhiteSpace() + public function testAllowWhiteSpace(): void { $this->filter->setAllowWhiteSpace(true); @@ -126,13 +103,13 @@ public function testAllowWhiteSpace() 'AZ@#4.3' => 'AZ43', '' => '', "\n" => "\n", - " \t " => " \t " + " \t " => " \t ", ]; } elseif (static::$meansEnglishAlphabet) { //The Alphabet means english alphabet. $valuesExpected = [ 'a B 45' => 'a B 5', - 'z3 x' => 'z3x' + 'z3 x' => 'z3x', ]; } else { //The Alphabet means each language's alphabet. @@ -153,7 +130,7 @@ public function testAllowWhiteSpace() } } - public function testFilterSupportArray() + public function testFilterSupportArray(): void { $filter = new AlnumFilter(); @@ -162,7 +139,7 @@ public function testFilterSupportArray() 'abc 123' => 'abc123', 'abcxyz' => 'abcxyz', 'AZ@#4.3' => 'AZ43', - '' => '' + '' => '', ]; $actual = $filter->filter(array_keys($values)); @@ -170,19 +147,20 @@ public function testFilterSupportArray() $this->assertEquals(array_values($values), $actual); } - public function returnUnfilteredDataProvider() + /** @return array */ + public function returnUnfilteredDataProvider(): array { return [ [null], - [new \stdClass()] + [new stdClass()], ]; } /** * @dataProvider returnUnfilteredDataProvider - * @return void + * @param mixed $input */ - public function testReturnUnfiltered($input) + public function testReturnUnfiltered($input): void { $filter = new AlnumFilter(); diff --git a/test/Filter/AlphaTest.php b/test/Filter/AlphaTest.php index a69dd386..14acd9a0 100644 --- a/test/Filter/AlphaTest.php +++ b/test/Filter/AlphaTest.php @@ -1,22 +1,21 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->filter = new AlphaFilter(); - - $this->locale = Locale::getDefault(); - $language = Locale::getPrimaryLanguage($this->locale); + parent::setUp(); + $this->filter = new AlphaFilter(); + $language = Locale::getPrimaryLanguage(Locale::getDefault()); self::$meansEnglishAlphabet = $language === 'ja'; self::$unicodeEnabled = (bool) @preg_match('/\pL/u', 'a'); } /** * Ensures that the filter follows expected behavior - * - * @return void */ - public function testBasic() + public function testBasic(): void { if (! self::$unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match $valuesExpected = [ - 'abc123' => 'abc', - 'abc 123' => 'abc', - 'abcxyz' => 'abcxyz', - '' => '' + 'abc123' => 'abc', + 'abc 123' => 'abc', + 'abcxyz' => 'abcxyz', + '' => '', ]; } elseif (self::$meansEnglishAlphabet) { //The Alphabet means english alphabet. @@ -86,21 +67,21 @@ public function testBasic() $valuesExpected = [ 'aABbc' => 'aBc', 'z Y x' => 'zx', - 'W1v3U4t' => 'vt', + 'W1v3U4t' => 'vt', ',sй.rλ:qν_p' => 'srqp', - 'onml' => 'onml' + 'onml' => 'onml', ]; } else { //The Alphabet means each language's alphabet. $valuesExpected = [ - 'abc123' => 'abc', - 'abc 123' => 'abc', - 'abcxyz' => 'abcxyz', - 'četně' => 'četně', - 'لعربية' => 'لعربية', - 'grzegżółka' => 'grzegżółka', - 'België' => 'België', - '' => '' + 'abc123' => 'abc', + 'abc 123' => 'abc', + 'abcxyz' => 'abcxyz', + 'četně' => 'četně', + 'لعربية' => 'لعربية', + 'grzegżółka' => 'grzegżółka', + 'België' => 'België', + '' => '', ]; } @@ -112,44 +93,42 @@ public function testBasic() /** * Ensures that the filter follows expected behavior - * - * @return void */ - public function testAllowWhiteSpace() + public function testAllowWhiteSpace(): void { $this->filter->setAllowWhiteSpace(true); if (! self::$unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match $valuesExpected = [ - 'abc123' => 'abc', - 'abc 123' => 'abc ', - 'abcxyz' => 'abcxyz', - '' => '', - "\n" => "\n", - " \t " => " \t " + 'abc123' => 'abc', + 'abc 123' => 'abc ', + 'abcxyz' => 'abcxyz', + '' => '', + "\n" => "\n", + " \t " => " \t ", ]; } if (self::$meansEnglishAlphabet) { //The Alphabet means english alphabet. $valuesExpected = [ - 'a B' => 'a B', - 'zY x' => 'zx' + 'a B' => 'a B', + 'zY x' => 'zx', ]; } else { //The Alphabet means each language's alphabet. $valuesExpected = [ - 'abc123' => 'abc', - 'abc 123' => 'abc ', - 'abcxyz' => 'abcxyz', - 'četně' => 'četně', - 'لعربية' => 'لعربية', - 'grzegżółka' => 'grzegżółka', - 'België' => 'België', - '' => '', - "\n" => "\n", - " \t " => " \t " - ]; + 'abc123' => 'abc', + 'abc 123' => 'abc ', + 'abcxyz' => 'abcxyz', + 'četně' => 'četně', + 'لعربية' => 'لعربية', + 'grzegżółka' => 'grzegżółka', + 'België' => 'België', + '' => '', + "\n" => "\n", + " \t " => " \t ", + ]; } foreach ($valuesExpected as $input => $expected) { @@ -158,15 +137,15 @@ public function testAllowWhiteSpace() } } - public function testFilterSupportArray() + public function testFilterSupportArray(): void { $filter = new AlphaFilter(); $values = [ - 'abc123' => 'abc', - 'abc 123' => 'abc', - 'abcxyz' => 'abcxyz', - '' => '' + 'abc123' => 'abc', + 'abc 123' => 'abc', + 'abcxyz' => 'abcxyz', + '' => '', ]; $actual = $filter->filter(array_keys($values)); @@ -174,19 +153,20 @@ public function testFilterSupportArray() $this->assertEquals(array_values($values), $actual); } - public function returnUnfilteredDataProvider() + /** @return array */ + public function returnUnfilteredDataProvider(): array { return [ [null], - [new \stdClass()] + [new stdClass()], ]; } /** * @dataProvider returnUnfilteredDataProvider - * @return void + * @param mixed $input */ - public function testReturnUnfiltered($input) + public function testReturnUnfiltered($input): void { $filter = new AlphaFilter(); diff --git a/test/Filter/NumberFormatTest.php b/test/Filter/NumberFormatTest.php index 062ea3aa..9e45df40 100644 --- a/test/Filter/NumberFormatTest.php +++ b/test/Filter/NumberFormatTest.php @@ -1,32 +1,28 @@ markTestSkipped('ext/intl not enabled'); - } - } - - public function testConstructWithOptions() + public function testConstructWithOptions(): void { $filter = new NumberFormatFilter([ 'locale' => 'en_US', - 'style' => NumberFormatter::DECIMAL + 'style' => NumberFormatter::DECIMAL, ]); $this->assertEquals('en_US', $filter->getLocale()); $this->assertEquals(NumberFormatter::DECIMAL, $filter->getStyle()); } - public function testConstructWithParameters() + public function testConstructWithParameters(): void { $filter = new NumberFormatFilter('en_US', NumberFormatter::DECIMAL); @@ -34,72 +30,46 @@ public function testConstructWithParameters() $this->assertEquals(NumberFormatter::DECIMAL, $filter->getStyle()); } - - /** - * @param $locale - * @param $style - * @param $type - * @param $value - * @param $expected - * @dataProvider numberToFormattedProvider - */ - public function testNumberToFormatted($locale, $style, $type, $value, $expected) - { - $filter = new NumberFormatFilter($locale, $style, $type); - $this->assertEquals($expected, $filter->filter($value)); - } - - /** - * @param $locale - * @param $style - * @param $type - * @param $value - * @param $expected - * @dataProvider formattedToNumberProvider - */ - public function testFormattedToNumber($locale, $style, $type, $value, $expected) + /** @return array */ + public function numberToFormattedProvider(): array { - $filter = new NumberFormatFilter($locale, $style, $type); - $this->assertEquals($expected, $filter->filter($value)); - } - - public function numberToFormattedProvider() - { - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } - return [ [ 'en_US', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE, 1234567.8912346, - '1,234,567.891' + '1,234,567.891', ], [ 'de_DE', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE, 1234567.8912346, - '1.234.567,891' + '1.234.567,891', ], [ 'ru_RU', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE, 1234567.8912346, - '1 234 567,891' + '1 234 567,891', ], ]; } - public function formattedToNumberProvider() + /** + * @dataProvider numberToFormattedProvider + */ + public function testNumberToFormatted(string $locale, int $style, int $type, float $value, string $expected): void { - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } + $filter = new NumberFormatFilter($locale, $style, $type); + $this->assertEquals($expected, $filter->filter($value)); + } + /** @return array */ + public function formattedToNumberProvider() + { return [ [ 'en_US', @@ -125,24 +95,35 @@ public function formattedToNumberProvider() ]; } + /** + * @dataProvider formattedToNumberProvider + */ + public function testFormattedToNumber(string $locale, int $style, int $type, string $value, float $expected): void + { + $filter = new NumberFormatFilter($locale, $style, $type); + $this->assertEquals($expected, $filter->filter($value)); + } - public function returnUnfilteredDataProvider() + /** @return array */ + public function returnUnfilteredDataProvider(): array { return [ [null], - [new \stdClass()], - [[ - '1.234.567,891', - '1.567,891' - ]] + [new stdClass()], + [ + [ + '1.234.567,891', + '1.567,891', + ], + ], ]; } /** * @dataProvider returnUnfilteredDataProvider - * @return void + * @param mixed $input */ - public function testReturnUnfiltered($input) + public function testReturnUnfiltered($input): void { $filter = new NumberFormatFilter('de_AT', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE); diff --git a/test/Filter/NumberParseTest.php b/test/Filter/NumberParseTest.php index 16c5f46c..cd01e14a 100644 --- a/test/Filter/NumberParseTest.php +++ b/test/Filter/NumberParseTest.php @@ -1,32 +1,27 @@ markTestSkipped('ext/intl not enabled'); - } - } - - public function testConstructWithOptions() + public function testConstructWithOptions(): void { $filter = new NumberParseFilter([ 'locale' => 'en_US', - 'style' => NumberFormatter::DECIMAL + 'style' => NumberFormatter::DECIMAL, ]); $this->assertEquals('en_US', $filter->getLocale()); $this->assertEquals(NumberFormatter::DECIMAL, $filter->getStyle()); } - public function testConstructWithParameters() + public function testConstructWithParameters(): void { $filter = new NumberParseFilter('en_US', NumberFormatter::DECIMAL); @@ -35,20 +30,16 @@ public function testConstructWithParameters() } /** - * @param $locale - * @param $style - * @param $type - * @param $value - * @param $expected * @dataProvider formattedToNumberProvider */ - public function testFormattedToNumber($locale, $style, $type, $value, $expected) + public function testFormattedToNumber(string $locale, int $style, int $type, string $value, float $expected): void { $filter = new NumberParseFilter($locale, $style, $type); $this->assertSame($expected, $filter->filter($value)); } - public static function formattedToNumberProvider() + /** @return array */ + public static function formattedToNumberProvider(): array { return [ [ diff --git a/test/ModuleTest.php b/test/ModuleTest.php index a50d1d6f..356fec20 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -1,15 +1,20 @@ module = new Module(); } diff --git a/test/TestAsset/ModuleEventInterface.php b/test/TestAsset/ModuleEventInterface.php index e4d1d3a8..2f9d07c3 100644 --- a/test/TestAsset/ModuleEventInterface.php +++ b/test/TestAsset/ModuleEventInterface.php @@ -1,5 +1,7 @@ defaultLocale = Locale::getDefault(); + self::assertNotNull($this->defaultLocale); + } + + protected function tearDown(): void + { + Locale::setDefault($this->defaultLocale); + parent::tearDown(); + } +} diff --git a/test/Translator/Loader/GettextTest.php b/test/Translator/Loader/GettextTest.php index 702a409c..9837b7ac 100644 --- a/test/Translator/Loader/GettextTest.php +++ b/test/Translator/Loader/GettextTest.php @@ -1,24 +1,29 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->originalLocale = Locale::getDefault(); + parent::setUp(); Locale::setDefault('en_EN'); $this->testFilesDir = realpath(__DIR__ . '/../_files'); @@ -29,52 +34,50 @@ protected function setUp(): void protected function tearDown(): void { - if (extension_loaded('intl')) { - Locale::setDefault($this->originalLocale); - set_include_path($this->originalIncludePath); - } + set_include_path($this->originalIncludePath); + parent::tearDown(); } - public function testLoaderFailsToLoadMissingFile() + public function testLoaderFailsToLoadMissingFile(): void { $loader = new GettextLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Could not find or open file'); $loader->load('en_EN', 'missing'); } - public function testLoaderFailsToLoadBadFile() + public function testLoaderFailsToLoadBadFile(): void { $loader = new GettextLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('is not a valid gettext file'); $loader->load('en_EN', $this->testFilesDir . '/failed.mo'); } - public function testLoaderLoadsEmptyFile() + public function testLoaderLoadsEmptyFile(): void { $loader = new GettextLoader(); $domain = $loader->load('en_EN', $this->testFilesDir . '/translation_empty.mo'); - $this->assertInstanceOf('Laminas\I18n\Translator\TextDomain', $domain); + $this->assertInstanceOf(TextDomain::class, $domain); } - public function testLoaderLoadsBigEndianFile() + public function testLoaderLoadsBigEndianFile(): void { $loader = new GettextLoader(); $domain = $loader->load('en_EN', $this->testFilesDir . '/translation_bigendian.mo'); - $this->assertInstanceOf('Laminas\I18n\Translator\TextDomain', $domain); + $this->assertInstanceOf(TextDomain::class, $domain); } - public function testLoaderReturnsValidTextDomain() + public function testLoaderReturnsValidTextDomain(): void { - $loader = new GettextLoader(); + $loader = new GettextLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en.mo'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsPluralRules() + public function testLoaderLoadsPluralRules(): void { $loader = new GettextLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en.mo'); @@ -85,7 +88,7 @@ public function testLoaderLoadsPluralRules() $this->assertEquals(2, $textDomain->getPluralRule()->evaluate(10)); } - public function testLoaderLoadsFromIncludePath() + public function testLoaderLoadsFromIncludePath(): void { $loader = new GettextLoader(); $loader->setUseIncludePath(true); @@ -95,7 +98,7 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsFromPhar() + public function testLoaderLoadsFromPhar(): void { $loader = new GettextLoader(); $loader->setUseIncludePath(true); @@ -105,11 +108,7 @@ public function testLoaderLoadsFromPhar() $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - /** - * @group 6762 - * @group 6765 - */ - public function testLoaderLoadsPlural() + public function testLoaderLoadsPlural(): void { $loader = new GettextLoader(); diff --git a/test/Translator/Loader/IniTest.php b/test/Translator/Loader/IniTest.php index a180cb53..dd5036c6 100644 --- a/test/Translator/Loader/IniTest.php +++ b/test/Translator/Loader/IniTest.php @@ -1,20 +1,29 @@ testFilesDir = realpath(__DIR__ . '/../_files'); - + parent::setUp(); + $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); set_include_path($this->testFilesDir . PATH_SEPARATOR . $this->testFilesDir . '/translations.phar'); } @@ -22,67 +31,68 @@ protected function setUp(): void protected function tearDown(): void { set_include_path($this->originalIncludePath); + parent::tearDown(); } - public function testLoaderFailsToLoadMissingFile() + public function testLoaderFailsToLoadMissingFile(): void { $loader = new IniLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Could not find or open file'); $loader->load('en_EN', 'missing'); } - public function testLoaderLoadsEmptyFile() + public function testLoaderLoadsEmptyFile(): void { - $loader = new IniLoader(); + $loader = new IniLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_empty.ini'); - $this->assertInstanceOf('Laminas\I18n\Translator\TextDomain', $textDomain); + $this->assertInstanceOf(TextDomain::class, $textDomain); } - public function testLoaderFailsToLoadNonArray() + public function testLoaderFailsToLoadNonArray(): void { $loader = new IniLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Each INI row must be an array with message and translation'); $loader->load('en_EN', $this->testFilesDir . '/failed.ini'); } - public function testLoaderFailsToLoadBadSyntax() + public function testLoaderFailsToLoadBadSyntax(): void { $loader = new IniLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Each INI row must be an array with message and translation'); $loader->load('en_EN', $this->testFilesDir . '/failed_syntax.ini'); } - public function testLoaderReturnsValidTextDomain() + public function testLoaderReturnsValidTextDomain(): void { - $loader = new IniLoader(); + $loader = new IniLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en.ini'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderReturnsValidTextDomainWithFileWithoutPlural() + public function testLoaderReturnsValidTextDomainWithFileWithoutPlural(): void { - $loader = new IniLoader(); + $loader = new IniLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en_without_plural.ini'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderReturnsValidTextDomainWithSimpleSyntax() + public function testLoaderReturnsValidTextDomainWithSimpleSyntax(): void { - $loader = new IniLoader(); + $loader = new IniLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en_simple_syntax.ini'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsPluralRules() + public function testLoaderLoadsPluralRules(): void { $loader = new IniLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en.ini'); @@ -93,7 +103,7 @@ public function testLoaderLoadsPluralRules() $this->assertEquals(2, $textDomain->getPluralRule()->evaluate(10)); } - public function testLoaderLoadsFromIncludePath() + public function testLoaderLoadsFromIncludePath(): void { $loader = new IniLoader(); $loader->setUseIncludePath(true); @@ -103,7 +113,7 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsFromPhar() + public function testLoaderLoadsFromPhar(): void { $loader = new IniLoader(); $loader->setUseIncludePath(true); diff --git a/test/Translator/Loader/PhpArrayTest.php b/test/Translator/Loader/PhpArrayTest.php index 3ad457ed..5c667bfe 100644 --- a/test/Translator/Loader/PhpArrayTest.php +++ b/test/Translator/Loader/PhpArrayTest.php @@ -1,73 +1,75 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->originalLocale = Locale::getDefault(); + parent::setUp(); Locale::setDefault('en_EN'); - $this->testFilesDir = realpath(__DIR__ . '/../_files'); - + $this->testFilesDir = realpath(__DIR__ . '/../_files'); $this->originalIncludePath = get_include_path(); set_include_path($this->testFilesDir . PATH_SEPARATOR . $this->testFilesDir . '/translations.phar'); } protected function tearDown(): void { - if (extension_loaded('intl')) { - Locale::setDefault($this->originalLocale); - set_include_path($this->originalIncludePath); - } + set_include_path($this->originalIncludePath); + parent::tearDown(); } - public function testLoaderFailsToLoadMissingFile() + public function testLoaderFailsToLoadMissingFile(): void { $loader = new PhpArrayLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Could not find or open file'); $loader->load('en_EN', 'missing'); } - public function testLoaderFailsToLoadNonArray() + public function testLoaderFailsToLoadNonArray(): void { $loader = new PhpArrayLoader(); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected an array, but received'); $loader->load('en_EN', $this->testFilesDir . '/failed.php'); } - public function testLoaderLoadsEmptyArray() + public function testLoaderLoadsEmptyArray(): void { - $loader = new PhpArrayLoader(); + $loader = new PhpArrayLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_empty.php'); - $this->assertInstanceOf('Laminas\I18n\Translator\TextDomain', $textDomain); + $this->assertInstanceOf(TextDomain::class, $textDomain); } - public function testLoaderReturnsValidTextDomain() + public function testLoaderReturnsValidTextDomain(): void { - $loader = new PhpArrayLoader(); + $loader = new PhpArrayLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en.php'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsPluralRules() + public function testLoaderLoadsPluralRules(): void { $loader = new PhpArrayLoader(); $textDomain = $loader->load('en_EN', $this->testFilesDir . '/translation_en.php'); @@ -78,7 +80,7 @@ public function testLoaderLoadsPluralRules() $this->assertEquals(2, $textDomain->getPluralRule()->evaluate(10)); } - public function testLoaderLoadsFromIncludePath() + public function testLoaderLoadsFromIncludePath(): void { $loader = new PhpArrayLoader(); $loader->setUseIncludePath(true); @@ -88,7 +90,7 @@ public function testLoaderLoadsFromIncludePath() $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsFromPhar() + public function testLoaderLoadsFromPhar(): void { $loader = new PhpArrayLoader(); $loader->setUseIncludePath(true); diff --git a/test/Translator/Loader/PhpMemoryArrayTest.php b/test/Translator/Loader/PhpMemoryArrayTest.php index ddcc8338..dc50b89d 100644 --- a/test/Translator/Loader/PhpMemoryArrayTest.php +++ b/test/Translator/Loader/PhpMemoryArrayTest.php @@ -1,76 +1,70 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->originalLocale = Locale::getDefault(); + parent::setUp(); Locale::setDefault('en_US'); $this->testFilesDir = realpath(__DIR__ . '/../_files/phpmemoryarray'); } - protected function tearDown(): void - { - if (extension_loaded('intl')) { - Locale::setDefault($this->originalLocale); - } - } - public function testLoaderFailsToLoadNonArray() + public function testLoaderFailsToLoadNonArray(): void { $loader = new PhpMemoryArrayLoader('foo'); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected an array, but received'); $loader->load('en_US', 'default'); } - public function testLoaderFailsToLoadMissingTextDomain() + public function testLoaderFailsToLoadMissingTextDomain(): void { $loader = new PhpMemoryArrayLoader([]); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected textdomain "default" to be an array, but it is not set'); $loader->load('en_US', 'default'); } - public function testLoaderFailsToLoadNonArrayLocale() + public function testLoaderFailsToLoadNonArrayLocale(): void { $loader = new PhpMemoryArrayLoader(['default' => []]); - $this->expectException('Laminas\I18n\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected locale "en_US" to be an array, but it is not set'); $loader->load('en_US', 'default'); } - public function testLoaderLoadsEmptyArray() + public function testLoaderLoadsEmptyArray(): void { - $loader = new PhpMemoryArrayLoader(include $this->testFilesDir . '/translation_empty.php'); + $loader = new PhpMemoryArrayLoader(include $this->testFilesDir . '/translation_empty.php'); $textDomain = $loader->load('en_US', 'default'); - $this->assertInstanceOf('Laminas\I18n\Translator\TextDomain', $textDomain); + $this->assertInstanceOf(TextDomain::class, $textDomain); } - public function testLoaderReturnsValidTextDomain() + public function testLoaderReturnsValidTextDomain(): void { - $loader = new PhpMemoryArrayLoader(include $this->testFilesDir . '/translation_en.php'); + $loader = new PhpMemoryArrayLoader(include $this->testFilesDir . '/translation_en.php'); $textDomain = $loader->load('en_US', 'default'); $this->assertEquals('Message 1 (en)', $textDomain['Message 1']); $this->assertEquals('Message 4 (en)', $textDomain['Message 4']); } - public function testLoaderLoadsPluralRules() + public function testLoaderLoadsPluralRules(): void { $loader = new PhpMemoryArrayLoader(include $this->testFilesDir . '/translation_en.php'); $textDomain = $loader->load('en_US', 'default'); diff --git a/test/Translator/LoaderPluginManagerCompatibilityTest.php b/test/Translator/LoaderPluginManagerCompatibilityTest.php index 2f845955..1bbea6d8 100644 --- a/test/Translator/LoaderPluginManagerCompatibilityTest.php +++ b/test/Translator/LoaderPluginManagerCompatibilityTest.php @@ -1,5 +1,7 @@ markTestSkipped('Test skipped as LoaderPluginManager allows multiple instance types'); } diff --git a/test/Translator/LoaderPluginManagerFactoryTest.php b/test/Translator/LoaderPluginManagerFactoryTest.php index bc37abee..6bca3b80 100644 --- a/test/Translator/LoaderPluginManagerFactoryTest.php +++ b/test/Translator/LoaderPluginManagerFactoryTest.php @@ -1,5 +1,7 @@ prophesize(ContainerInterface::class)->reveal(); @@ -22,7 +27,7 @@ public function testFactoryReturnsUnconfiguredPluginManagerWhenNoOptionsPresent( $this->assertFalse($loaders->has('test')); } - public function testCreateServiceReturnsUnconfiguredPluginManagerWhenNoOptionsPresent() + public function testCreateServiceReturnsUnconfiguredPluginManagerWhenNoOptionsPresent(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); @@ -33,7 +38,8 @@ public function testCreateServiceReturnsUnconfiguredPluginManagerWhenNoOptionsPr $this->assertFalse($loaders->has('test')); } - public function provideLoader() + /** @return array */ + public function provideLoader(): array { return [ ['gettext'], @@ -48,14 +54,16 @@ public function provideLoader() /** * @dataProvider provideLoader */ - public function testFactoryCanConfigurePluginManagerViaOptions($loader) + public function testFactoryCanConfigurePluginManagerViaOptions(string $loader): void { - $container = $this->prophesize(ContainerInterface::class)->reveal(); + $container = $this->createMock(ContainerInterface::class); $factory = new LoaderPluginManagerFactory(); - $loaders = $factory($container, 'TranslatorPluginManager', ['aliases' => [ - 'test' => $loader, - ]]); + $loaders = $factory($container, 'TranslatorPluginManager', [ + 'aliases' => [ + 'test' => $loader, + ], + ]); $this->assertInstanceOf(LoaderPluginManager::class, $loaders); $this->assertTrue($loaders->has('test')); } @@ -63,26 +71,28 @@ public function testFactoryCanConfigurePluginManagerViaOptions($loader) /** * @dataProvider provideLoader */ - public function testCreateServiceCanConfigurePluginManagerViaOptions($loader) + public function testCreateServiceCanConfigurePluginManagerViaOptions(string $loader): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); $factory = new LoaderPluginManagerFactory(); - $factory->setCreationOptions(['aliases' => [ - 'test' => $loader, - ]]); + $factory->setCreationOptions([ + 'aliases' => [ + 'test' => $loader, + ], + ]); $loaders = $factory->createService($container->reveal()); $this->assertInstanceOf(LoaderPluginManager::class, $loaders); $this->assertTrue($loaders->has('test')); } - public function testConfiguresTranslatorServicesWhenFound() + public function testConfiguresTranslatorServicesWhenFound(): void { $translator = $this->prophesize(FileLoaderInterface::class)->reveal(); - $config = [ + $config = [ 'translator_plugins' => [ - 'aliases' => [ + 'aliases' => [ 'test' => PhpArray::class, ], 'factories' => [ @@ -100,7 +110,7 @@ public function testConfiguresTranslatorServicesWhenFound() $container->has('config')->willReturn(true); $container->get('config')->willReturn($config); - $factory = new LoaderPluginManagerFactory(); + $factory = new LoaderPluginManagerFactory(); $translators = $factory($container->reveal(), 'TranslatorPluginManager'); $this->assertInstanceOf(LoaderPluginManager::class, $translators); @@ -110,12 +120,12 @@ public function testConfiguresTranslatorServicesWhenFound() $this->assertSame($translator, $translators->get('test-too')); } - public function testDoesNotConfigureTranslatorServicesWhenServiceListenerPresent() + public function testDoesNotConfigureTranslatorServicesWhenServiceListenerPresent(): void { $translator = $this->prophesize(FileLoaderInterface::class)->reveal(); - $config = [ + $config = [ 'translator_plugins' => [ - 'aliases' => [ + 'aliases' => [ 'test' => PhpArray::class, ], 'factories' => [ @@ -133,7 +143,7 @@ public function testDoesNotConfigureTranslatorServicesWhenServiceListenerPresent $container->has('config')->shouldNotBeCalled(); $container->get('config')->shouldNotBeCalled(); - $factory = new LoaderPluginManagerFactory(); + $factory = new LoaderPluginManagerFactory(); $translators = $factory($container->reveal(), 'TranslatorPluginManager'); $this->assertInstanceOf(LoaderPluginManager::class, $translators); @@ -141,7 +151,7 @@ public function testDoesNotConfigureTranslatorServicesWhenServiceListenerPresent $this->assertFalse($translators->has('test-too')); } - public function testDoesNotConfigureTranslatorServicesWhenConfigServiceNotPresent() + public function testDoesNotConfigureTranslatorServicesWhenConfigServiceNotPresent(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); @@ -150,13 +160,13 @@ public function testDoesNotConfigureTranslatorServicesWhenConfigServiceNotPresen $container->has('config')->willReturn(false); $container->get('config')->shouldNotBeCalled(); - $factory = new LoaderPluginManagerFactory(); + $factory = new LoaderPluginManagerFactory(); $translators = $factory($container->reveal(), 'TranslatorPluginManager'); $this->assertInstanceOf(LoaderPluginManager::class, $translators); } - public function testDoesNotConfigureTranslatorServicesWhenConfigServiceDoesNotContainTranslatorsConfig() + public function testDoesNotConfigureTranslatorServicesWhenConfigServiceDoesNotContainTranslatorsConfig(): void { $container = $this->prophesize(ServiceLocatorInterface::class); $container->willImplement(ContainerInterface::class); @@ -165,7 +175,7 @@ public function testDoesNotConfigureTranslatorServicesWhenConfigServiceDoesNotCo $container->has('config')->willReturn(true); $container->get('config')->willReturn(['foo' => 'bar']); - $factory = new LoaderPluginManagerFactory(); + $factory = new LoaderPluginManagerFactory(); $translators = $factory($container->reveal(), 'TranslatorPluginManager'); $this->assertInstanceOf(LoaderPluginManager::class, $translators); diff --git a/test/Translator/Plural/RuleTest.php b/test/Translator/Plural/RuleTest.php index 52e1a6bc..1dc96411 100644 --- a/test/Translator/Plural/RuleTest.php +++ b/test/Translator/Plural/RuleTest.php @@ -1,13 +1,16 @@ */ + public function parseRuleProvider(): array { return [ // Basic calculations @@ -46,14 +49,14 @@ public static function parseRuleProvider() 'boolean-or-false' => ['0 || 0', 0], // Variable injection - 'variable-injection' => ['n', 0] + 'variable-injection' => ['n', 0], ]; } /** * @dataProvider parseRuleProvider */ - public function testParseRules($rule, $expectedValue) + public function testParseRules(string $rule, int $expectedValue): void { $this->assertEquals( $expectedValue, @@ -61,7 +64,8 @@ public function testParseRules($rule, $expectedValue) ); } - public static function completeRuleProvider() + /** @return array */ + public function completeRuleProvider(): array { // Taken from original gettext tests return [ @@ -70,63 +74,63 @@ public static function completeRuleProvider() '10111111111111111111111111111111111111111111111111111111111111' . '111111111111111111111111111111111111111111111111111111111111' . '111111111111111111111111111111111111111111111111111111111111' - . '111111111111111111' + . '111111111111111111', ], [ 'n>1', '00111111111111111111111111111111111111111111111111111111111111' . '111111111111111111111111111111111111111111111111111111111111' . '111111111111111111111111111111111111111111111111111111111111' - . '111111111111111111' + . '111111111111111111', ], [ 'n==1 ? 0 : n==2 ? 1 : 2', '20122222222222222222222222222222222222222222222222222222222222' . '222222222222222222222222222222222222222222222222222222222222' . '222222222222222222222222222222222222222222222222222222222222' - . '222222222222222222' + . '222222222222222222', ], [ 'n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2', '10111111111111111111222222222222222222222222222222222222222222' . '222222222222222222222222222222222222222111111111111111111122' . '222222222222222222222222222222222222222222222222222222222222' - . '222222222222222222' + . '222222222222222222', ], [ 'n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2', '20111111112222222222201111111120111111112011111111201111111120' . '111111112011111111201111111120111111112011111111222222222220' . '111111112011111111201111111120111111112011111111201111111120' - . '111111112011111111' + . '111111112011111111', ], [ 'n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2', '20111222222222222222201112222220111222222011122222201112222220' . '111222222011122222201112222220111222222011122222222222222220' . '111222222011122222201112222220111222222011122222201112222220' - . '111222222011122222' + . '111222222011122222', ], [ 'n%100/10==1 ? 2 : n%10==1 ? 0 : (n+9)%10>3 ? 2 : 1', '20111222222222222222201112222220111222222011122222201112222220' . '111222222011122222201112222220111222222011122222222222222220' . '111222222011122222201112222220111222222011122222201112222220' - . '111222222011122222' + . '111222222011122222', ], [ 'n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2', '20111222222222222222221112222222111222222211122222221112222222' . '111222222211122222221112222222111222222211122222222222222222' . '111222222211122222221112222222111222222211122222221112222222' - . '111222222211122222' + . '111222222211122222', ], [ 'n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3', '30122333333333333333333333333333333333333333333333333333333333' . '333333333333333333333333333333333333333012233333333333333333' . '333333333333333333333333333333333333333333333333333333333333' - . '333333333333333333' + . '333333333333333333', ], ]; } @@ -134,7 +138,7 @@ public static function completeRuleProvider() /** * @dataProvider completeRuleProvider */ - public function testCompleteRules($rule, $expectedValues) + public function testCompleteRules(string $rule, string $expectedValues): void { $rule = Rule::fromString('nplurals=9; plural=' . $rule); @@ -143,7 +147,7 @@ public function testCompleteRules($rule, $expectedValues) } } - public function testGetNumPlurals() + public function testGetNumPlurals(): void { $rule = Rule::fromString('nplurals=9; plural=n'); $this->assertEquals(9, $rule->getNumPlurals()); diff --git a/test/Translator/TestAsset/Loader.php b/test/Translator/TestAsset/Loader.php index 668ac90c..6d18a99d 100644 --- a/test/Translator/TestAsset/Loader.php +++ b/test/Translator/TestAsset/Loader.php @@ -1,20 +1,24 @@ assertEquals('bar', $domain['foo']); } @@ -49,7 +52,7 @@ public function testMerging() public function testMergingIncompatibleTextDomains() { - $this->expectException('Laminas\I18n\Exception\RuntimeException'); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('is not compatible'); $domainA = new TextDomain(); diff --git a/test/Translator/TranslatorAwareTraitTest.php b/test/Translator/TranslatorAwareTraitTest.php index a7cc2a54..d837a78f 100644 --- a/test/Translator/TranslatorAwareTraitTest.php +++ b/test/Translator/TranslatorAwareTraitTest.php @@ -1,10 +1,12 @@ getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertNull($object->getTranslator()); - $translator = new Translator; + $translator = new Translator(); $object->setTranslator($translator); @@ -26,12 +28,12 @@ public function testSetTranslator() public function testSetTranslatorAndTextDomain() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertNull($object->getTranslator()); $this->assertSame('default', $object->getTranslatorTextDomain()); - $translator = new Translator; + $translator = new Translator(); $textDomain = 'domain'; $object->setTranslator($translator, $textDomain); @@ -42,11 +44,11 @@ public function testSetTranslatorAndTextDomain() public function testGetTranslator() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertNull($object->getTranslator()); - $translator = new Translator; + $translator = new Translator(); $object->setTranslator($translator); @@ -55,11 +57,11 @@ public function testGetTranslator() public function testHasTranslator() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertFalse($object->hasTranslator()); - $translator = new Translator; + $translator = new Translator(); $object->setTranslator($translator); @@ -68,7 +70,7 @@ public function testHasTranslator() public function testSetTranslatorEnabled() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertTrue($object->isTranslatorEnabled()); @@ -85,7 +87,7 @@ public function testSetTranslatorEnabled() public function testIsTranslatorEnabled() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertTrue($object->isTranslatorEnabled()); @@ -96,7 +98,7 @@ public function testIsTranslatorEnabled() public function testSetTranslatorTextDomain() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertSame('default', $object->getTranslatorTextDomain()); @@ -109,7 +111,7 @@ public function testSetTranslatorTextDomain() public function testGetTranslatorTextDomain() { - $object = $this->getObjectForTrait('\Laminas\I18n\Translator\TranslatorAwareTrait'); + $object = $this->getObjectForTrait(TranslatorAwareTrait::class); $this->assertEquals('default', $object->getTranslatorTextDomain()); diff --git a/test/Translator/TranslatorServiceFactoryTest.php b/test/Translator/TranslatorServiceFactoryTest.php index 1591ed61..2db7bbfe 100644 --- a/test/Translator/TranslatorServiceFactoryTest.php +++ b/test/Translator/TranslatorServiceFactoryTest.php @@ -1,15 +1,20 @@ prophesize(LoaderPluginManager::class)->reveal(); @@ -19,7 +24,7 @@ public function testCreateServiceWithNoTranslatorKeyDefined() $serviceLocator->get('TranslatorPluginManager')->willReturn($pluginManagerMock)->shouldBeCalledTimes(1); $serviceLocator->get('config')->willReturn([])->shouldBeCalledTimes(1); - $factory = new TranslatorServiceFactory(); + $factory = new TranslatorServiceFactory(); $translator = $factory($serviceLocator->reveal(), Translator::class); $this->assertInstanceOf(Translator::class, $translator); $this->assertSame($pluginManagerMock, $translator->getPluginManager()); @@ -31,7 +36,7 @@ public function testCreateServiceWithNoTranslatorPluginManagerDefined() $serviceLocator->has('TranslatorPluginManager')->willReturn(false)->shouldBeCalledTimes(1); $serviceLocator->get('config')->willReturn([])->shouldBeCalledTimes(1); - $factory = new TranslatorServiceFactory(); + $factory = new TranslatorServiceFactory(); $translator = $factory($serviceLocator->reveal(), Translator::class); $this->assertInstanceOf(Translator::class, $translator); } diff --git a/test/Translator/TranslatorTest.php b/test/Translator/TranslatorTest.php index 34acd36c..55210df5 100644 --- a/test/Translator/TranslatorTest.php +++ b/test/Translator/TranslatorTest.php @@ -1,171 +1,168 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->originalLocale = Locale::getDefault(); - $this->translator = new Translator(); - + parent::setUp(); + $this->translator = new Translator(); Locale::setDefault('en_EN'); - $this->testFilesDir = __DIR__ . '/_files'; } - protected function tearDown(): void - { - if (extension_loaded('intl')) { - Locale::setDefault($this->originalLocale); - } - } - - public function testFactoryCreatesTranslator() + public function testFactoryCreatesTranslator(): void { $translator = Translator::factory([ - 'locale' => 'de_DE', + 'locale' => 'de_DE', 'patterns' => [ [ - 'type' => 'phparray', + 'type' => 'phparray', 'base_dir' => $this->testFilesDir . '/testarray', - 'pattern' => 'translation-%s.php' - ] + 'pattern' => 'translation-%s.php', + ], ], - 'files' => [ + 'files' => [ [ - 'type' => 'phparray', + 'type' => 'phparray', 'filename' => $this->testFilesDir . '/translation_en.php', - ] - ] + ], + ], ]); - $this->assertInstanceOf('Laminas\I18n\Translator\Translator', $translator); + $this->assertInstanceOf(Translator::class, $translator); $this->assertEquals('de_DE', $translator->getLocale()); } - public function testTranslationFromSeveralTranslationFiles() + public function testTranslationFromSeveralTranslationFiles(): void { $translator = Translator::factory([ - 'locale' => 'de_DE', + 'locale' => 'de_DE', 'translation_file_patterns' => [ [ - 'type' => 'phparray', + 'type' => 'phparray', 'base_dir' => $this->testFilesDir . '/testarray', - 'pattern' => 'translation-%s.php' + 'pattern' => 'translation-%s.php', ], [ - 'type' => 'phparray', + 'type' => 'phparray', 'base_dir' => $this->testFilesDir . '/testarray', - 'pattern' => 'translation-more-%s.php' - ] - ] + 'pattern' => 'translation-more-%s.php', + ], + ], ]); //Test translator instance - $this->assertInstanceOf('Laminas\I18n\Translator\Translator', $translator); + $this->assertInstanceOf(Translator::class, $translator); //Test translations - $this->assertEquals('Nachricht 1', $translator->translate('Message 1')); //translation-de_DE.php - $this->assertEquals('Nachricht 9', $translator->translate('Message 9')); //translation-more-de_DE.php - $this->assertEquals('Nachricht 10 - 0', $translator->translatePlural('Message 10', 'Message 10', 1)); //translation-de_DE.php - $this->assertEquals('Nachricht 10 - 1', $translator->translatePlural('Message 10', 'Message 10', 2)); //translation-de_DE.php - $this->assertEquals('Nachricht 11 - 0', $translator->translatePlural('Message 11', 'Message 11', 1)); //translation-more-de_DE.php - $this->assertEquals('Nachricht 11 - 1', $translator->translatePlural('Message 11', 'Message 11', 2)); //translation-more-de_DE.php + $this->assertEquals( + 'Nachricht 1', + $translator->translate('Message 1') + ); //translation-de_DE.php + $this->assertEquals( + 'Nachricht 9', + $translator->translate('Message 9') + ); //translation-more-de_DE.php + $this->assertEquals( + 'Nachricht 10 - 0', + $translator->translatePlural('Message 10', 'Message 10', 1) + ); //translation-de_DE.php + $this->assertEquals( + 'Nachricht 10 - 1', + $translator->translatePlural('Message 10', 'Message 10', 2) + ); //translation-de_DE.php + $this->assertEquals( + 'Nachricht 11 - 0', + $translator->translatePlural('Message 11', 'Message 11', 1) + ); //translation-more-de_DE.php + $this->assertEquals( + 'Nachricht 11 - 1', + $translator->translatePlural('Message 11', 'Message 11', 2) + ); //translation-more-de_DE.php } - public function testTranslationFromDifferentSourceTypes() + public function testTranslationFromDifferentSourceTypes(): void { $translator = Translator::factory([ - 'locale' => 'de_DE', + 'locale' => 'de_DE', 'translation_file_patterns' => [ [ 'type' => 'phparray', 'base_dir' => $this->testFilesDir . '/testarray', - 'pattern' => 'translation-de_DE.php' + 'pattern' => 'translation-de_DE.php', ], ], - 'translation_files' => [ + 'translation_files' => [ [ 'type' => 'phparray', - 'filename' => $this->testFilesDir . '/testarray/translation-more-de_DE.php' - ] - ] + 'filename' => $this->testFilesDir . '/testarray/translation-more-de_DE.php', + ], + ], ]); $this->assertEquals('Nachricht 1', $translator->translate('Message 1')); //translation-de_DE.php $this->assertEquals('Nachricht 9', $translator->translate('Message 9')); //translation-more-de_DE.php } - public function testFactoryCreatesTranslatorWithCache() + public function testFactoryCreatesTranslatorWithCache(): void { $translator = Translator::factory([ - 'locale' => 'de_DE', + 'locale' => 'de_DE', 'patterns' => [ [ - 'type' => 'phparray', + 'type' => 'phparray', 'base_dir' => $this->testFilesDir . '/testarray', - 'pattern' => 'translation-%s.php' - ] + 'pattern' => 'translation-%s.php', + ], + ], + 'cache' => [ + 'adapter' => 'memory', ], - 'cache' => [ - 'adapter' => 'memory' - ] ]); - $this->assertInstanceOf('Laminas\I18n\Translator\Translator', $translator); - $this->assertInstanceOf('Laminas\Cache\Storage\StorageInterface', $translator->getCache()); + $this->assertInstanceOf(Translator::class, $translator); + $this->assertInstanceOf(StorageInterface::class, $translator->getCache()); } - public function testDefaultLocale() + public function testDefaultLocale(): void { $this->assertEquals('en_EN', $this->translator->getLocale()); } - public function testForcedLocale() + public function testForcedLocale(): void { $this->translator->setLocale('de_DE'); $this->assertEquals('de_DE', $this->translator->getLocale()); } - public function testTranslate() + public function testTranslate(): void { - $loader = new TestLoader(); + $loader = new TestLoader(); $loader->textDomain = new TextDomain(['foo' => 'bar']); - $config = new Config([ + $config = new Config([ 'services' => [ - 'test' => $loader - ] + 'test' => $loader, + ], ]); - $pm = $this->translator->getPluginManager(); + $pm = $this->translator->getPluginManager(); $config->configureServiceManager($pm); $this->translator->setPluginManager($pm); $this->translator->addTranslationFile('test', null); @@ -173,7 +170,7 @@ public function testTranslate() $this->assertEquals('bar', $this->translator->translate('foo')); } - public function testTranslationsLoadedFromCache() + public function testTranslationsLoadedFromCache(): void { $cache = CacheFactory::factory(['adapter' => 'memory']); $this->translator->setCache($cache); @@ -186,15 +183,15 @@ public function testTranslationsLoadedFromCache() $this->assertEquals('bar', $this->translator->translate('foo')); } - public function testTranslationsAreStoredInCache() + public function testTranslationsAreStoredInCache(): void { $cache = CacheFactory::factory(['adapter' => 'memory']); $this->translator->setCache($cache); - $loader = new TestLoader(); + $loader = new TestLoader(); $loader->textDomain = new TextDomain(['foo' => 'bar']); - $config = new Config(['services' => ['test' => $loader]]); - $plugins = $this->translator->getPluginManager(); + $config = new Config(['services' => ['test' => $loader]]); + $plugins = $this->translator->getPluginManager(); $config->configureServiceManager($plugins); $this->translator->setPluginManager($plugins); $this->translator->addTranslationFile('test', null); @@ -202,11 +199,11 @@ public function testTranslationsAreStoredInCache() $this->assertEquals('bar', $this->translator->translate('foo')); $item = $cache->getItem($this->translator->getCacheId('default', 'en_EN')); - $this->assertInstanceOf('Laminas\I18n\Translator\TextDomain', $item); + $this->assertInstanceOf(TextDomain::class, $item); $this->assertEquals('bar', $item['foo']); } - public function testTranslationsAreClearedFromCache() + public function testTranslationsAreClearedFromCache(): void { $textDomain = 'default'; $locale = 'en_EN'; @@ -226,12 +223,12 @@ public function testTranslationsAreClearedFromCache() $this->assertFalse($success); } - public function testClearCacheReturnsFalseIfNoCacheIsPresent() + public function testClearCacheReturnsFalseIfNoCacheIsPresent(): void { $this->assertFalse($this->translator->clearCache('default', 'en_EN')); } - public function testTranslatePlurals() + public function testTranslatePlurals(): void { $this->translator->setLocale('en_EN'); $this->translator->addTranslationFile( @@ -250,7 +247,7 @@ public function testTranslatePlurals() $this->assertEquals('Message 5 (en) Plural 2', $pl2); } - public function testTranslatePluralsNonExistantLocale() + public function testTranslatePluralsNonExistentLocale(): void { $this->translator->addTranslationFilePattern( 'phparray', @@ -269,7 +266,7 @@ public function testTranslatePluralsNonExistantLocale() $this->assertEquals('Message 5 Plural', $pl2); } - public function testTranslatePluralsNonExistantTranslation() + public function testTranslatePluralsNonExistentTranslation(): void { $this->translator->addTranslationFilePattern( 'phparray', @@ -288,7 +285,7 @@ public function testTranslatePluralsNonExistantTranslation() $this->assertEquals('Message 12 Plural', $pl2); } - public function testTranslateNoPlurals() + public function testTranslateNoPlurals(): void { // Some languages such as Japanese and Chinese does not have plural forms $this->translator->setLocale('ja_JP'); @@ -308,7 +305,7 @@ public function testTranslateNoPlurals() $this->assertEquals('Message 9 (ja)', $pl2); } - public function testTranslateNonExistantLocale() + public function testTranslateNonExistentLocale(): void { $this->translator->addTranslationFilePattern( 'phparray', @@ -329,7 +326,7 @@ public function testTranslateNonExistantLocale() $this->assertEquals('Message 9', $this->translator->translate('Message 9')); } - public function testTranslateNonExistantTranslation() + public function testTranslateNonExistentTranslation(): void { $this->translator->addTranslationFilePattern( 'phparray', @@ -344,7 +341,7 @@ public function testTranslateNonExistantTranslation() $this->assertEquals('Message 13', $this->translator->translate('Message 13')); } - public function testEnableDisableEventManger() + public function testEnableDisableEventManger(): void { $this->assertFalse($this->translator->isEventManagerEnabled(), 'Default value'); @@ -355,10 +352,10 @@ public function testEnableDisableEventManger() $this->assertFalse($this->translator->isEventManagerEnabled()); } - public function testEnableEventMangerViaFactory() + public function testEnableEventMangerViaFactory(): void { $translator = Translator::factory([ - 'event_manager_enabled' => true + 'event_manager_enabled' => true, ]); $this->assertTrue($translator->isEventManagerEnabled()); @@ -366,7 +363,7 @@ public function testEnableEventMangerViaFactory() $this->assertFalse($translator->isEventManagerEnabled()); } - public function testMissingTranslationEvent() + public function testMissingTranslationEvent(): void { $actualEvent = null; @@ -382,7 +379,7 @@ static function (EventInterface $event) use (&$actualEvent) { $this->translator->translate('foo', 'bar', 'baz'); - $this->assertInstanceOf('Laminas\EventManager\Event', $actualEvent); + $this->assertInstanceOf(Event::class, $actualEvent); $this->assertEquals( [ 'message' => 'foo', @@ -399,7 +396,7 @@ static function (EventInterface $event) use (&$actualEvent) { $this->assertNull($actualEvent); } - public function testListenerOnMissingTranslationEventCanReturnString() + public function testListenerOnMissingTranslationEventCanReturnString(): void { $trigger = null; $doNotTriger = null; @@ -437,7 +434,7 @@ static function (EventInterface $event) use (&$doNotTrigger) { $this->assertNull($doNotTrigger); } - public function testNoMessagesLoadedEvent() + public function testNoMessagesLoadedEvent(): void { $actualEvent = null; @@ -450,7 +447,7 @@ public function testNoMessagesLoadedEvent() $this->translator->translate('foo', 'bar', 'baz'); - $this->assertInstanceOf('Laminas\EventManager\Event', $actualEvent); + $this->assertInstanceOf(Event::class, $actualEvent); $this->assertEquals( [ 'locale' => 'baz', @@ -466,7 +463,7 @@ public function testNoMessagesLoadedEvent() $this->assertNull($actualEvent); } - public function testListenerOnNoMessagesLoadedEventCanReturnTextDomainObject() + public function testListenerOnNoMessagesLoadedEventCanReturnTextDomainObject(): void { $trigger = null; $doNotTrigger = null; @@ -508,7 +505,7 @@ static function (EventInterface $event) use (&$doNotTrigger) { $this->assertEquals('BOOYAH', $result); } - public function testGetAllMessagesLoadedInTranslator() + public function testGetAllMessagesLoadedInTranslator(): void { $this->translator->setLocale('en_EN'); $this->translator->addTranslationFile( @@ -524,7 +521,7 @@ public function testGetAllMessagesLoadedInTranslator() $this->assertEquals('Message 1 (en)', $allMessages['Message 1']); } - public function testGetAllMessagesReturnsNullWhenGivenTextDomainIsNotFound() + public function testGetAllMessagesReturnsNullWhenGivenTextDomainIsNotFound(): void { $this->translator->setLocale('en_EN'); $this->translator->addTranslationFile( @@ -538,7 +535,7 @@ public function testGetAllMessagesReturnsNullWhenGivenTextDomainIsNotFound() $this->assertNull($allMessages); } - public function testGetAllMessagesReturnsNullWhenGivenLocaleNotExist() + public function testGetAllMessagesReturnsNullWhenGivenLocaleNotExist(): void { $this->translator->setLocale('en_EN'); $this->translator->addTranslationFile( @@ -552,17 +549,16 @@ public function testGetAllMessagesReturnsNullWhenGivenLocaleNotExist() $this->assertNull($allMessages); } - /** - * @group 33 - */ - public function testNullMessageArgumentShouldReturnAnEmptyString() + public function testNullMessageArgumentShouldReturnAnEmptyString(): void { - $loader = new TestLoader(); + $loader = new TestLoader(); $loader->textDomain = new TextDomain(['foo' => 'bar']); - $config = new Config(['services' => [ - 'test' => $loader - ]]); - $pm = $this->translator->getPluginManager(); + $config = new Config([ + 'services' => [ + 'test' => $loader, + ], + ]); + $pm = $this->translator->getPluginManager(); $config->configureServiceManager($pm); $this->translator->setPluginManager($pm); $this->translator->addTranslationFile('test', null); diff --git a/test/Validator/AlnumTest.php b/test/Validator/AlnumTest.php index 7478f160..bd4fd600 100644 --- a/test/Validator/AlnumTest.php +++ b/test/Validator/AlnumTest.php @@ -1,40 +1,30 @@ markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->validator = new AlnumValidator(); } /** * Ensures that the validator follows expected behavior for basic input values - * - * @return void */ - public function testExpectedResultsWithBasicInputValues() + public function testExpectedResultsWithBasicInputValues(): void { $valuesExpected = [ 'abc123' => true, @@ -45,7 +35,7 @@ public function testExpectedResultsWithBasicInputValues() '' => false, ' ' => false, "\n" => false, - 'foobar1' => true + 'foobar1' => true, ]; foreach ($valuesExpected as $input => $result) { $this->assertEquals($result, $this->validator->isValid($input)); @@ -54,20 +44,16 @@ public function testExpectedResultsWithBasicInputValues() /** * Ensures that getMessages() returns expected initial value - * - * @return void */ - public function testMessagesEmptyInitially() + public function testMessagesEmptyInitially(): void { $this->assertEquals([], $this->validator->getMessages()); } /** * Ensures that the allowWhiteSpace option works as expected - * - * @return void */ - public function testOptionToAllowWhiteSpaceWithBasicInputValues() + public function testOptionToAllowWhiteSpaceWithBasicInputValues(): void { $this->validator->setAllowWhiteSpace(true); @@ -81,8 +67,8 @@ public function testOptionToAllowWhiteSpaceWithBasicInputValues() ' ' => true, "\n" => true, " \t " => true, - 'foobar1' => true - ]; + 'foobar1' => true, + ]; foreach ($valuesExpected as $input => $result) { $this->assertEquals( $result, @@ -92,50 +78,38 @@ public function testOptionToAllowWhiteSpaceWithBasicInputValues() } } - /** - * @return void - */ - public function testEmptyStringValueResultsInProperValidationFailureMessages() + public function testEmptyStringValueResultsInProperValidationFailureMessages(): void { $this->assertFalse($this->validator->isValid('')); - $messages = $this->validator->getMessages(); + $messages = $this->validator->getMessages(); $arrayExpected = [ - AlnumValidator::STRING_EMPTY => 'The input is an empty string' + AlnumValidator::STRING_EMPTY => 'The input is an empty string', ]; $this->assertThat($messages, $this->identicalTo($arrayExpected)); } - /** - * @return void - */ - public function testInvalidValueResultsInProperValidationFailureMessages() + public function testInvalidValueResultsInProperValidationFailureMessages(): void { $this->assertFalse($this->validator->isValid('#')); - $messages = $this->validator->getMessages(); + $messages = $this->validator->getMessages(); $arrayExpected = [ - AlnumValidator::NOT_ALNUM => 'The input contains characters which are non alphabetic and no digits' + AlnumValidator::NOT_ALNUM => 'The input contains characters which are non alphabetic and no digits', ]; $this->assertThat($messages, $this->identicalTo($arrayExpected)); } - /** - * @Laminas-4352 - */ - public function testNonStringValidation() + public function testNonStringValidation(): void { $this->assertFalse($this->validator->isValid([1 => 1])); } - /** - * @Laminas-7475 - */ - public function testIntegerValidation() + public function testIntegerValidation(): void { $this->assertTrue($this->validator->isValid(1)); } - public function testEqualsMessageTemplates() + public function testEqualsMessageTemplates(): void { $validator = $this->validator; diff --git a/test/Validator/AlphaTest.php b/test/Validator/AlphaTest.php index abcb4de3..fda3064f 100644 --- a/test/Validator/AlphaTest.php +++ b/test/Validator/AlphaTest.php @@ -1,35 +1,27 @@ markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->validator = new AlphaValidator(); } /** * Ensures that the validator follows expected behavior - * - * @return void */ - public function testBasic() + public function testBasic(): void { $valuesExpected = [ 'abc123' => false, @@ -40,8 +32,8 @@ public function testBasic() 'aBcDeF' => true, '' => false, ' ' => false, - "\n" => false - ]; + "\n" => false, + ]; foreach ($valuesExpected as $input => $result) { $this->assertEquals($result, $this->validator->isValid($input)); } @@ -49,20 +41,16 @@ public function testBasic() /** * Ensures that getMessages() returns expected default value - * - * @return void */ - public function testGetMessages() + public function testGetMessages(): void { $this->assertEquals([], $this->validator->getMessages()); } /** * Ensures that the allowWhiteSpace option works as expected - * - * @return void */ - public function testAllowWhiteSpace() + public function testAllowWhiteSpace(): void { $this->validator->setAllowWhiteSpace(true); @@ -77,7 +65,7 @@ public function testAllowWhiteSpace() ' ' => true, "\n" => true, " \t " => true, - "a\tb c" => true + "a\tb c" => true, ]; foreach ($valuesExpected as $input => $result) { $this->assertEquals( @@ -88,15 +76,12 @@ public function testAllowWhiteSpace() } } - /** - * @Laminas-4352 - */ - public function testNonStringValidation() + public function testNonStringValidation(): void { $this->assertFalse($this->validator->isValid([1 => 1])); } - public function testEqualsMessageTemplates() + public function testEqualsMessageTemplates(): void { $validator = $this->validator; diff --git a/test/Validator/DateTimeTest.php b/test/Validator/DateTimeTest.php index 96b26f1e..e081b3fb 100644 --- a/test/Validator/DateTimeTest.php +++ b/test/Validator/DateTimeTest.php @@ -1,50 +1,39 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->locale = Locale::getDefault(); + parent::setUp(); $this->timezone = date_default_timezone_get(); $this->validator = new DateTimeValidator([ - 'locale' => 'en', - 'timezone' => 'Europe/Amsterdam' + 'locale' => 'en', + 'timezone' => 'Europe/Amsterdam', ]); } protected function tearDown(): void { - if (extension_loaded('intl')) { - Locale::setDefault($this->locale); - } + parent::tearDown(); date_default_timezone_set($this->timezone); } @@ -52,18 +41,18 @@ protected function tearDown(): void * Ensures that the validator follows expected behavior * * @dataProvider basicProvider name of method that provides parameters - * @param string $value that will be tested - * @param boolean $expected expected result of assertion - * @param array $options fed into the validator before validation + * @param string $value that will be tested + * @param boolean $expected expected result of assertion + * @param array $options fed into the validator before validation */ - public function testBasic($value, $expected, $options = []) + public function testBasic(string $value, bool $expected, array $options = []): void { $this->validator->setOptions($options); $this->assertEquals( $expected, $this->validator->isValid($value), - sprintf('Failed expecting %s being %s', $value, ($expected ? 'true' : 'false')) + sprintf('Failed expecting %s being %s', $value, $expected ? 'true' : 'false') . sprintf( ' (locale:%s, dateType: %s, timeType: %s, pattern:%s)', $this->validator->getLocale(), @@ -74,12 +63,9 @@ public function testBasic($value, $expected, $options = []) ); } - public function basicProvider() + /** @return array}> */ + public function basicProvider(): array { - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } - $trueArray = []; $testingDate = new DateTime(); $testingLocales = ['en', 'de', 'zh-TW', 'ja', 'ar', 'ru', 'si', 'ml-IN', 'hi']; @@ -88,7 +74,7 @@ public function basicProvider() IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, - IntlDateFormatter::NONE + IntlDateFormatter::NONE, ]; //Loop locales and formats for a more thorough set of "true" test data @@ -99,7 +85,7 @@ public function basicProvider() $trueArray[] = [ IntlDateFormatter::create($locale, $dateFormat, $timeFormat)->format($testingDate), true, - ['locale' => $locale, 'dateType' => $dateFormat, 'timeType' => $timeFormat] + ['locale' => $locale, 'dateType' => $dateFormat, 'timeType' => $timeFormat], ]; } } @@ -111,11 +97,11 @@ public function basicProvider() 'May 38, 2013', false, [ - 'locale' => 'en', + 'locale' => 'en', 'dateType' => IntlDateFormatter::FULL, - 'timeType' => IntlDateFormatter::NONE - ] - ] + 'timeType' => IntlDateFormatter::NONE, + ], + ], ]; return array_merge($trueArray, $falseArray); @@ -177,6 +163,18 @@ public function testOptionPatternOmitted() $this->assertEquals('yyyyMMdd hh:mm a', $this->validator->getPattern()); } + public function testSettingThePatternToNullIsAcceptable(): void + { + $this->validator->setPattern(null); + self::assertTrue($this->validator->isValid('20200101 12:34 am')); + } + + public function testSettingThePatternToAnEmptyStringIsAcceptable(): void + { + $this->validator->setPattern(''); + self::assertTrue($this->validator->isValid('20200101 12:34 am')); + } + /** * Ensures that setting the pattern results in pattern used (by the validation process) */ diff --git a/test/Validator/IsFloatTest.php b/test/Validator/IsFloatTest.php index 9a0ed485..2665516c 100644 --- a/test/Validator/IsFloatTest.php +++ b/test/Validator/IsFloatTest.php @@ -1,73 +1,72 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->locale = Locale::getDefault(); + parent::setUp(); $this->validator = new IsFloatValidator(['locale' => 'en']); } - protected function tearDown(): void - { - if (extension_loaded('intl')) { - Locale::setDefault($this->locale); - } - } - /** * Test float and integer type variables. Includes decimal and scientific notation NumberFormatter-formatted * versions. Should return true for all locales. * - * @param string $value that will be tested + * @param mixed $value that will be tested * @param boolean $expected expected result of assertion * @param string $locale locale for validation * @dataProvider floatAndIntegerProvider - * @return void */ - public function testFloatAndIntegers($value, $expected, $locale, $type) + public function testFloatAndIntegers($value, bool $expected, string $locale, string $type): void { $this->validator->setLocale($locale); $this->assertEquals( $expected, $this->validator->isValid($value), - 'Failed expecting ' . $value . ' being ' . ($expected ? 'true' : 'false') . - sprintf(' (locale:%s, type:%s)', $locale, $type) . ', ICU Version:' . INTL_ICU_VERSION . '-' . - INTL_ICU_DATA_VERSION + 'Failed expecting ' . $value . ' being ' . ($expected ? 'true' : 'false') + . sprintf(' (locale:%s, type:%s)', $locale, $type) . ', ICU Version:' . INTL_ICU_VERSION . '-' + . INTL_ICU_DATA_VERSION ); } - public function floatAndIntegerProvider() + /** @return array */ + public function floatAndIntegerProvider(): array { $trueArray = []; $testingLocales = ['ar', 'bn', 'de', 'dz', 'en', 'fr-CH', 'ja', 'ks', 'ml-IN', 'mr', 'my', 'ps', 'ru']; - $testingExamples = [1000, -2000, +398.00, 0.04, -0.5, .6, -.70, 8E10, -9.3456E-2, 10.23E6, - 123.1234567890987654321, 1, 13, -3]; + $testingExamples = [ + 1000, + -2000, + +398.00, + 0.04, + -0.5, + .6, + -.70, + 8E10, + -9.3456E-2, + 10.23E6, + 123.1234567890987654321, + 1, + 13, + -3, + ]; //Loop locales and examples for a more thorough set of "true" test data foreach ($testingLocales as $locale) { @@ -79,7 +78,7 @@ public function floatAndIntegerProvider() ->format($example, NumberFormatter::TYPE_DOUBLE), true, $locale, - 'decimal' + 'decimal', ]; //Scientific Notation Formatted $trueArray[] = [ @@ -87,7 +86,7 @@ public function floatAndIntegerProvider() ->format($example, NumberFormatter::TYPE_DOUBLE), true, $locale, - 'scientific' + 'scientific', ]; } } @@ -103,9 +102,8 @@ public function floatAndIntegerProvider() * @param boolean $expected expected result of assertion * @param string $locale locale for validation * @dataProvider lookAlikeProvider - * @return void */ - public function testlookAlikes($value, $expected, $locale) + public function testlookAlikes(string $value, bool $expected, string $locale): void { $this->validator->setLocale($locale); @@ -116,12 +114,13 @@ public function testlookAlikes($value, $expected, $locale) ); } - public function lookAlikeProvider() + /** @return array */ + public function lookAlikeProvider(): array { - $trueArray = []; - $testingArray = [ + $trueArray = []; + $testingArray = [ 'ar' => "\xD9\xA1'\xD9\xA1\xD9\xA1\xD9\xA1,\xD9\xA2\xD9\xA3", - 'ru' => '2 000,00' + 'ru' => '2 000,00', ]; //Loop locales and examples for a more thorough set of "true" test data @@ -140,9 +139,8 @@ public function lookAlikeProvider() * @param boolean $expected expected result of assertion * @param string $locale locale for validation * @dataProvider validationFailureProvider - * @return void */ - public function testValidationFailures($value, $expected, $locale) + public function testValidationFailures(string $value, bool $expected, string $locale): void { $this->validator->setLocale($locale); @@ -153,14 +151,15 @@ public function testValidationFailures($value, $expected, $locale) ); } - public function validationFailureProvider() + /** @return array */ + public function validationFailureProvider(): array { - $trueArray = []; - $testingArray = [ + $trueArray = []; + $testingArray = [ 'ar' => ['10.1', '66notflot.6'], 'ru' => ['10.1', '66notflot.6', '2,000.00', '2 00'], 'en' => ['10,1', '66notflot.6', '2.000,00', '2 000', '2,00'], - 'fr-CH' => ['66notflot.6', '2,000.00', "2'00"] + 'fr-CH' => ['66notflot.6', '2,000.00', "2'00"], ]; //Loop locales and examples for a more thorough set of "true" test data @@ -174,10 +173,8 @@ public function validationFailureProvider() /** * Ensures that getMessages() returns expected default value - * - * @return void */ - public function testGetMessages() + public function testGetMessages(): void { $this->assertEquals([], $this->validator->getMessages()); } @@ -185,42 +182,32 @@ public function testGetMessages() /** * Ensures that set/getLocale() works */ - public function testSettingLocales() + public function testSettingLocales(): void { $this->validator->setLocale('de'); $this->assertEquals('de', $this->validator->getLocale()); } - /** - * @Laminas-4352 - */ - public function testNonStringValidation() + public function testNonStringValidation(): void { $this->assertFalse($this->validator->isValid([1 => 1])); } - /** - * @Laminas-7489 - */ - public function testUsingApplicationLocale() + public function testUsingApplicationLocale(): void { Locale::setDefault('de'); $valid = new IsFloatValidator(); $this->assertEquals('de', $valid->getLocale()); } - public function testEqualsMessageTemplates() + public function testEqualsMessageTemplates(): void { $validator = $this->validator; $this->assertSame($validator->getOption('messageTemplates'), $validator->getMessageTemplates()); } - /** - * @group 6647 - * @group 6648 - */ - public function testNotFloat() + public function testNotFloat(): void { $this->assertFalse($this->validator->isValid('2.000.000,00')); diff --git a/test/Validator/IsIntTest.php b/test/Validator/IsIntTest.php index 80c22d03..d2c46d37 100644 --- a/test/Validator/IsIntTest.php +++ b/test/Validator/IsIntTest.php @@ -1,45 +1,26 @@ markTestSkipped('ext/intl not enabled'); - } - - $this->locale = Locale::getDefault(); + parent::setUp(); $this->validator = new IsIntValidator(); } - protected function tearDown(): void - { - if (extension_loaded('intl')) { - Locale::setDefault($this->locale); - } - } - - public function intDataProvider() + /** @return array */ + public function intDataProvider(): array { return [ [1.00, true], @@ -59,9 +40,9 @@ public function intDataProvider() * Ensures that the validator follows expected behavior * * @dataProvider intDataProvider() - * @return void + * @param mixed $intVal */ - public function testBasic($intVal, $expected) + public function testBasic($intVal, bool $expected): void { $this->validator->setLocale('en'); $this->assertEquals($expected, $this->validator->isValid($intVal)); @@ -69,10 +50,8 @@ public function testBasic($intVal, $expected) /** * Ensures that getMessages() returns expected default value - * - * @return void */ - public function testGetMessages() + public function testGetMessages(): void { $this->assertEquals([], $this->validator->getMessages()); } @@ -80,7 +59,7 @@ public function testGetMessages() /** * Ensures that set/getLocale() works */ - public function testSettingLocales() + public function testSettingLocales(): void { $this->validator->setLocale('de'); $this->assertEquals('de', $this->validator->getLocale()); @@ -88,28 +67,19 @@ public function testSettingLocales() $this->assertEquals(true, $this->validator->isValid('10.000')); } - /** - * @Laminas-4352 - */ - public function testNonStringValidation() + public function testNonStringValidation(): void { $this->assertFalse($this->validator->isValid([1 => 1])); } - /** - * @Laminas-7489 - */ - public function testUsingApplicationLocale() + public function testUsingApplicationLocale(): void { Locale::setDefault('de'); $valid = new IsIntValidator(); $this->assertTrue($valid->isValid('10.000')); } - /** - * @Laminas-7703 - */ - public function testLocaleDetectsNoEnglishLocaleOnOtherSetLocale() + public function testLocaleDetectsNoEnglishLocaleOnOtherSetLocale(): void { Locale::setDefault('de'); $valid = new IsIntValidator(); @@ -117,14 +87,14 @@ public function testLocaleDetectsNoEnglishLocaleOnOtherSetLocale() $this->assertFalse($valid->isValid('1,200')); } - public function testEqualsMessageTemplates() + public function testEqualsMessageTemplates(): void { $validator = $this->validator; $this->assertSame($validator->getOption('messageTemplates'), $validator->getMessageTemplates()); } - public function testGetStrict() + public function testGetStrict(): void { $this->assertFalse( $this->validator->getStrict() @@ -137,9 +107,9 @@ public function testGetStrict() } /** - * @return array + * @return array */ - public function setStrictInvalidParameterDataProvider() + public function setStrictInvalidParameterDataProvider(): array { return [ [null], @@ -156,16 +126,16 @@ public function setStrictInvalidParameterDataProvider() * @dataProvider setStrictInvalidParameterDataProvider * @param mixed $strict */ - public function testSetStrictThrowsInvalidArgumentException($strict) + public function testSetStrictThrowsInvalidArgumentException($strict): void { $this->expectException(Exception\InvalidArgumentException::class); $this->validator->setStrict($strict); } /** - * @return array + * @return array */ - public function strictIntDataProvider() + public function strictIntDataProvider(): array { return [ [1, true], @@ -186,10 +156,8 @@ public function strictIntDataProvider() /** * @dataProvider strictIntDataProvider * @param mixed $intVal - * @param bool $expected - * @return void */ - public function testStrictComparison($intVal, $expected) + public function testStrictComparison($intVal, bool $expected): void { $this->validator->setLocale('en'); $this->validator->setStrict(true); diff --git a/test/Validator/PhoneNumberTest.php b/test/Validator/PhoneNumberTest.php index 1da72079..fbb99f57 100644 --- a/test/Validator/PhoneNumberTest.php +++ b/test/Validator/PhoneNumberTest.php @@ -1,22 +1,22 @@ */ + private $phone = [ 'AC' => [ 'code' => '247', 'patterns' => [ @@ -928,19 +928,19 @@ class PhoneNumberTest extends TestCase 'fixed' => '123456789', 'mobile' => ['612345678', '700123456', '734567890'], 'tollfree' => '801234567', - 'premium' => ['3123123456', '891123456', '897123456',], - 'shared' => ['810123456', '820123456',], + 'premium' => ['3123123456', '891123456', '897123456'], + 'shared' => ['810123456', '820123456'], 'voip' => '912345678', - 'emergency' => ['15', '17', '18', '112',], + 'emergency' => ['15', '17', '18', '112'], ], 'invalid' => [ - 'fixed' => ['0123456789', '1234567890', '12345678',], - 'mobile' => ['0612345678', '6123456780', '123456789', '6123456789',], - 'tollfree' => ['0801234567', '8012345670', '101234567', '811234567', '8012345678',], - 'premium' => ['31231234560', '03123123456', '2123123456', '894123456',], - 'shared' => ['812123456', '822123456', '830123456', '881123456', '891123456',], - 'voip' => ['123456789', '812345678', '9123456789',], - 'emergency' => ['14', '16', '19', '20', '111', '113',], + 'fixed' => ['0123456789', '1234567890', '12345678'], + 'mobile' => ['0612345678', '6123456780', '123456789', '6123456789'], + 'tollfree' => ['0801234567', '8012345670', '101234567', '811234567', '8012345678'], + 'premium' => ['31231234560', '03123123456', '2123123456', '894123456'], + 'shared' => ['812123456', '822123456', '830123456', '881123456', '891123456'], + 'voip' => ['123456789', '812345678', '9123456789'], + 'emergency' => ['14', '16', '19', '20', '111', '113'], ], ], ], @@ -1039,11 +1039,11 @@ class PhoneNumberTest extends TestCase 'code' => '350', 'patterns' => [ 'example' => [ - 'fixed' => '20012345', - 'mobile' => '57123456', - 'tollfree' => '80123456', - 'premium' => '88123456', - 'shared' => '87123456', + 'fixed' => '20012345', + 'mobile' => '57123456', + 'tollfree' => '80123456', + 'premium' => '88123456', + 'shared' => '87123456', // wrong: 'shortcode' => '116123', 'emergency' => '112', ], @@ -2971,7 +2971,7 @@ class PhoneNumberTest extends TestCase ], ], 'XK' => [ - 'code' => '383', + 'code' => '383', 'patterns' => [ 'example' => [ 'fixed' => '38550001', @@ -2980,7 +2980,7 @@ class PhoneNumberTest extends TestCase 'premium' => '90012345', 'uan' => '700123456', 'shortcode' => '18923', - 'emergency' => ['112', '192','193', '194'], + 'emergency' => ['112', '192', '193', '194'], ], ], ], @@ -3046,56 +3046,75 @@ class PhoneNumberTest extends TestCase protected function setUp(): void { + parent::setUp(); $this->validator = new PhoneNumber(); } + public function testThatTheCountryCanBeRetrievedWhenNoOptionsAreGivenToTheConstructor(): void + { + $expect = Locale::getRegion(Locale::getDefault()); + self::assertEquals( + $expect, + (new PhoneNumber())->getCountry() + ); + } + /** * @dataProvider constructDataProvider - * - * @param array $args - * @param array $options - * @param string $locale + * @param array $constructorOptions */ - public function testConstruct(array $args, array $options, $locale = null) + public function testConstruct(array $constructorOptions, string $expectedCountry, ?string $locale = null): void { - if ($locale) { + if ($locale !== null) { Locale::setDefault($locale); } - $validator = new PhoneNumber($args); + $validator = new PhoneNumber($constructorOptions); - $this->assertSame($options['country'], $validator->getCountry()); + $this->assertSame( + $expectedCountry, + $validator->getCountry(), + sprintf( + 'Expected the country option to be "%s" but "%s" was received', + $expectedCountry, + $validator->getCountry() + ) + ); } - public function constructDataProvider() + /** @return array, 1: string, 2: string|null}> */ + public function constructDataProvider(): array { return [ [ [], - ['country' => Locale::getRegion(Locale::getDefault())], - null + Locale::getRegion(Locale::getDefault()), + null, ], [ [], - ['country' => 'CN'], - 'zh_CN' + 'CN', + 'zh_CN', ], [ ['country' => 'CN'], - ['country' => 'CN'], - null + 'CN', + null, ], ]; } - public function numbersDataProvider() + /** @return list}> */ + public function numbersDataProvider(): array { $data = []; foreach ($this->phone as $country => $parameters) { + /** @psalm-var array $patterns */ + $patterns = $parameters['patterns'] ?? []; $countryRow = [ 'country' => $country, - 'code' => $parameters['code'], - 'patterns' => $parameters['patterns'], + 'code' => (string) $parameters['code'], + 'patterns' => $patterns, ]; $data[] = $countryRow; @@ -3106,15 +3125,14 @@ public function numbersDataProvider() /** * @dataProvider numbersDataProvider - * - * @param string $country - * @param string $code - * @param array $patterns + * @param array $patterns */ - public function testExampleNumbers($country, $code, $patterns) + public function testExampleNumbers(string $country, string $code, array $patterns): void { + /** @psalm-var array $patterns */ + $patterns = $patterns['example'] ?? []; $this->validator->setCountry($country); - foreach ($patterns['example'] as $type => $values) { + foreach ($patterns as $type => $values) { $values = is_array($values) ? $values : [$values]; foreach ($values as $value) { $this->validator->allowedTypes([$type]); @@ -3140,16 +3158,15 @@ public function testExampleNumbers($country, $code, $patterns) /** * @dataProvider numbersDataProvider - * - * @param string $country - * @param string $code - * @param array $patterns + * @param array $patterns */ - public function testExampleNumbersAgainstPossible($country, $code, $patterns) + public function testExampleNumbersAgainstPossible(string $country, string $code, array $patterns): void { $this->validator->allowPossible(true); $this->validator->setCountry($country); - foreach ($patterns['example'] as $type => $values) { + /** @psalm-var array $patterns */ + $patterns = $patterns['example'] ?? []; + foreach ($patterns as $type => $values) { $values = is_array($values) ? $values : [$values]; foreach ($values as $value) { $this->validator->allowedTypes([$type]); @@ -3173,14 +3190,14 @@ public function testExampleNumbersAgainstPossible($country, $code, $patterns) } } - public function testAllowPossibleSetterGetter() + public function testAllowPossibleSetterGetter(): void { $this->assertFalse($this->validator->allowPossible()); $this->validator->allowPossible(true); $this->assertTrue($this->validator->allowPossible()); } - public function testCountryIsCaseInsensitive() + public function testCountryIsCaseInsensitive(): void { $this->validator->setCountry('lt'); $this->assertTrue($this->validator->isValid('+37067811268')); @@ -3190,19 +3207,19 @@ public function testCountryIsCaseInsensitive() /** * @dataProvider numbersDataProvider - * - * @param string $country - * @param string $code - * @param array $patterns + * @param array $patterns */ - public function testInvalidTypes($country, $code, $patterns) + public function testInvalidTypes(string $country, string $code, array $patterns): void { $this->validator->setCountry($country); if (! isset($patterns['invalid'])) { - $this->addToAssertionCount(1); return; } - foreach ($patterns['invalid'] as $type => $values) { + + /** @psalm-var array $patterns */ + $patterns = $patterns['invalid'] ?? []; + + foreach ($patterns as $type => $values) { $values = is_array($values) ? $values : [$values]; foreach ($values as $value) { $this->validator->allowedTypes([$type]); @@ -3222,7 +3239,7 @@ public function testInvalidTypes($country, $code, $patterns) } } - public function testCanSpecifyCountryWithContext() + public function testCanSpecifyCountryWithContext(): void { Locale::setDefault('ZW'); $validator = new PhoneNumber([ diff --git a/test/Validator/PostCodeTest.php b/test/Validator/PostCodeTest.php index 96e543b4..9de4052d 100644 --- a/test/Validator/PostCodeTest.php +++ b/test/Validator/PostCodeTest.php @@ -1,46 +1,35 @@ markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->validator = new PostCodeValidator(['locale' => 'de_AT']); } /** * @dataProvider UKPostCodesDataProvider - * @group #7250 - * @group #7264 */ - public function testUKBasic($postCode, $expected) + public function testUKBasic(string $postCode, bool $expected): void { - $uk_validator = new PostCodeValidator(['locale' => 'en_GB']); - $this->assertSame($expected, $uk_validator->isValid($postCode)); + $ukValidator = new PostCodeValidator(['locale' => 'en_GB']); + $this->assertSame($expected, $ukValidator->isValid($postCode)); } - public function UKPostCodesDataProvider() + /** @return array */ + public function UKPostCodesDataProvider(): array { return [ ['CA3 5JQ', true], @@ -55,7 +44,8 @@ public function UKPostCodesDataProvider() ]; } - public function postCodesDataProvider() + /** @return array */ + public function postCodesDataProvider(): array { return [ ['2292', true], @@ -76,19 +66,17 @@ public function postCodesDataProvider() * Ensures that the validator follows expected behavior * * @dataProvider postCodesDataProvider - * @return void + * @param mixed $postCode */ - public function testBasic($postCode, $expected) + public function testBasic($postCode, bool $expected): void { $this->assertEquals($expected, $this->validator->isValid($postCode)); } /** * Ensures that getMessages() returns expected default value - * - * @return void */ - public function testGetMessages() + public function testGetMessages(): void { $this->assertEquals([], $this->validator->getMessages()); } @@ -96,9 +84,9 @@ public function testGetMessages() /** * Ensures that a region is available */ - public function testSettingLocalesWithoutRegion() + public function testSettingLocalesWithoutRegion(): void { - $this->expectException('Laminas\Validator\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Locale must contain a region'); $this->validator->setLocale('de')->isValid('1000'); } @@ -106,9 +94,9 @@ public function testSettingLocalesWithoutRegion() /** * Ensures that the region contains postal codes */ - public function testSettingLocalesWithoutPostalCodes() + public function testSettingLocalesWithoutPostalCodes(): void { - $this->expectException('Laminas\Validator\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('A postcode-format string has to be given for validation'); $this->validator->setLocale('gez_ER')->isValid('1000'); } @@ -116,7 +104,7 @@ public function testSettingLocalesWithoutPostalCodes() /** * Ensures locales can be retrieved */ - public function testGettingLocale() + public function testGettingLocale(): void { $this->assertEquals('de_AT', $this->validator->getLocale()); } @@ -124,30 +112,27 @@ public function testGettingLocale() /** * Ensures format can be set and retrieved */ - public function testSetGetFormat() + public function testSetGetFormat(): void { $this->validator->setFormat('\d{1}'); $this->assertEquals('\d{1}', $this->validator->getFormat()); } - public function testSetGetFormatThrowsExceptionOnNullFormat() + public function testSetGetFormatThrowsExceptionOnNullFormat(): void { - $this->expectException('Laminas\Validator\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('A postcode-format string has to be given'); $this->validator->setLocale(null)->setFormat(null)->isValid('1000'); } - public function testSetGetFormatThrowsExceptionOnEmptyFormat() + public function testSetGetFormatThrowsExceptionOnEmptyFormat(): void { - $this->expectException('Laminas\Validator\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('A postcode-format string has to be given'); $this->validator->setLocale(null)->setFormat('')->isValid('1000'); } - /** - * @group Laminas-9212 - */ - public function testErrorMessageText() + public function testErrorMessageText(): void { $this->assertFalse($this->validator->isValid('hello')); $message = $this->validator->getMessages(); @@ -155,18 +140,16 @@ public function testErrorMessageText() } /** - * Test service class with invalid validation - * - * @group Laminas-44 - */ - public function testServiceClass() + * Test service class with invalid validation + */ + public function testServiceClass(): void { - $params = (object)[ - 'serviceTrue' => null, - 'serviceFalse' => null, + $params = (object) [ + 'serviceTrue' => null, + 'serviceFalse' => null, ]; - $serviceTrue = static function ($value) use ($params) { + $serviceTrue = static function ($value) use ($params) { $params->serviceTrue = $value; return true; }; @@ -178,13 +161,11 @@ public function testServiceClass() $this->assertEquals(null, $this->validator->getService()); - $this->validator->setService($serviceTrue); $this->assertEquals($this->validator->getService(), $serviceTrue); $this->assertTrue($this->validator->isValid('2292')); $this->assertEquals($params->serviceTrue, '2292'); - $this->validator->setService($serviceFalse); $this->assertEquals($this->validator->getService(), $serviceFalse); $this->assertFalse($this->validator->isValid('hello')); @@ -194,7 +175,7 @@ public function testServiceClass() $this->assertStringContainsString('not appear to be a postal code', $message['postcodeService']); } - public function testEqualsMessageTemplates() + public function testEqualsMessageTemplates(): void { $validator = $this->validator; $this->assertSame($validator->getOption('messageTemplates'), $validator->getMessageTemplates()); @@ -204,7 +185,7 @@ public function testEqualsMessageTemplates() * Post codes are provided by French government official post code database * https://www.data.gouv.fr/fr/datasets/base-officielle-des-codes-postaux/ */ - public function testFrPostCodes() + public function testFrPostCodes(): void { $validator = $this->validator; $validator->setLocale('fr_FR'); @@ -221,7 +202,7 @@ public function testFrPostCodes() * Post codes are provided by Norway Mail database * http://www.bring.no/hele-bring/produkter-og-tjenester/brev-og-postreklame/andre-tjenester/postnummertabeller */ - public function testNoPostCodes() + public function testNoPostCodes(): void { $validator = $this->validator; $validator->setLocale('en_NO'); @@ -237,7 +218,7 @@ public function testNoPostCodes() * To prevent BC break LV- prefix is optional * https://en.wikipedia.org/wiki/Postal_codes_in_Latvia */ - public function testLvPostCodes() + public function testLvPostCodes(): void { $validator = $this->validator; $validator->setLocale('en_LV'); @@ -248,7 +229,8 @@ public function testLvPostCodes() $this->assertFalse($validator->isValid('LV-ABCD')); } - public function liPostCode() + /** @return Generator */ + public function liPostCode(): Generator { yield 'Nendeln' => [9485]; yield 'Schaanwald' => [9486]; @@ -268,9 +250,8 @@ public function liPostCode() /** * @dataProvider liPostCode - * @param int $postCode */ - public function testLiPostCodes($postCode) + public function testLiPostCodes(int $postCode): void { $validator = $this->validator; $validator->setLocale('de_LI'); diff --git a/test/View/Helper/CurrencyFormatTest.php b/test/View/Helper/CurrencyFormatTest.php index 9af51d08..a592d06f 100644 --- a/test/View/Helper/CurrencyFormatTest.php +++ b/test/View/Helper/CurrencyFormatTest.php @@ -1,38 +1,27 @@ markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->helper = new CurrencyFormatHelper(); } - public function currencyProvider() + /** @return array */ + public function currencyProvider(): array { return [ // locale currency show decimals number currencyPattern expected @@ -61,8 +50,14 @@ public function currencyProvider() /** * @dataProvider currencyProvider */ - public function testBasic($locale, $currencyCode, $showDecimals, $number, $currencyPattern, $expected) - { + public function testBasic( + string $locale, + string $currencyCode, + bool $showDecimals, + float $number, + ?string $currencyPattern, + string $expected + ): void { $this->assertMbStringEquals( $expected, $this->helper->__invoke( @@ -79,13 +74,13 @@ public function testBasic($locale, $currencyCode, $showDecimals, $number, $curre * @dataProvider currencyProvider */ public function testSettersProvideDefaults( - $locale, - $currencyCode, - $showDecimals, - $number, - $currencyPattern, - $expected - ) { + string $locale, + string $currencyCode, + bool $showDecimals, + float $number, + ?string $currencyPattern, + string $expected + ): void { $this->helper ->setLocale($locale) ->setShouldShowDecimals($showDecimals) @@ -95,7 +90,7 @@ public function testSettersProvideDefaults( $this->assertMbStringEquals($expected, $this->helper->__invoke($number)); } - public function testViewhelperExecutedSequentially() + public function testViewHelperExecutedSequentially(): void { $helper = $this->helper; $helper->setShouldShowDecimals(true); @@ -105,15 +100,15 @@ public function testViewhelperExecutedSequentially() $this->assertEquals('1.234,43 €', $helper(1234.4321, 'EUR', null, 'de_DE')); } - public function testDefaultLocale() + public function testDefaultLocale(): void { $this->assertMbStringEquals(Locale::getDefault(), $this->helper->getLocale()); } - public function assertMbStringEquals($expected, $test, $message = '') + public function assertMbStringEquals(string $expected, string $test, string $message = ''): void { $expected = str_replace(["\xC2\xA0", ' '], '', $expected); - $test = str_replace(["\xC2\xA0", ' '], '', $test); + $test = str_replace(["\xC2\xA0", ' '], '', $test); $this->assertEquals($expected, $test, $message); } } diff --git a/test/View/Helper/DateFormatTest.php b/test/View/Helper/DateFormatTest.php index eb6f9609..02b4dd12 100644 --- a/test/View/Helper/DateFormatTest.php +++ b/test/View/Helper/DateFormatTest.php @@ -1,66 +1,33 @@ markTestSkipped( - 'Skipping tests that utilize laminas-view until that component is ' - . 'forwards-compatible with laminas-stdlib and laminas-servicemanager v3' - ); - } - - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->helper = new DateFormatHelper(); } - /** - * Tears down the fixture, for example, close a network connection. - * This method is called after a test is executed. - * - * @return void - */ - protected function tearDown(): void + /** @return array */ + public function dateTestsDataProvider(): array { - unset($this->helper); - } - - public function dateTestsDataProvider() - { - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } - $date = new DateTime('2012-07-02T22:44:03Z'); return [ @@ -151,12 +118,9 @@ public function dateTestsDataProvider() ]; } - public function dateTestsDataProviderWithPattern() + /** @return array */ + public function dateTestsDataProviderWithPattern(): array { - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } - $date = new DateTime('2012-07-02T22:44:03Z'); return [ @@ -198,8 +162,13 @@ public function dateTestsDataProviderWithPattern() /** * @dataProvider dateTestsDataProvider */ - public function testBasic($locale, $timezone, $timeType, $dateType, $date) - { + public function testBasic( + string $locale, + string $timezone, + int $timeType, + int $dateType, + DateTimeInterface $date + ): void { $this->helper ->setTimezone($timezone); @@ -218,8 +187,13 @@ public function testBasic($locale, $timezone, $timeType, $dateType, $date) /** * @dataProvider dateTestsDataProvider */ - public function testSettersProvideDefaults($locale, $timezone, $timeType, $dateType, $date) - { + public function testSettersProvideDefaults( + string $locale, + string $timezone, + int $timeType, + int $dateType, + DateTimeInterface $date + ): void { $this->helper ->setTimezone($timezone) ->setLocale($locale); @@ -237,8 +211,14 @@ public function testSettersProvideDefaults($locale, $timezone, $timeType, $dateT /** * @dataProvider dateTestsDataProviderWithPattern */ - public function testUseCustomPattern($locale, $timezone, $timeType, $dateType, $pattern, $date) - { + public function testUseCustomPattern( + string $locale, + string $timezone, + int $timeType, + int $dateType, + string $pattern, + DateTimeInterface $date + ): void { $this->helper ->setTimezone($timezone); @@ -254,12 +234,12 @@ public function testUseCustomPattern($locale, $timezone, $timeType, $dateType, $ )); } - public function testDefaultLocale() + public function testDefaultLocale(): void { $this->assertEquals(Locale::getDefault(), $this->helper->getLocale()); } - public function testBugTwoPatternOnSameHelperInstance() + public function testBugTwoPatternOnSameHelperInstance(): void { $date = new DateTime('2012-07-02T22:44:03Z'); @@ -275,19 +255,24 @@ public function testBugTwoPatternOnSameHelperInstance() ); } - public function assertMbStringEquals($expected, $test, $message = '') + public function assertMbStringEquals(string $expected, string $test, string $message = ''): void { $expected = str_replace(["\xC2\xA0", ' '], '', $expected); $test = str_replace(["\xC2\xA0", ' '], '', $test); $this->assertEquals($expected, $test, $message); } - public function getIntlDateFormatter($locale, $dateType, $timeType, $timezone, $pattern = null) - { - return new IntlDateFormatter($locale, $dateType, $timeType, $timezone, null, $pattern); + public function getIntlDateFormatter( + string $locale, + int $dateType, + int $timeType, + string $timezone, + ?string $pattern = null + ): IntlDateFormatter { + return new IntlDateFormatter($locale, $dateType, $timeType, $timezone, null, $pattern ?? ''); } - public function testDifferentTimezone() + public function testDifferentTimezone(): void { $helper = $this->helper; @@ -302,7 +287,7 @@ public function testDifferentTimezone() self::assertSame('Jan 1, 2018', $helper($date, IntlDateFormatter::MEDIUM)); } - public function testIntlCalendarIsHandledAsWell() + public function testIntlCalendarIsHandledAsWell(): void { $calendar = new IntlGregorianCalendar(2013, 6, 1); diff --git a/test/View/Helper/NumberFormatTest.php b/test/View/Helper/NumberFormatTest.php index 7bf1806f..adddbaa8 100644 --- a/test/View/Helper/NumberFormatTest.php +++ b/test/View/Helper/NumberFormatTest.php @@ -1,57 +1,29 @@ markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->helper = new NumberFormatHelper(); } - /** - * Tears down the fixture, for example, close a network connection. - * This method is called after a test is executed. - * - * @return void - */ - protected function tearDown(): void - { - unset($this->helper); - } - - public function currencyTestsDataProvider() + /** @return array, 5: float, 6: string}> */ + public function currencyTestsDataProvider(): array { - if (! extension_loaded('intl')) { - $this->markTestSkipped('ext/intl not enabled'); - } - return [ [ 'de_DE', @@ -60,7 +32,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234567890000, - '1.234.567,891' + '1.234.567,891', ], [ 'de_DE', @@ -78,7 +50,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234567890000, - '123.456.789 %' + '123.456.789 %', ], [ 'de_DE', @@ -87,7 +59,7 @@ public function currencyTestsDataProvider() 1, [], 1234567.891234567890000, - '123.456.789,1 %' + '123.456.789,1 %', ], [ 'de_DE', @@ -96,7 +68,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234560000, - '1,23456789123456E6' + '1,23456789123456E6', ], [ 'ru_RU', @@ -105,7 +77,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234567890000, - '1 234 567,891' + '1 234 567,891', ], [ 'ru_RU', @@ -114,7 +86,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234567890000, - '123 456 789 %' + '123 456 789 %', ], [ 'ru_RU', @@ -123,7 +95,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234560000, - '1,23456789123456E6' + '1,23456789123456E6', ], [ 'en_US', @@ -132,7 +104,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234567890000, - '1,234,567.891' + '1,234,567.891', ], [ 'en_US', @@ -141,7 +113,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234567890000, - '123,456,789%' + '123,456,789%', ], [ 'en_US', @@ -150,7 +122,7 @@ public function currencyTestsDataProvider() null, [], 1234567.891234560000, - '1.23456789123456E6' + '1.23456789123456E6', ], [ 'en_US', @@ -158,19 +130,27 @@ public function currencyTestsDataProvider() NumberFormatter::TYPE_DOUBLE, null, [ - NumberFormatter::NEGATIVE_PREFIX => 'MINUS' + NumberFormatter::NEGATIVE_PREFIX => 'MINUS', ], -1234567.891234567890000, - 'MINUS123,456,789%' + 'MINUS123,456,789%', ], ]; } /** * @dataProvider currencyTestsDataProvider + * @param array $textAttributes */ - public function testBasic($locale, $formatStyle, $formatType, $decimals, $textAttributes, $number, $expected) - { + public function testBasic( + string $locale, + int $formatStyle, + int $formatType, + ?int $decimals, + array $textAttributes, + float $number, + string $expected + ) { $this->assertMbStringEquals($expected, $this->helper->__invoke( $number, $formatStyle, @@ -183,16 +163,17 @@ public function testBasic($locale, $formatStyle, $formatType, $decimals, $textAt /** * @dataProvider currencyTestsDataProvider + * @param array $textAttributes */ public function testSettersProvideDefaults( - $locale, - $formatStyle, - $formatType, - $decimals, - $textAttributes, - $number, - $expected - ) { + string $locale, + int $formatStyle, + int $formatType, + ?int $decimals, + array $textAttributes, + float $number, + string $expected + ): void { $this->helper ->setLocale($locale) ->setFormatStyle($formatStyle) @@ -203,12 +184,12 @@ public function testSettersProvideDefaults( $this->assertMbStringEquals($expected, $this->helper->__invoke($number)); } - public function testDefaultLocale() + public function testDefaultLocale(): void { $this->assertEquals(Locale::getDefault(), $this->helper->getLocale()); } - public function assertMbStringEquals($expected, $test, $message = '') + public function assertMbStringEquals(string $expected, string $test, string $message = ''): void { $expected = str_replace(["\xC2\xA0", ' '], '', $expected); $test = str_replace(["\xC2\xA0", ' '], '', $test); diff --git a/test/View/Helper/PluralTest.php b/test/View/Helper/PluralTest.php index a8b1161a..756db91c 100644 --- a/test/View/Helper/PluralTest.php +++ b/test/View/Helper/PluralTest.php @@ -1,9 +1,11 @@ markTestSkipped('ext/intl not enabled'); - } - + parent::setUp(); $this->helper = new PluralHelper(); } /** - * @return array + * @return array, 2:int, 3:string}> */ - public function pluralsTestProvider() + public function pluralsTestProvider(): array { return [ - ['nplurals=1; plural=0', 'かさ', 0, 'かさ'], - ['nplurals=1; plural=0', 'かさ', 10, 'かさ'], - + ['nplurals=1; plural=0', ['かさ'], 0, 'かさ'], + ['nplurals=1; plural=0', ['かさ'], 10, 'かさ'], ['nplurals=2; plural=(n==1 ? 0 : 1)', ['umbrella', 'umbrellas'], 0, 'umbrellas'], ['nplurals=2; plural=(n==1 ? 0 : 1)', ['umbrella', 'umbrellas'], 1, 'umbrella'], ['nplurals=2; plural=(n==1 ? 0 : 1)', ['umbrella', 'umbrellas'], 2, 'umbrellas'], - ['nplurals=2; plural=(n==0 || n==1 ? 0 : 1)', ['parapluie', 'parapluies'], 0, 'parapluie'], ['nplurals=2; plural=(n==0 || n==1 ? 0 : 1)', ['parapluie', 'parapluies'], 1, 'parapluie'], ['nplurals=2; plural=(n==0 || n==1 ? 0 : 1)', ['parapluie', 'parapluies'], 2, 'parapluies'], @@ -51,8 +41,9 @@ public function pluralsTestProvider() /** * @dataProvider pluralsTestProvider + * @param list $strings */ - public function testGetCorrectPlurals($pluralRule, $strings, $number, $expected) + public function testGetCorrectPlurals(string $pluralRule, array $strings, int $number, string $expected): void { $this->helper->setPluralRule($pluralRule); $result = $this->helper->__invoke($strings, $number); diff --git a/test/View/Helper/TranslatePluralTest.php b/test/View/Helper/TranslatePluralTest.php index 01cf89ae..dfd884c5 100644 --- a/test/View/Helper/TranslatePluralTest.php +++ b/test/View/Helper/TranslatePluralTest.php @@ -1,10 +1,14 @@ helper = new TranslatePluralHelper(); } - /** - * Tears down the fixture, for example, close a network connection. - * This method is called after a test is executed. - * - * @return void - */ - protected function tearDown(): void - { - unset($this->helper); - } - public function testInvokingWithoutTranslatorWillRaiseException() { - $this->expectException('Laminas\I18n\Exception\RuntimeException'); + $this->expectException(RuntimeException::class); $this->helper->__invoke('singular', 'plural', 1); } diff --git a/test/View/Helper/TranslateTest.php b/test/View/Helper/TranslateTest.php index 027835c9..97948b04 100644 --- a/test/View/Helper/TranslateTest.php +++ b/test/View/Helper/TranslateTest.php @@ -1,10 +1,14 @@ helper = new TranslateHelper(); } - /** - * Tears down the fixture, for example, close a network connection. - * This method is called after a test is executed. - * - * @return void - */ - protected function tearDown(): void - { - unset($this->helper); - } - public function testInvokingWithoutTranslatorWillRaiseException() { - $this->expectException('Laminas\I18n\Exception\RuntimeException'); + $this->expectException(RuntimeException::class); $this->helper->__invoke('message'); }