diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml deleted file mode 100644 index 20dda7e..0000000 --- a/.github/workflows/build-test.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Continuous Integration - -on: - push: - # Avoid running tests on changes to documentation - paths-ignore: - - 'docs/**' - pull_request: - paths-ignore: - - 'docs/**' - -jobs: - build: - strategy: - matrix: - php_version: ['8.1', '8.2', '8.3', '8.4'] - deps: ['--prefer-lowest', '--prefer-dist'] - include: - - code-coverage: 'yes' - php_version: '8.3' - deps: '' - - runs-on: ubuntu-latest - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{matrix.php_version}} - - - name: Check PHP version - run: php -v - - - name: test deps - run: echo ${{ matrix.deps }} - - - uses: actions/checkout@v4 - name: Checkout branch - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v4 - with: - path: vendor - key: ${{ runner.os }}-php--${{matrix.php_version}}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php--${{matrix.php_version}} - - - name: Install/update dependencies - run: composer update ${{matrix.deps}} - - - name: Run PHPUnit test suite with coverage - if: ${{ matrix.code-coverage == 'yes' }} - run: composer test-coverage - - - name: Run PHPUnit test suite no coverage - if: ${{ matrix.code-coverage != 'yes' }} - run: composer test - - - name: Upload coverage results to Coverall - if: ${{ matrix.code-coverage == 'yes' }} - uses: coverallsapp/github-action@v2 - diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml new file mode 100644 index 0000000..26c5802 --- /dev/null +++ b/.github/workflows/continous-integration.yml @@ -0,0 +1,11 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + tags: + +jobs: + ci: + uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x diff --git a/.gitignore b/.gitignore index a7d4c63..4b64650 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build/ /.idea/ .phpunit* #/composer.lock +/.phpcs-cache diff --git a/.laminas-ci.json b/.laminas-ci.json new file mode 100644 index 0000000..cc00d67 --- /dev/null +++ b/.laminas-ci.json @@ -0,0 +1,5 @@ +{ + "ignore_php_platform_requirements": { + "8.4": true + } +} diff --git a/README.md b/README.md index 8cead5c..62905ac 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # LmcCors - ![Build Status](https://github.com/lm-commons/lmccors/actions/workflows/build-test.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/LM-Commons/LmcCors/badge.svg?branch=master)](https://coveralls.io/github/LM-Commons/LmcCors?branch=master) [![Latest Stable Version](https://poser.pugx.org/lm-commons/lmc-cors/v)](//packagist.org/packages/lm-commons/lmc-cors) @@ -45,8 +44,8 @@ With CORS, you can allow your server to reply to such requests. You can find better documentation on how CORS works on the web: - * [Mozilla documentation about CORS](https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS) - * [CORS server flowchart](http://www.html5rocks.com/static/images/cors_server_flowchart.png) +* [Mozilla documentation about CORS](https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS) +* [CORS server flowchart](http://www.html5rocks.com/static/images/cors_server_flowchart.png) ### Event registration @@ -57,20 +56,20 @@ of 2. This means that this listener is executed BEFORE the route has been matche As by default, all the various options are set globally for all routes: -- `allowed_origins`: (array) List of allowed origins. To allow any origin, you can use the wildcard (`*`) character. If +* `allowed_origins`: (array) List of allowed origins. To allow any origin, you can use the wildcard (`*`) character. If multiple origins are specified, LmcCors will automatically check the `"Origin"` header's value, and only return the - allowed domain (if any) in the `"Allow-Access-Control-Origin"` response header. To allow any sub-domain, you can prefix + allowed domain (if any) in the `"Allow-Access-Control-Origin"` response header. To allow any sub-domain, you can prefix the domain with the wildcard character (i.e. `*.example.com`). Please note that you don't need to add your host URI (so if your website is hosted as "example.com", "example.com" is automatically allowed. -- `allowed_methods`: (array) List of allowed HTTP methods. Those methods will be returned for the preflight request to +* `allowed_methods`: (array) List of allowed HTTP methods. Those methods will be returned for the preflight request to indicate which methods are allowed to the user agent. You can even specify custom HTTP verbs. -- `allowed_headers`: (array) List of allowed headers that will be returned for the preflight request. This indicates +* `allowed_headers`: (array) List of allowed headers that will be returned for the preflight request. This indicates to the user agent which headers are permitted to be sent when doing the actual request. -- `max_age`: (int) Maximum age (seconds) the preflight request should be cached by the user agent. This prevents the +* `max_age`: (int) Maximum age (seconds) the preflight request should be cached by the user agent. This prevents the user agent from sending a preflight request for each request. -- `exposed_headers`: (array) List of response headers that are allowed to be read in the user agent. Please note that +* `exposed_headers`: (array) List of response headers that are allowed to be read in the user agent. Please note that some browsers do not implement this feature correctly. -- `allowed_credentials`: (boolean) If true, it allows the browser to send cookies along with the request. +* `allowed_credentials`: (boolean) If true, it allows the browser to send cookies along with the request. If you want to configure specific routes, you can add `LmcCors\Options\CorsOptions::ROUTE_PARAM` to your route configuration: @@ -178,6 +177,7 @@ testing your API with some Google Chrome extensions), you need to add support fo the `UriFactory` config (please [refer to the doc](https://docs.laminas.dev/laminas-uri/usage/#creating-a-new-custom-class-uri)). ### Example + To register the `chrome-extension` custom scheme in your API, simply add: ```php diff --git a/composer.json b/composer.json index e8afbe9..df5a96b 100644 --- a/composer.json +++ b/composer.json @@ -35,18 +35,15 @@ }, "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", - "laminas/laminas-eventmanager": "^2.6.4 || ^3.2.1", + "laminas/laminas-eventmanager": "^3.2.1", "laminas/laminas-http": "^2.10", - "laminas/laminas-mvc": "^2.7.15 || ^3.1.1", - "laminas/laminas-servicemanager": "^2.7.9 || ^3.4.0" + "laminas/laminas-mvc": "^3.1.1", + "laminas/laminas-servicemanager": "^3.4.0" }, "require-dev": { - "laminas/laminas-i18n": "^2.9", - "laminas/laminas-log": "^2.10", "laminas/laminas-modulemanager": "^2.7.2", - "laminas/laminas-view": "^2.8.1", "phpunit/phpunit": "^10.5 || ^11.0", - "laminas/laminas-coding-standard": "^2.5", + "laminas/laminas-coding-standard": "^3.0", "vimeo/psalm": "^5.26.0", "psalm/plugin-phpunit": "^0.19.0" }, @@ -69,7 +66,8 @@ "cs-fix": "phpcbf", "test": "phpunit", "test-coverage": "phpunit --colors=always --coverage-clover build/logs/clover.xml", - "test-coverage-html": "phpunit --colors=always --coverage-html build/html" + "test-coverage-html": "phpunit --colors=always --coverage-html build/html", + "static-analysis": "psalm --shepherd --stats" }, "config": { "allow-plugins": { diff --git a/composer.lock b/composer.lock index 61a1acc..07751a6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "36e82c1a2b708c5675333aa1cd4bf99c", + "content-hash": "efb8689f64b1f970138750e3a6ce4c63", "packages": [ { "name": "brick/varexporter", @@ -1731,35 +1731,38 @@ }, { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.7.2", + "version": "v1.0.0", "source": { "type": "git", - "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", - "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", "shasum": "" }, "require": { "composer-plugin-api": "^1.0 || ^2.0", - "php": ">=5.3", + "php": ">=5.4", "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", "php-parallel-lint/php-parallel-lint": "^1.3.1", - "phpcompatibility/php-compatibility": "^9.0" + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" }, "type": "composer-plugin", "extra": { - "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" }, "autoload": { "psr-4": { - "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1775,7 +1778,7 @@ }, { "name": "Contributors", - "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -1799,10 +1802,10 @@ "tests" ], "support": { - "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", - "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" }, - "time": "2022-02-04T12:51:07+00:00" + "time": "2023-01-05T11:28:13+00:00" }, { "name": "dnoegel/php-xdg-base-dir", @@ -1841,6 +1844,53 @@ }, "time": "2019-12-04T15:06:13+00:00" }, + { + "name": "doctrine/deprecations", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/1.1.3" + }, + "time": "2024-01-30T19:34:25+00:00" + }, { "name": "felixfbecker/advanced-json-rpc", "version": "v3.2.1", @@ -2005,27 +2055,24 @@ }, { "name": "laminas/laminas-coding-standard", - "version": "2.5.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/laminas/laminas-coding-standard.git", - "reference": "c1aaa18a7c860c6932677a3e4ec13161f9fc7d61" + "reference": "ac809f5b27f0b22d0c1ec0cbc78cb67f92bfebcb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/c1aaa18a7c860c6932677a3e4ec13161f9fc7d61", - "reference": "c1aaa18a7c860c6932677a3e4ec13161f9fc7d61", + "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/ac809f5b27f0b22d0c1ec0cbc78cb67f92bfebcb", + "reference": "ac809f5b27f0b22d0c1ec0cbc78cb67f92bfebcb", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", "php": "^7.4 || ^8.0", - "slevomat/coding-standard": "^7.0", - "squizlabs/php_codesniffer": "^3.6", - "webimpress/coding-standard": "^1.2" - }, - "conflict": { - "phpstan/phpdoc-parser": ">=1.6.0" + "slevomat/coding-standard": "^8.15.0", + "squizlabs/php_codesniffer": "^3.10", + "webimpress/coding-standard": "^1.3" }, "type": "phpcodesniffer-standard", "autoload": { @@ -2057,234 +2104,7 @@ "type": "community_bridge" } ], - "time": "2023-01-05T15:53:40+00:00" - }, - { - "name": "laminas/laminas-i18n", - "version": "2.29.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-i18n.git", - "reference": "9aa7ef6073556e9b4cfd8d9a0cb8e41cd3883454" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-i18n/zipball/9aa7ef6073556e9b4cfd8d9a0cb8e41cd3883454", - "reference": "9aa7ef6073556e9b4cfd8d9a0cb8e41cd3883454", - "shasum": "" - }, - "require": { - "ext-intl": "*", - "laminas/laminas-servicemanager": "^3.21.0", - "laminas/laminas-stdlib": "^3.0", - "laminas/laminas-translator": "^1.0", - "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0" - }, - "conflict": { - "laminas/laminas-view": "<2.20.0", - "zendframework/zend-i18n": "*" - }, - "require-dev": { - "laminas/laminas-cache": "^3.12.1", - "laminas/laminas-cache-storage-adapter-memory": "^2.3.0", - "laminas/laminas-cache-storage-deprecated-factory": "^1.2", - "laminas/laminas-coding-standard": "~2.5.0", - "laminas/laminas-config": "^3.9.0", - "laminas/laminas-eventmanager": "^3.13", - "laminas/laminas-filter": "^2.34", - "laminas/laminas-validator": "^2.49", - "laminas/laminas-view": "^2.34", - "phpunit/phpunit": "^10.5.11", - "psalm/plugin-phpunit": "^0.19.0", - "vimeo/psalm": "^5.22.2" - }, - "suggest": { - "laminas/laminas-cache": "You should install this package to cache the translations", - "laminas/laminas-config": "You should install this package to use the INI translation format", - "laminas/laminas-eventmanager": "You should install this package to use the events in the translator", - "laminas/laminas-filter": "You should install this package to use the provided filters", - "laminas/laminas-i18n-resources": "This package provides validator and captcha translations", - "laminas/laminas-validator": "You should install this package to use the provided validators", - "laminas/laminas-view": "You should install this package to use the provided view helpers" - }, - "type": "library", - "extra": { - "laminas": { - "component": "Laminas\\I18n", - "config-provider": "Laminas\\I18n\\ConfigProvider" - } - }, - "autoload": { - "psr-4": { - "Laminas\\I18n\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Provide translations for your application, and filter and validate internationalized values", - "homepage": "https://laminas.dev", - "keywords": [ - "i18n", - "laminas" - ], - "support": { - "chat": "https://laminas.dev/chat", - "docs": "https://docs.laminas.dev/laminas-i18n/", - "forum": "https://discourse.laminas.dev", - "issues": "https://github.com/laminas/laminas-i18n/issues", - "rss": "https://github.com/laminas/laminas-i18n/releases.atom", - "source": "https://github.com/laminas/laminas-i18n" - }, - "funding": [ - { - "url": "https://funding.communitybridge.org/projects/laminas-project", - "type": "community_bridge" - } - ], - "time": "2024-10-11T09:44:53+00:00" - }, - { - "name": "laminas/laminas-log", - "version": "2.17.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-log.git", - "reference": "f24c4c78d3024bb59610845328d7876d6c797065" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-log/zipball/f24c4c78d3024bb59610845328d7876d6c797065", - "reference": "f24c4c78d3024bb59610845328d7876d6c797065", - "shasum": "" - }, - "require": { - "laminas/laminas-servicemanager": "^3.21.0", - "laminas/laminas-stdlib": "^3.0", - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "psr/log": "^1.1.2" - }, - "conflict": { - "zendframework/zend-log": "*" - }, - "provide": { - "psr/log-implementation": "1.0.0" - }, - "require-dev": { - "ext-dom": "*", - "ext-json": "*", - "ext-xml": "*", - "firephp/firephp-core": "^0.5.3", - "laminas/laminas-coding-standard": "~2.3.0", - "laminas/laminas-db": "^2.6", - "laminas/laminas-escaper": "^2.5", - "laminas/laminas-filter": "^2.5", - "laminas/laminas-mail": "^2.6.1", - "laminas/laminas-validator": "^2.10.1", - "mikey179/vfsstream": "^1.6.7", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5.10" - }, - "suggest": { - "ext-mongo": "mongo extension to use Mongo writer", - "ext-mongodb": "mongodb extension to use MongoDB writer", - "laminas/laminas-db": "Laminas\\Db component to use the database log writer", - "laminas/laminas-escaper": "Laminas\\Escaper component, for use in the XML log formatter", - "laminas/laminas-mail": "Laminas\\Mail component to use the email log writer", - "laminas/laminas-validator": "Laminas\\Validator component to block invalid log messages" - }, - "type": "library", - "extra": { - "laminas": { - "component": "Laminas\\Log", - "config-provider": "Laminas\\Log\\ConfigProvider" - } - }, - "autoload": { - "psr-4": { - "Laminas\\Log\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Robust, composite logger with filtering, formatting, and PSR-3 support", - "homepage": "https://laminas.dev", - "keywords": [ - "laminas", - "log", - "logging" - ], - "support": { - "chat": "https://laminas.dev/chat", - "docs": "https://docs.laminas.dev/laminas-log/", - "forum": "https://discourse.laminas.dev", - "issues": "https://github.com/laminas/laminas-log/issues", - "rss": "https://github.com/laminas/laminas-log/releases.atom", - "source": "https://github.com/laminas/laminas-log" - }, - "funding": [ - { - "url": "https://funding.communitybridge.org/projects/laminas-project", - "type": "community_bridge" - } - ], - "time": "2023-12-05T18:27:50+00:00" - }, - { - "name": "laminas/laminas-translator", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-translator.git", - "reference": "12897e710e21413c1f93fc38fe9dead6b51c5218" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-translator/zipball/12897e710e21413c1f93fc38fe9dead6b51c5218", - "reference": "12897e710e21413c1f93fc38fe9dead6b51c5218", - "shasum": "" - }, - "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0" - }, - "require-dev": { - "laminas/laminas-coding-standard": "~3.0.0", - "vimeo/psalm": "^5.24.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Laminas\\Translator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Interfaces for the Translator component of laminas-i18n", - "homepage": "https://laminas.dev", - "keywords": [ - "i18n", - "laminas" - ], - "support": { - "chat": "https://laminas.dev/chat", - "docs": "https://docs.laminas.dev/laminas-i18n/", - "forum": "https://discourse.laminas.dev", - "issues": "https://github.com/laminas/laminas-translator/issues", - "rss": "https://github.com/laminas/laminas-translator/releases.atom", - "source": "https://github.com/laminas/laminas-translator" - }, - "funding": [ - { - "url": "https://funding.communitybridge.org/projects/laminas-project", - "type": "community_bridge" - } - ], - "time": "2024-10-21T15:33:01+00:00" + "time": "2024-10-16T09:23:09+00:00" }, { "name": "myclabs/deep-copy", @@ -2570,28 +2390,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", + "version": "5.6.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" + "reference": "f3558a4c23426d12bffeaab463f8a8d8b681193c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/f3558a4c23426d12bffeaab463f8a8d8b681193c", + "reference": "f3558a4c23426d12bffeaab463f8a8d8b681193c", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.1", "ext-filter": "*", - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", + "phpdocumentor/type-resolver": "^1.7", + "phpstan/phpdoc-parser": "^1.7|^2.0", "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" + "mockery/mockery": "~1.3.5 || ~1.6.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-webmozart-assert": "^1.2", + "phpunit/phpunit": "^9.5", + "psalm/phar": "^5.26" }, "type": "library", "extra": { @@ -2615,36 +2442,39 @@ }, { "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" + "email": "opensource@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.0" }, - "time": "2021-10-19T17:43:47+00:00" + "time": "2024-11-12T11:25:25+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.6.2", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "48f445a408c131e38cab1c235aa6d2bb7a0bb20d" + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/48f445a408c131e38cab1c235aa6d2bb7a0bb20d", - "reference": "48f445a408c131e38cab1c235aa6d2bb7a0bb20d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a", + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a", "shasum": "" }, "require": { - "php": "^7.4 || ^8.0", - "phpdocumentor/reflection-common": "^2.0" + "doctrine/deprecations": "^1.0", + "php": "^7.3 || ^8.0", + "phpdocumentor/reflection-common": "^2.0", + "phpstan/phpdoc-parser": "^1.18|^2.0" }, "require-dev": { "ext-tokenizer": "*", + "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.8", "phpstan/phpstan-phpunit": "^1.1", @@ -2676,31 +2506,34 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.2" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.10.0" }, - "time": "2022-10-14T12:47:21+00:00" + "time": "2024-11-09T15:12:26+00:00" }, { "name": "phpstan/phpdoc-parser", - "version": "1.5.1", + "version": "1.33.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "981cc368a216c988e862a75e526b6076987d1b50" + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/981cc368a216c988e862a75e526b6076987d1b50", - "reference": "981cc368a216c988e862a75e526b6076987d1b50", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5", "symfony/process": "^5.2" @@ -2720,9 +2553,9 @@ "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.5.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" }, - "time": "2022-05-05T11:32:40+00:00" + "time": "2024-10-13T11:25:22+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3208,30 +3041,30 @@ }, { "name": "psr/log", - "version": "1.1.4", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.0.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "3.x-dev" } }, "autoload": { "psr-4": { - "Psr\\Log\\": "Psr/Log/" + "Psr\\Log\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -3252,9 +3085,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" + "source": "https://github.com/php-fig/log/tree/3.0.2" }, - "time": "2021-05-03T11:20:27+00:00" + "time": "2024-09-11T13:17:53+00:00" }, { "name": "sebastian/cli-parser", @@ -4174,42 +4007,42 @@ }, { "name": "slevomat/coding-standard", - "version": "7.2.1", + "version": "8.15.0", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90" + "reference": "7d1d957421618a3803b593ec31ace470177d7817" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/aff06ae7a84e4534bf6f821dc982a93a5d477c90", - "reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/7d1d957421618a3803b593ec31ace470177d7817", + "reference": "7d1d957421618a3803b593ec31ace470177d7817", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.5.1", - "squizlabs/php_codesniffer": "^3.6.2" + "phpstan/phpdoc-parser": "^1.23.1", + "squizlabs/php_codesniffer": "^3.9.0" }, "require-dev": { - "phing/phing": "2.17.3", + "phing/phing": "2.17.4", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.10|1.7.1", - "phpstan/phpstan-deprecation-rules": "1.0.0", - "phpstan/phpstan-phpunit": "1.0.0|1.1.1", - "phpstan/phpstan-strict-rules": "1.2.3", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.20" + "phpstan/phpstan": "1.10.60", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.16", + "phpstan/phpstan-strict-rules": "1.5.2", + "phpunit/phpunit": "8.5.21|9.6.8|10.5.11" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "7.x-dev" + "dev-master": "8.x-dev" } }, "autoload": { "psr-4": { - "SlevomatCodingStandard\\": "SlevomatCodingStandard" + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" } }, "notification-url": "https://packagist.org/downloads/", @@ -4217,9 +4050,13 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.2.1" + "source": "https://github.com/slevomat/coding-standard/tree/8.15.0" }, "funding": [ { @@ -4231,7 +4068,7 @@ "type": "tidelift" } ], - "time": "2022-05-25T10:58:12+00:00" + "time": "2024-03-09T15:20:58+00:00" }, { "name": "spatie/array-to-xml", diff --git a/config/module.config.php b/config/module.config.php deleted file mode 100644 index 60ce070..0000000 --- a/config/module.config.php +++ /dev/null @@ -1,31 +0,0 @@ - [ - 'factories' => [ - Mvc\CorsRequestListener::class => Factory\CorsRequestListenerFactory::class, - Options\CorsOptions::class => Factory\CorsOptionsFactory::class, - Service\CorsService::class => Factory\CorsServiceFactory::class, - ], - ], - - 'lmc_cors' => [], -]; diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 31edb87..c4dc2a9 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,3 +1,296 @@ - + + + + + + + + + + + + getRouteMatch()]]> + + + + getHeader('Access-Control-Request-Method')->getFieldValue()]]> + + + + + + + + + + + + + + + + + + + + + + options->getMaxAge()]]> + + + + + + + getParam(CorsOptions::ROUTE_PARAM) ?: []]]> + getParam(CorsOptions::ROUTE_PARAM) ?: []]]> + + + options->getAllowedHeaders()]]> + options->getAllowedMethods()]]> + options->getExposedHeaders()]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + get('Vary')->getFieldValue()]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/psalm.xml b/psalm.xml index 852b9fd..a70a675 100644 --- a/psalm.xml +++ b/psalm.xml @@ -7,13 +7,13 @@ findUnusedBaselineEntry="true" findUnusedCode="true" findUnusedPsalmSuppress="true" + errorBaseline="psalm.baseline.xml" > - diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index f731f00..b6757a7 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -1,5 +1,7 @@ $this->getDependencyConfig(), - 'lmc_cors' => $this->getModuleConfig(), + 'lmc_cors' => $this->getModuleConfig(), ]; } @@ -25,7 +27,6 @@ public function getDependencyConfig(): array public function getModuleConfig(): array { - return [ - ]; + return []; } } diff --git a/src/Exception/DisallowedOriginException.php b/src/Exception/DisallowedOriginException.php index 1fb75b0..21cd7f4 100644 --- a/src/Exception/DisallowedOriginException.php +++ b/src/Exception/DisallowedOriginException.php @@ -1,4 +1,7 @@ - */ class DisallowedOriginException extends DomainException implements ExceptionInterface { } diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index e5aa171..ac5d4db 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,4 +1,7 @@ - */ interface ExceptionInterface { } diff --git a/src/Exception/InvalidOriginException.php b/src/Exception/InvalidOriginException.php index 42fa5a1..c2dc461 100644 --- a/src/Exception/InvalidOriginException.php +++ b/src/Exception/InvalidOriginException.php @@ -1,13 +1,11 @@ - */ class InvalidOriginException extends DomainException implements ExceptionInterface { /** diff --git a/src/Factory/CorsOptionsFactory.php b/src/Factory/CorsOptionsFactory.php index 74f615d..2eefb29 100644 --- a/src/Factory/CorsOptionsFactory.php +++ b/src/Factory/CorsOptionsFactory.php @@ -1,4 +1,7 @@ */ class CorsOptionsFactory implements FactoryInterface { /** - * @param ContainerInterface $container - * @param $requestedName - * @param array|null $options - * @return CorsOptions + * @param string $requestedName * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): CorsOptions { - /* @var $config array */ + /** @var array $config */ $config = $container->has('config') ? $container->get('config') : []; $config = $config['lmc_cors'] ?? []; diff --git a/src/Factory/CorsRequestListenerFactory.php b/src/Factory/CorsRequestListenerFactory.php index 163938c..2160b96 100644 --- a/src/Factory/CorsRequestListenerFactory.php +++ b/src/Factory/CorsRequestListenerFactory.php @@ -1,4 +1,7 @@ */ class CorsRequestListenerFactory implements FactoryInterface { /** - * @param ContainerInterface $container - * @param $requestedName - * @param $options - * @return CorsRequestListener + * @param string $requestedName * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $requestedName, $options = null): CorsRequestListener + public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): CorsRequestListener { - /* @var $corsService CorsService */ + /** @var CorsService $corsService */ $corsService = $container->get(CorsService::class); return new CorsRequestListener($corsService); diff --git a/src/Factory/CorsServiceFactory.php b/src/Factory/CorsServiceFactory.php index 9485865..7507c8a 100644 --- a/src/Factory/CorsServiceFactory.php +++ b/src/Factory/CorsServiceFactory.php @@ -1,4 +1,7 @@ */ class CorsServiceFactory implements FactoryInterface { /** - * @param ContainerInterface $container - * @param $requestedName - * @param $options - * @return CorsService + * @param string $requestedName * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $requestedName, $options = null): CorsService + public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): CorsService { - /* @var $corsOptions CorsOptions */ + /** @var CorsOptions $corsOptions */ $corsOptions = $container->get(CorsOptions::class); return new CorsService($corsOptions); diff --git a/src/Module.php b/src/Module.php index 48394b7..0020d0b 100644 --- a/src/Module.php +++ b/src/Module.php @@ -1,4 +1,7 @@ */ class Module implements BootstrapListenerInterface, ConfigProviderInterface { - /** * {@inheritDoc} */ public function onBootstrap(EventInterface $e): void { - /* @var $application Application */ - $application = $e->getTarget(); - $serviceManager = $application->getServiceManager(); - $eventManager = $application->getEventManager(); + /** @var Application $application */ + $application = $e->getTarget(); + $serviceManager = $application->getServiceManager(); + $eventManager = $application->getEventManager(); /** @var CorsRequestListener $listener */ - $listener = $serviceManager->get('LmcCors\Mvc\CorsRequestListener'); + $listener = $serviceManager->get(CorsRequestListener::class); $listener->attach($eventManager); } @@ -55,7 +56,7 @@ public function getConfig(): array return [ 'service_manager' => $configProvider->getDependencyConfig(), - 'lmc_cors' => $configProvider->getModuleConfig(), + 'lmc_cors' => $configProvider->getModuleConfig(), ]; } } diff --git a/src/Mvc/CorsRequestListener.php b/src/Mvc/CorsRequestListener.php index 8d84bc7..76df458 100644 --- a/src/Mvc/CorsRequestListener.php +++ b/src/Mvc/CorsRequestListener.php @@ -1,4 +1,7 @@ */ class CorsRequestListener extends AbstractListenerAggregate { - /** - * @var CorsService - */ protected CorsService $corsService; /** * Whether or not a preflight request was detected - * - * @var bool */ protected bool $isPreflight = false; - /** - * @param CorsService $corsService - */ public function __construct(CorsService $corsService) { $this->corsService = $corsService; @@ -70,7 +62,6 @@ public function attach(EventManagerInterface $events, $priority = 1): void /** * Handle a CORS preflight request * - * @param MvcEvent $event * @return null|HttpResponse|void */ public function onCorsPreflight(MvcEvent $event) @@ -78,7 +69,7 @@ public function onCorsPreflight(MvcEvent $event) // Reset state flag $this->isPreflight = false; - /** @var $request HttpRequest */ + /** @var HttpRequest $request */ $request = $event->getRequest(); if (! $request instanceof HttpRequest) { @@ -116,8 +107,6 @@ public function onCorsPreflight(MvcEvent $event) /** * Handle a CORS request (non-preflight, normal CORS request) - * - * @param MvcEvent $event */ public function onCorsRequest(MvcEvent $event): void { @@ -126,12 +115,11 @@ public function onCorsRequest(MvcEvent $event): void return; } - /** @var $request HttpRequest */ - $request = $event->getRequest(); - /** @var $response HttpResponse */ + /** @var HttpRequest $request */ + $request = $event->getRequest(); + /** @var HttpResponse $response */ $response = $event->getResponse(); - if (! $request instanceof HttpRequest) { return; } diff --git a/src/Options/CorsOptions.php b/src/Options/CorsOptions.php index f3a508d..9744454 100644 --- a/src/Options/CorsOptions.php +++ b/src/Options/CorsOptions.php @@ -1,4 +1,7 @@ + * @template TValue + * @extends AbstractOptions */ class CorsOptions extends AbstractOptions { - const ROUTE_PARAM = 'cors'; + public const ROUTE_PARAM = 'cors'; /** * Set the list of allowed origins domain with protocol. - * - * @var array */ protected array $allowedOrigins = []; /** * Set the list of HTTP verbs. - * - * @var array */ protected array $allowedMethods = []; /** * Set the list of headers. - * - * @var array */ protected array $allowedHeaders = []; /** * Set the max age of the authorize request in seconds. - * - * @var int */ protected int $maxAge = 0; /** * Set the list of exposed headers. - * - * @var array */ protected array $exposedHeaders = []; /** * Allow CORS request with credential. - * - * @var bool */ protected bool $allowedCredentials = false; - /** - * @param array $allowedOrigins - * @return void - */ public function setAllowedOrigins(array $allowedOrigins): void { $this->allowedOrigins = $allowedOrigins; } - /** - * @return array - */ public function getAllowedOrigins(): array { return $this->allowedOrigins; } - /** - * @param array $allowedMethods - * @return void - */ public function setAllowedMethods(array $allowedMethods): void { foreach ($allowedMethods as &$allowedMethod) { @@ -102,77 +84,46 @@ public function setAllowedMethods(array $allowedMethods): void $this->allowedMethods = $allowedMethods; } - /** - * @return array - */ public function getAllowedMethods(): array { return $this->allowedMethods; } - /** - * @param array $allowedHeaders - * @return void - */ public function setAllowedHeaders(array $allowedHeaders): void { $this->allowedHeaders = $allowedHeaders; } - /** - * @return array - */ public function getAllowedHeaders(): array { return $this->allowedHeaders; } - /** - * @param int $maxAge - * @return void - */ public function setMaxAge(int $maxAge): void { $this->maxAge = (int) $maxAge; } - /** - * @return int - */ public function getMaxAge(): int { return $this->maxAge; } - /** - * @param array $exposedHeaders - * @return void - */ public function setExposedHeaders(array $exposedHeaders): void { $this->exposedHeaders = $exposedHeaders; } - /** - * @return array - */ public function getExposedHeaders(): array { return $this->exposedHeaders; } - /** - * @param bool $allowedCredentials - * @return void - */ public function setAllowedCredentials(bool $allowedCredentials): void { - $this->allowedCredentials = (bool) $allowedCredentials; + $this->allowedCredentials = $allowedCredentials; } - /** - * @return boolean - */ public function getAllowedCredentials(): bool { return $this->allowedCredentials; diff --git a/src/Service/CorsService.php b/src/Service/CorsService.php index b0cb36c..65dfa49 100644 --- a/src/Service/CorsService.php +++ b/src/Service/CorsService.php @@ -1,4 +1,7 @@ */ class CorsService { - /** - * @var CorsOptions - */ protected CorsOptions $options; - /** - * @param CorsOptions $options - */ public function __construct(CorsOptions $options) { $this->options = $options; @@ -55,9 +55,6 @@ public function __construct(CorsOptions $options) /** * Check if the HTTP request is a CORS request by checking if the Origin header is present and that the * request URI is not the same as the one in the Origin - * - * @param HttpRequest $request - * @return bool */ public function isCorsRequest(HttpRequest $request): bool { @@ -78,17 +75,13 @@ public function isCorsRequest(HttpRequest $request): bool // According to the spec (http://tools.ietf.org/html/rfc6454#section-4), we should check host, port and scheme - return (! ($originUri->getHost() === $requestUri->getHost()) + return ! ($originUri->getHost() === $requestUri->getHost()) || ! ($originUri->getPort() === $requestUri->getPort()) - || ! ($originUri->getScheme() === $requestUri->getScheme()) - ); + || ! ($originUri->getScheme() === $requestUri->getScheme()); } /** * Check if the CORS request is a preflight request - * - * @param HttpRequest $request - * @return bool */ public function isPreflightRequest(HttpRequest $request): bool { @@ -99,9 +92,6 @@ public function isPreflightRequest(HttpRequest $request): bool /** * Create a preflight response by adding the corresponding headers - * - * @param HttpRequest $request - * @return HttpResponse */ public function createPreflightCorsResponse(HttpRequest $request): HttpResponse { @@ -125,14 +115,11 @@ public function createPreflightCorsResponse(HttpRequest $request): HttpResponse /** * Create a preflight response by adding the corresponding headers which are merged with per-route configuration - * - * @param HttpRequest $request - * @param RouteMatch|null $routeMatch - * - * @return HttpResponse */ - public function createPreflightCorsResponseWithRouteOptions(HttpRequest $request, RouteMatch|null $routeMatch = null): HttpResponse - { + public function createPreflightCorsResponseWithRouteOptions( + HttpRequest $request, + RouteMatch|null $routeMatch = null + ): HttpResponse { $options = $this->options; if ($routeMatch instanceof RouteMatch) { $options->setFromArray($routeMatch->getParam(CorsOptions::ROUTE_PARAM) ?: []); @@ -143,14 +130,13 @@ public function createPreflightCorsResponseWithRouteOptions(HttpRequest $request /** * Populate a simple CORS response * - * @param HttpRequest $request - * @param HttpResponse $response - * @param RouteMatch|null $routeMatch - * @return HttpResponse - * @throws DisallowedOriginException If the origin is not allowed + * @throws DisallowedOriginException */ - public function populateCorsResponse(HttpRequest $request, HttpResponse $response, RouteMatch|null $routeMatch = null): HttpResponse - { + public function populateCorsResponse( + HttpRequest $request, + HttpResponse $response, + RouteMatch|null $routeMatch = null + ): HttpResponse { if ($routeMatch instanceof RouteMatch) { $this->options->setFromArray($routeMatch->getParam(CorsOptions::ROUTE_PARAM) ?: []); } @@ -161,7 +147,7 @@ public function populateCorsResponse(HttpRequest $request, HttpResponse $respons // a simple request, it is useless to continue the processing as it will be refused // by the browser anyway, so we throw an exception if ($origin === 'null') { - $origin = $request->getHeader('Origin'); + $origin = $request->getHeader('Origin'); $originHeader = $origin ? $origin->getFieldValue() : ''; throw new DisallowedOriginException( sprintf( @@ -193,8 +179,6 @@ public function populateCorsResponse(HttpRequest $request, HttpResponse $respons * value are wildcard ("*"), an exact domain or a null string. * * @link http://www.w3.org/TR/cors/#access-control-allow-origin-response-header - * @param HttpRequest $request - * @return string */ protected function getAllowedOriginValue(HttpRequest $request): string { @@ -220,10 +204,7 @@ protected function getAllowedOriginValue(HttpRequest $request): string /** * Ensure that the Vary header is set. * - * * @link http://www.w3.org/TR/cors/#resource-implementation - * @param HttpResponse $response - * @return Headers */ public function ensureVaryHeader(HttpResponse $response): Headers { diff --git a/test/Bootstrap.php b/test/Bootstrap.php index 95d2c5b..0cdf036 100644 --- a/test/Bootstrap.php +++ b/test/Bootstrap.php @@ -1,4 +1,7 @@ assertArrayHasKey('dependencies', $config); $this->assertArrayHasKey('lmc_cors', $config); $this->assertArrayHasKey('factories', $config['dependencies']); diff --git a/test/Factory/CorsOptionsFactoryTest.php b/test/Factory/CorsOptionsFactoryTest.php index e332e45..1218179 100644 --- a/test/Factory/CorsOptionsFactoryTest.php +++ b/test/Factory/CorsOptionsFactoryTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Factory\CorsOptionsFactory')] +#[CoversClass(CorsOptionsFactory::class)] class CorsOptionsFactoryTest extends TestCase { /** - * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ diff --git a/test/Factory/CorsRequestListenerFactoryTest.php b/test/Factory/CorsRequestListenerFactoryTest.php index 158e727..da01f10 100644 --- a/test/Factory/CorsRequestListenerFactoryTest.php +++ b/test/Factory/CorsRequestListenerFactoryTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Factory\CorsRequestListenerFactory')] +#[CoversClass(CorsRequestListenerFactory::class)] class CorsRequestListenerFactoryTest extends TestCase { - public function testCanCreateCorsRequestListener() + public function testCanCreateCorsRequestListener(): void { $serviceManager = ServiceManagerFactory::getServiceManager(); $listener = $serviceManager->get(CorsRequestListener::class); diff --git a/test/Factory/CorsServiceFactoryTest.php b/test/Factory/CorsServiceFactoryTest.php index 8117aec..d4642f7 100644 --- a/test/Factory/CorsServiceFactoryTest.php +++ b/test/Factory/CorsServiceFactoryTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Factory\CorsServiceFactory')] +#[CoversClass(CorsServiceFactory::class)] class CorsServiceFactoryTest extends TestCase { - public function testCanCreateCorsService() + public function testCanCreateCorsService(): void { $serviceManager = ServiceManagerFactory::getServiceManager(); $service = $serviceManager->get(CorsService::class); diff --git a/test/ModuleTest.php b/test/ModuleTest.php index 707fae0..019bbb8 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Module')] +#[CoversClass(Module::class)] class ModuleTest extends TestCase { public function testGetConfig() @@ -44,13 +52,13 @@ public function testGetConfig() public function testAssertListenerIsCorrectlyRegistered() { $module = new Module(); - $mvcEvent = $this->getMockBuilder('Laminas\Mvc\MvcEvent')->getMock(); - $application = $this->getMockBuilder('Laminas\Mvc\Application') + $mvcEvent = $this->getMockBuilder(MvcEvent::class)->getMock(); + $application = $this->getMockBuilder(Application::class) ->disableOriginalConstructor() ->getMock(); - $eventManager = $this->getMockBuilder('Laminas\EventManager\EventManagerInterface')->getMock(); - $serviceManager = $this->getMockBuilder('Laminas\ServiceManager\ServiceManager')->getMock(); - $corsListener = $this->getMockBuilder('LmcCors\Mvc\CorsRequestListener') + $eventManager = $this->getMockBuilder(EventManagerInterface::class)->getMock(); + $serviceManager = $this->getMockBuilder(ServiceManager::class)->getMock(); + $corsListener = $this->getMockBuilder(CorsRequestListener::class) ->disableOriginalConstructor() ->getMock(); @@ -60,7 +68,7 @@ public function testAssertListenerIsCorrectlyRegistered() $serviceManager ->expects($this->any()) ->method('get') - ->with('LmcCors\Mvc\CorsRequestListener') + ->with(CorsRequestListener::class) ->willReturn($corsListener); $corsListener->expects($this->once())->method('attach')->with($eventManager); diff --git a/test/Mvc/CorsRequestListenerTest.php b/test/Mvc/CorsRequestListenerTest.php index afa0073..70b3f81 100644 --- a/test/Mvc/CorsRequestListenerTest.php +++ b/test/Mvc/CorsRequestListenerTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Mvc\CorsRequestListener')] +#[CoversClass(CorsRequestListener::class)] class CorsRequestListenerTest extends TestCase { - - /** - * @var CorsService - */ protected CorsService $corsService; - /** - * @var CorsOptions - */ protected CorsOptions $corsOptions; - /** - * @var CorsRequestListener - */ protected CorsRequestListener $corsListener; public function setUp(): void { - $this->corsOptions = new CorsOptions(); - $this->corsService = new CorsService($this->corsOptions); + $this->corsOptions = new CorsOptions(); + $this->corsService = new CorsService($this->corsOptions); $this->corsListener = new CorsRequestListener($this->corsService); } - public function testAttach() + public function testAttach(): void { - $eventManager = $this->getMockBuilder('Laminas\EventManager\EventManagerInterface')->getMock(); + $eventManager = $this->getMockBuilder(EventManagerInterface::class)->getMock(); $matcher = $this->exactly(2); $eventManager ->expects($matcher) ->method('attach') - ->willReturnCallback(function (string $event, callable $callback, int $priority) use ($matcher) { + ->willReturnCallback(function (string $event, callable $callback, int $priority) { match ($event) { MvcEvent::EVENT_ROUTE => '', MvcEvent::EVENT_FINISH => '', @@ -81,10 +73,10 @@ public function testAttach() $this->corsListener->attach($eventManager); } - public function testReturnNothingForNonCorsRequest() + public function testReturnNothingForNonCorsRequest(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $response = new HttpResponse(); $mvcEvent @@ -95,12 +87,12 @@ public function testReturnNothingForNonCorsRequest() $this->assertNull($this->corsListener->onCorsRequest($mvcEvent)); } - public function testImmediatelyReturnResponseForPreflightCorsRequest() + public function testImmediatelyReturnResponseForPreflightCorsRequest(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $response = new HttpResponse(); - $router = new TreeRouteStack(); + $router = new TreeRouteStack(); $request->setMethod('OPTIONS'); $request->getHeaders()->addHeaderLine('Origin', 'http://example.com'); @@ -111,13 +103,13 @@ public function testImmediatelyReturnResponseForPreflightCorsRequest() ->setResponse($response) ->setRouter($router); - $this->assertInstanceOf('Laminas\Http\Response', $this->corsListener->onCorsPreflight($mvcEvent)); + $this->assertInstanceOf(HttpResponse::class, $this->corsListener->onCorsPreflight($mvcEvent)); } - public function testReturnNothingForNormalAuthorizedCorsRequest() + public function testReturnNothingForNormalAuthorizedCorsRequest(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $response = new HttpResponse(); $request->getHeaders()->addHeaderLine('Origin', 'http://example.com'); @@ -131,10 +123,10 @@ public function testReturnNothingForNormalAuthorizedCorsRequest() $this->assertNull($this->corsListener->onCorsRequest($mvcEvent)); } - public function testReturnUnauthorizedResponseForNormalUnauthorizedCorsRequest() + public function testReturnUnauthorizedResponseForNormalUnauthorizedCorsRequest(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $response = new HttpResponse(); $request->getHeaders()->addHeaderLine('Origin', 'http://unauthorized-domain.com'); @@ -152,12 +144,12 @@ public function testReturnUnauthorizedResponseForNormalUnauthorizedCorsRequest() $this->assertEquals('', $newResponse->getContent()); } - public function testImmediatelyReturnBadRequestResponseForInvalidOriginHeaderValue() + public function testImmediatelyReturnBadRequestResponseForInvalidOriginHeaderValue(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $response = new HttpResponse(); - $router = new TreeRouteStack(); + $router = new TreeRouteStack(); $request->getHeaders()->addHeaderLine('Origin', 'file:'); @@ -175,15 +167,12 @@ public function testImmediatelyReturnBadRequestResponseForInvalidOriginHeaderVal /** * Application always triggers `MvcEvent::EVENT_FINISH` and since the `CorsRequestListener` is listening on it, we - * should handle the exception aswell. - * - * - * @return void + * should handle the exception as well */ - public function testOnCorsRequestCanHandleInvalidOriginHeaderValue() + public function testOnCorsRequestCanHandleInvalidOriginHeaderValue(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $response = new HttpResponse(); $request->getHeaders()->addHeaderLine('Origin', 'file:'); @@ -195,36 +184,35 @@ public function testOnCorsRequestCanHandleInvalidOriginHeaderValue() $this->assertNull($this->corsListener->onCorsRequest($mvcEvent)); } - - public function testPreflightWorksWithMethodRoutes() + public function testPreflightWorksWithMethodRoutes(): void { $mvcEvent = new MvcEvent(); - $request = new HttpRequest(); + $request = new HttpRequest(); $request->setUri('/foo'); $request->setMethod('OPTIONS'); $request->getHeaders()->addHeaderLine('Origin', 'http://example.com'); $request->getHeaders()->addHeaderLine('Access-Control-Request-Method', 'GET'); $response = new HttpResponse(); - $router = new TreeRouteStack(); + $router = new TreeRouteStack(); $router ->addRoutes([ 'home' => [ - 'type' => 'literal', - 'options' => [ + 'type' => 'literal', + 'options' => [ 'route' => '/foo', ], 'may_terminate' => false, - 'child_routes' => [ + 'child_routes' => [ 'get' => [ - 'type' => 'method', + 'type' => 'method', 'options' => [ - 'verb' => 'get', + 'verb' => 'get', 'defaults' => [ CorsOptions::ROUTE_PARAM => [ 'allowed_origins' => ['http://example.com'], 'allowed_methods' => ['GET'], ], - ] + ], ], ], ], diff --git a/test/Options/CorsOptionsTest.php b/test/Options/CorsOptionsTest.php index 83fc2a5..41b54c0 100644 --- a/test/Options/CorsOptionsTest.php +++ b/test/Options/CorsOptionsTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Options\CorsOptions')] +#[CoversClass(CorsOptions::class)] class CorsOptionsTest extends TestCase { - public function testCorsOptionsAreSecuredByDefault() + public function testCorsOptionsAreSecuredByDefault(): void { $options = new CorsOptions(); @@ -44,7 +45,7 @@ public function testCorsOptionsAreSecuredByDefault() $this->assertFalse($options->getAllowedCredentials(), 'Cookies are not allowed'); } - public function testCanModifyOptions() + public function testCanModifyOptions(): void { $options = new CorsOptions(); @@ -67,7 +68,7 @@ public function testCanModifyOptions() $this->assertTrue($options->getAllowedCredentials()); } - public function testNormalizeHttpMethods() + public function testNormalizeHttpMethods(): void { $options = new CorsOptions(); diff --git a/test/Service/CorsServiceTest.php b/test/Service/CorsServiceTest.php index 7b52f23..623e535 100644 --- a/test/Service/CorsServiceTest.php +++ b/test/Service/CorsServiceTest.php @@ -1,4 +1,7 @@ - * * @group Coverage */ -#[CoversClass('\LmcCors\Service\CorsService')] +#[CoversClass(CorsService::class)] class CorsServiceTest extends TestCase { - /** - * @var CorsService - */ protected CorsService $corsService; - /** - * @var HttpResponse - */ protected HttpResponse $response; - /** - * @var HttpRequest - */ protected HttpRequest $request; - /** - * @var MvcEvent - */ protected MvcEvent $event; - /** - * @var CorsOptions - */ protected CorsOptions $corsOptions; /** @@ -85,7 +71,7 @@ public function setUp(): void $this->corsService = new CorsService($this->corsOptions); } - public function testCanDetectCorsRequest() + public function testCanDetectCorsRequest(): void { $request = new HttpRequest(); @@ -95,7 +81,7 @@ public function testCanDetectCorsRequest() $this->assertTrue($this->corsService->isCorsRequest($request)); } - public function testIsNotCorsRequestIfNotACrossRequest() + public function testIsNotCorsRequestIfNotACrossRequest(): void { $request = new HttpRequest(); $request->setUri('http://example.com'); @@ -104,7 +90,7 @@ public function testIsNotCorsRequestIfNotACrossRequest() $this->assertFalse($this->corsService->isCorsRequest($request)); } - public function testCanDetectPreflightRequest() + public function testCanDetectPreflightRequest(): void { $request = new HttpRequest(); @@ -120,9 +106,9 @@ public function testCanDetectPreflightRequest() $this->assertTrue($this->corsService->isPreflightRequest($request)); } - public function testProperlyCreatePreflightResponse() + public function testProperlyCreatePreflightResponse(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://example.com'); $response = $this->corsService->createPreflightCorsResponse($request); @@ -143,9 +129,9 @@ public function testProperlyCreatePreflightResponse() $this->assertEquals('true', $headers->get('Access-Control-Allow-Credentials')->getFieldValue()); } - public function testDoesNotAddAllowCredentialsHeadersIfAsked() + public function testDoesNotAddAllowCredentialsHeadersIfAsked(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://example.com'); $this->corsOptions->setAllowedCredentials(false); @@ -155,9 +141,9 @@ public function testDoesNotAddAllowCredentialsHeadersIfAsked() $this->assertFalse($headers->has('Access-Control-Allow-Credentials')); } - public function testCanReturnWildCardAllowOrigin() + public function testCanReturnWildCardAllowOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://funny-origin.com'); $this->corsOptions->setAllowedOrigins(['*']); @@ -167,35 +153,35 @@ public function testCanReturnWildCardAllowOrigin() $this->assertEquals('http://funny-origin.com', $headers->get('Access-Control-Allow-Origin')->getFieldValue()); } - public function testCanReturnWildCardSubDomainAllowOrigin() + public function testCanReturnWildCardSubDomainAllowOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://subdomain.example.com'); $this->corsOptions->setAllowedOrigins(['*.example.com']); $response = $this->corsService->createPreflightCorsResponse($request); - $headers = $response->getHeaders(); + $headers = $response->getHeaders(); $headerValue = $headers->get('Access-Control-Allow-Origin')->getFieldValue(); $this->assertEquals('http://subdomain.example.com', $headerValue); } - public function testCanReturnWildCardSubDomainWithSchemeAllowOrigin() + public function testCanReturnWildCardSubDomainWithSchemeAllowOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'https://subdomain.example.com'); $this->corsOptions->setAllowedOrigins(['https://*.example.com']); $response = $this->corsService->createPreflightCorsResponse($request); - $headers = $response->getHeaders(); + $headers = $response->getHeaders(); $headerValue = $headers->get('Access-Control-Allow-Origin')->getFieldValue(); $this->assertEquals('https://subdomain.example.com', $headerValue); } - public function testReturnNullForMissMatchedWildcardSubDomainOrigin() + public function testReturnNullForMissMatchedWildcardSubDomainOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://subdomain.example.org'); $this->corsOptions->setAllowedOrigins(['*.example.com']); @@ -205,9 +191,9 @@ public function testReturnNullForMissMatchedWildcardSubDomainOrigin() $this->assertEquals('null', $headers->get('Access-Control-Allow-Origin')->getFieldValue()); } - public function testReturnNullForRootDomainOnWildcardSubDomainOrigin() + public function testReturnNullForRootDomainOnWildcardSubDomainOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://example.com'); $this->corsOptions->setAllowedOrigins(['*.example.com']); @@ -217,9 +203,9 @@ public function testReturnNullForRootDomainOnWildcardSubDomainOrigin() $this->assertEquals('null', $headers->get('Access-Control-Allow-Origin')->getFieldValue()); } - public function testReturnNullForDifferentSchemeOnWildcardSubDomainOrigin() + public function testReturnNullForDifferentSchemeOnWildcardSubDomainOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'https://example.com'); $this->corsOptions->setAllowedOrigins(['http://*.example.com']); @@ -229,9 +215,9 @@ public function testReturnNullForDifferentSchemeOnWildcardSubDomainOrigin() $this->assertEquals('null', $headers->get('Access-Control-Allow-Origin')->getFieldValue()); } - public function testReturnNullForUnknownOrigin() + public function testReturnNullForUnknownOrigin(): void { - $request = new HttpRequest(); + $request = new HttpRequest(); $request->getHeaders()->addHeaderLine('Origin', 'http://unauthorized-origin.com'); $response = $this->corsService->createPreflightCorsResponse($request); @@ -240,7 +226,7 @@ public function testReturnNullForUnknownOrigin() $this->assertEquals('null', $headers->get('Access-Control-Allow-Origin')->getFieldValue()); } - public function testEnsureVaryHeaderForNoOrigin() + public function testEnsureVaryHeaderForNoOrigin(): void { $response = new HttpResponse(); @@ -254,11 +240,11 @@ public function testEnsureVaryHeaderForNoOrigin() $this->assertStringContainsString('Origin', $headers->get('Vary')->getFieldValue()); } - public function testEnsureNoVaryHeaderWhenAcceptsAnyOrigin() + public function testEnsureNoVaryHeaderWhenAcceptsAnyOrigin(): void { - $response = new HttpResponse(); + $response = new HttpResponse(); $corsService = new CorsService(new CorsOptions([ - 'allowed_origins' => ['*'] + 'allowed_origins' => ['*'], ])); $corsService->ensureVaryHeader($response); @@ -269,7 +255,7 @@ public function testEnsureNoVaryHeaderWhenAcceptsAnyOrigin() $this->assertFalse($headers->get('Vary')); } - public function testCanPopulateNormalCorsRequest() + public function testCanPopulateNormalCorsRequest(): void { $request = new HttpRequest(); $response = new HttpResponse(); @@ -284,7 +270,7 @@ public function testCanPopulateNormalCorsRequest() $this->assertEquals('Location', $headers->get('Access-Control-Expose-Headers')->getFieldValue()); } - public function testRefuseNormalCorsRequestIfUnauthorized() + public function testRefuseNormalCorsRequestIfUnauthorized(): void { $request = new HttpRequest(); $response = new HttpResponse(); @@ -297,7 +283,7 @@ public function testRefuseNormalCorsRequestIfUnauthorized() $this->corsService->populateCorsResponse($request, $response); } - public function testAddVaryHeaderInNormalRequest() + public function testAddVaryHeaderInNormalRequest(): void { $request = new HttpRequest(); $response = new HttpResponse(); @@ -310,7 +296,7 @@ public function testAddVaryHeaderInNormalRequest() $this->assertTrue($headers->has('Vary')); } - public function testAppendVaryHeaderInNormalRequest() + public function testAppendVaryHeaderInNormalRequest(): void { $request = new HttpRequest(); $response = new HttpResponse(); @@ -325,7 +311,7 @@ public function testAppendVaryHeaderInNormalRequest() $this->assertEquals('Foo, Origin', $headers->get('Vary')->getFieldValue()); } - public function testPopulatesAllowCredentialsNormalCorsRequest() + public function testPopulatesAllowCredentialsNormalCorsRequest(): void { $request = new HttpRequest(); $response = new HttpResponse(); @@ -335,11 +321,11 @@ public function testPopulatesAllowCredentialsNormalCorsRequest() $this->corsService->populateCorsResponse($request, $response); $headers = $response->getHeaders(); - + $this->assertNotNull($headers); $this->assertEquals('true', $headers->get('Access-Control-Allow-Credentials')->getFieldValue()); } - public function testCanDetectCorsRequestFromSameHostButDifferentPort() + public function testCanDetectCorsRequestFromSameHostButDifferentPort(): void { $request = new HttpRequest(); $request->setUri('http://example.com'); @@ -347,7 +333,7 @@ public function testCanDetectCorsRequestFromSameHostButDifferentPort() $this->assertTrue($this->corsService->isCorsRequest($request)); } - public function testCanDetectCorsRequestFromSameHostButDifferentScheme() + public function testCanDetectCorsRequestFromSameHostButDifferentScheme(): void { $request = new HttpRequest(); $request->setUri('https://example.com'); @@ -355,7 +341,7 @@ public function testCanDetectCorsRequestFromSameHostButDifferentScheme() $this->assertTrue($this->corsService->isCorsRequest($request)); } - public function testCanHandleUnconfiguredRouteMatch() + public function testCanHandleUnconfiguredRouteMatch(): void { $routeMatch = new RouteMatch([]); @@ -379,9 +365,8 @@ public function testCanHandleUnconfiguredRouteMatch() $this->assertEquals('true', $headers->get('Access-Control-Allow-Credentials')->getFieldValue()); } - public function testCanHandleConfiguredRouteMatch() + public function testCanHandleConfiguredRouteMatch(): void { - $routeMatchParameters = [ CorsOptions::ROUTE_PARAM => [ 'allowed_origins' => ['http://example.org'], @@ -420,7 +405,7 @@ public function testCanHandleConfiguredRouteMatch() /** * @see https://github.com/zf-fr/zfr-cors/issues/44 */ - public function testDoesNotCrashApplicationOnInvalidOriginValue() + public function testDoesNotCrashApplicationOnInvalidOriginValue(): void { $request = new HttpRequest(); $request->setUri('https://example.com'); @@ -432,13 +417,13 @@ public function testDoesNotCrashApplicationOnInvalidOriginValue() /** * @see https://github.com/zf-fr/zfr-cors/issues/57 */ - public function testCanPopulateNormalCorsRequestWithRouteMatch() + public function testCanPopulateNormalCorsRequestWithRouteMatch(): void { - $request = new HttpRequest(); - $response = new HttpResponse(); + $request = new HttpRequest(); + $response = new HttpResponse(); $routeMatchParameters = [ CorsOptions::ROUTE_PARAM => [ - 'allowed_origins' => ['http://example.org'] + 'allowed_origins' => ['http://example.org'], ], ]; @@ -447,7 +432,7 @@ public function testCanPopulateNormalCorsRequestWithRouteMatch() $request->getHeaders()->addHeaderLine('Origin', 'http://example.org'); $response = $this->corsService->populateCorsResponse($request, $response, $routeMatch); - $this->assertInstanceOf(\Laminas\Http\Response::class, $response); + $this->assertInstanceOf(HttpResponse::class, $response); $this->assertEquals( 'http://example.org', $response->getHeaders()->get('Access-Control-Allow-Origin')->getFieldValue() @@ -457,13 +442,13 @@ public function testCanPopulateNormalCorsRequestWithRouteMatch() /** * @see https://github.com/zf-fr/zfr-cors/issues/57 */ - public function testCanPopulateNormalCorsRequestWithRouteMatchRewriteException() + public function testCanPopulateNormalCorsRequestWithRouteMatchRewriteException(): void { - $request = new HttpRequest(); - $response = new HttpResponse(); + $request = new HttpRequest(); + $response = new HttpResponse(); $routeMatchParameters = [ CorsOptions::ROUTE_PARAM => [ - 'allowed_origins' => ['http://example.org'] + 'allowed_origins' => ['http://example.org'], ], ]; diff --git a/test/Util/ServiceManagerFactory.php b/test/Util/ServiceManagerFactory.php index 2de167a..931b26e 100644 --- a/test/Util/ServiceManagerFactory.php +++ b/test/Util/ServiceManagerFactory.php @@ -1,4 +1,7 @@ - * @author Florent Blaison */ -abstract class ServiceManagerFactory +class ServiceManagerFactory { - /** - * @var array - */ private static array $config = []; /** * @static - * @param array $config - * @return void */ public static function setApplicationConfig(array $config): void { @@ -52,7 +47,6 @@ public static function setApplicationConfig(array $config): void /** * @static - * @return array */ public static function getApplicationConfig(): array { @@ -60,15 +54,13 @@ public static function getApplicationConfig(): array } /** - * @param array|null $config - * @return ServiceManager * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public static function getServiceManager(array|null $config = null): ServiceManager { - $config = $config ?: static::getApplicationConfig(); - $serviceManager = new ServiceManager(); + $config = $config !== null ?: static::getApplicationConfig(); + $serviceManager = new ServiceManager(); $serviceManagerConfig = new ServiceManagerConfig( $config['service_manager'] ?? [] ); @@ -76,7 +68,7 @@ public static function getServiceManager(array|null $config = null): ServiceMana $serviceManager->setService('ApplicationConfig', $config); - /* @var $moduleManager ModuleManagerInterface */ + /** @var ModuleManagerInterface $moduleManager */ $moduleManager = $serviceManager->get('ModuleManager'); $moduleManager->loadModules(); diff --git a/test/testing.config.php b/test/testing.config.php index 41a6edf..6eeda09 100644 --- a/test/testing.config.php +++ b/test/testing.config.php @@ -1,4 +1,7 @@ [ - - ], + 'lmc_cors' => [], ];