From 2eaa3a70ce2b0ea3701252269bb09ac05e31a5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 4 Jul 2023 20:21:09 +0200 Subject: [PATCH 1/4] reactivate project --- .gitattributes | 36 +- .../{dependabot.yml => dependabot.temp.yml} | 3 +- .github/labels.yml | 14 +- .github/release-drafter.yml | 91 +++- .github/renovate.json5 | 73 +++ .github/workflows/cleanup-caches.yml | 39 ++ .github/workflows/codeql.yml | 83 +++ .github/workflows/continuous-integration.yml | 494 +++--------------- .github/workflows/dependency-review.yml | 34 ++ .github/workflows/labels.yml | 20 +- .github/workflows/lock-closed-issues.yml | 3 +- .github/workflows/reactions.yml | 10 +- .github/workflows/release-drafter.yml | 26 +- .gitignore | 9 +- .markdown-link-check.json | 7 + .mega-linter.yml | 27 + .phplint.yml | 8 + .yamllint.yml | 23 + LICENSE.md | 2 +- codecov.yml | 18 +- composer.json | 28 +- infection.json5 | 23 + phpcs.xml | 12 +- phpmd.ruleset.xml | 13 +- phpstan.neon | 77 ++- phpunit.xml | 38 +- psalm.xml | 18 + rector.php | 56 ++ 28 files changed, 787 insertions(+), 498 deletions(-) rename .github/{dependabot.yml => dependabot.temp.yml} (97%) create mode 100644 .github/renovate.json5 create mode 100644 .github/workflows/cleanup-caches.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/dependency-review.yml create mode 100644 .markdown-link-check.json create mode 100644 .mega-linter.yml create mode 100644 .phplint.yml create mode 100644 .yamllint.yml create mode 100644 infection.json5 create mode 100644 psalm.xml create mode 100644 rector.php diff --git a/.gitattributes b/.gitattributes index cd81734..f88905f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,23 +15,31 @@ *.txt text eol=lf *.ini text eol=lf *.sh text eol=lf +*.stub text eol=lf *.tmp text eol=lf # binary files *.zip -text binary # files/folders to ignore -/.* export-ignore -.editorconfig export-ignore text eol=lf -.gitattributes export-ignore text eol=lf -.gitignore export-ignore text eol=lf -.php-cs-fixer.php export-ignore text eol=lf -codecov.yml export-ignore text eol=lf -infection.json export-ignore text eol=lf -phpcs.xml export-ignore text eol=lf -phpmd.ruleset.xml export-ignore text eol=lf -phpstan.neon export-ignore text eol=lf -phpunit.xml export-ignore text eol=lf -rector.php export-ignore text eol=lf -/tests export-ignore -/.github export-ignore +/.* export-ignore +.github/CODEOWNERS export-ignore text eol=lf +.editorconfig export-ignore text eol=lf +.gitattributes export-ignore text eol=lf +.gitignore export-ignore text eol=lf +.markdown-link-check.json export-ignore text eol=lf +.mega-linter.yml export-ignore text eol=lf +.php-cs-fixer.php export-ignore text eol=lf +.phplint.yml export-ignore text eol=lf +.yamllint.yml export-ignore text eol=lf +codecov.yml export-ignore text eol=lf +infection.json export-ignore text eol=lf +infection.json5 export-ignore text eol=lf +phpcs.xml export-ignore text eol=lf +phpmd.ruleset.xml export-ignore text eol=lf +phpstan.neon export-ignore text eol=lf +phpunit.xml export-ignore text eol=lf +psalm.xml export-ignore text eol=lf +rector.php export-ignore text eol=lf +/tests export-ignore +/.github export-ignore diff --git a/.github/dependabot.yml b/.github/dependabot.temp.yml similarity index 97% rename from .github/dependabot.yml rename to .github/dependabot.temp.yml index 9c5abe7..204a93b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.temp.yml @@ -17,6 +17,7 @@ updates: - "mimmi20" labels: - "dependencies" + - "patch" versioning-strategy: increase commit-message: include: "scope" @@ -49,6 +50,6 @@ updates: - "mimmi20" labels: - "dependencies" + - "patch" commit-message: - include: "scope" prefix: "github-actions" diff --git a/.github/labels.yml b/.github/labels.yml index 42154f4..1d1a067 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -33,8 +33,8 @@ name: "stale" description: "no activity" - color: b60205 - name: "BC Break" - description: "" + name: "bc break" + description: "BC Break" - color: f4e99c name: "maintenance" description: "Maintenance" @@ -53,9 +53,17 @@ - color: 0075ca name: "documentation" description: "Improvements or additions to documentation" +- color: 84175d + name: "major" + description: "Major change" +- color: d86c28 + name: "minor" + description: "Minor change" +- color: 0a9b47 + name: "patch" + description: "Patch" # other Labels to mimmi20/ua-generic-request #- color: 5319e7 # name: "new useragents" # description: "" - diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index c1239c5..1a953c4 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -2,37 +2,84 @@ template: | ## Whatโ€™s Changed $CHANGES + + ## ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป Contributors + + $CONTRIBUTORS + +change-template: "- $TITLE by @$AUTHOR (#$NUMBER)" +change-title-escapes: '\<*_&#@`' # You can add # and @ to disable mentions, and add ` to disable code blocks. +no-changes-template: "- No changes" +name-template: "$RESOLVED_VERSION" +tag-template: "$RESOLVED_VERSION" +version-template: "$MAJOR.$MINOR.$PATCH" + exclude-labels: - - duplicate - - question - - invalid - - wontfix + - "duplicate" + - "question" + - "invalid" + - "wontfix" + +version-resolver: + major: + labels: + - "bc break" + - "removed" + - "major" + minor: + labels: + - "deprecated" + - "security" + - "minor" + patch: + labels: + - "bug" + - "dependencies" + - "enhancement" + - "maintenance" + - "documentation" + - "patch" + default: patch + +autolabeler: + - label: "documentation" + files: + - "*.md" + categories: - - title: '**๐Ÿ’ฅ Breaking:**' + - title: "**๐Ÿ’ฅ Breaking:**" + labels: + - "bc break" + - title: "**๐Ÿฐ Enhancements:**" labels: - - 'BC Break' - - title: '**๐Ÿฐ Enhancements:**' + - "enhancement" + - title: "**๐Ÿž Bugs:**" labels: - - 'enhancement' - - title: '**๐Ÿž Bugs:**' + - "bug" + - title: "**๐Ÿ’€ Deprecated:**" labels: - - 'bug' - - title: '**๐Ÿ’€ Deprecated:**' + - "deprecated" + - title: "**๐Ÿ—‘ Removed:**" labels: - - 'deprecated' - - title: '**๐Ÿ—‘ Removed:**' + - "removed" + - title: "**๐Ÿ›ก Security:**" labels: - - 'removed' - - title: '**๐Ÿ›ก Security:**' + - "security" + - title: "**๐Ÿ•ธ Dependencies:**" labels: - - 'security' - - title: '**๐Ÿ•ธ Dependencies:**' + - "dependencies" + - title: "**๐Ÿงน Maintenance:**" labels: - - 'dependencies' - - title: '**๐Ÿงน Maintenance:**' + - "maintenance" + - title: "**๐Ÿ“ฆ Documentation:**" labels: - - 'maintenance' + - "documentation" # other Labels to mimmi20/ua-generic-request - #- title: '**๐Ÿ“ฆ new Useragents:**' + #- title: "**๐Ÿ“ฆ new Useragents:**" # labels: - # - 'new useragents' + # - "new useragents" + +commitish: master +target_commitish: master +filter-by-commitish: true +include-pre-releases: true diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..2b33e09 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,73 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + + "extends": ["github>whitesource/merge-confidence:beta"], + + "enabled": true, + "assignees": [ + "mimmi20" + ], + "automerge": false, + "commitBody": "Signed-off-by: {{{gitAuthor}}}", + "commitBodyTable": true, + "dependencyDashboard": false, + "enabledManagers": ["composer", "github-actions", "npm"], + "ignoreUnstable": true, + "labels": [ + "dependencies", + "patch" + ], + "lockFileMaintenance": { + "enabled": false + }, + "platformAutomerge": false, + "prBodyColumns": [ + "Package", + "Change", + "Type", + "Update" + ], + "prBodyDefinitions": { + "Package": "`{{{depName}}}`", + "Type": "{{{depType}}}", + "Update": "{{{updateType}}}", + "Change": "[{{#if displayFrom}}`{{{displayFrom}}}` -> {{else}}{{#if currentValue}}`{{{currentValue}}}` -> {{/if}}{{/if}}{{#if displayTo}}`{{{displayTo}}}`{{else}}`{{{newValue}}}`{{/if}}]({{#if depName}}https://renovatebot.com/diffs/npm/{{replace '/' '%2f' depName}}/{{{currentVersion}}}/{{{newVersion}}}{{/if}})" + }, + "prCreation": "immediate", + "rangeStrategy": "bump", + "rebaseWhen": "behind-base-branch", + "reviewers": [ + "mimmi20" + ], + "rollbackPrs": true, + "schedule": ["at 4:00 am on Monday"], + "semanticCommits": "disabled", + "separateMajorMinor": true, + "separateMinorPatch": false, + "timezone": "Europe/Berlin", + "updateLockFiles": false, + "updateNotScheduled": false, + "packageRules": [ + { + "groupName": "all non-major dependencies", + "groupSlug": "all-minor-patch-dependencies", + "matchPackagePatterns": [ + "*" + ], + "matchUpdateTypes": [ + "minor", + "patch" + ] + }, + { + "groupName": "PHP", + "matchPackageNames": ["php"], + "allowedVersions": "^8.1", + "ignoreUnstable": false, + "rangeStrategy": "widen" + } + ], + "vulnerabilityAlerts": { + "enabled": true + } +} diff --git a/.github/workflows/cleanup-caches.yml b/.github/workflows/cleanup-caches.yml new file mode 100644 index 0000000..ff7c97f --- /dev/null +++ b/.github/workflows/cleanup-caches.yml @@ -0,0 +1,39 @@ +name: cleanup caches by a branch +on: + pull_request: + types: + - "closed" + workflow_dispatch: + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + lfs: false + persist-credentials: false + + - name: "Cleanup" + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + BRANCH=${{ github.ref }} + + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 ) + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..8288794 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,83 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: + - "master" + pull_request: + # The branches below must be a subset of the branches above + branches: + - "master" + schedule: + - cron: "28 0 * * 0" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: + - 'javascript' + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + lfs: false + persist-credentials: false + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # โ„น๏ธ Command-line programs to run using the OS shell. + # ๐Ÿ“š See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8adbbb0..0e32f9f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,355 +1,43 @@ # https://help.github.com/en/categories/automating-your-workflow-with-github-actions +name: "Continuous Integration" + on: - pull_request - push -name: "Continuous Integration" +permissions: + contents: read -env: - PHP_EXTENSIONS: "json, opcache, mbstring" - PHP_INI_VALUES: "opcache.enable=1, opcache.fast_shutdown=0, zend.assertions=1, assert.exception=On, intl.default_locale=de, intl.use_exceptions=1, zend.exception_ignore_args=0" - COMPOSER_OPTIONS: "--optimize-autoloader --prefer-dist --prefer-stable -v" - TOOLS: "composer:v2" +concurrency: + group: "${{ github.event_name }}-${{ github.workflow }}-${{ github.head_ref || github.run_id }}-${{ github.ref }}" + cancel-in-progress: true jobs: - validate: - name: "Validate composer" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: false - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-20.04" - - php-version: - - "7.4" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}" - - - name: "Validate composer.json" - run: "composer validate --strict" - - lint: - name: "Linting" - - needs: "validate" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: false - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-20.04" - - php-version: - - "7.4" - - "8.0" - - "8.1" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}" - - - name: "Lint PHP" - if: "${{ matrix.php-version == '7.4' }}" - uses: "overtrue/phplint@7.4" - - - name: "Lint PHP" - if: "${{ matrix.php-version != '7.4' }}" - uses: "overtrue/phplint@8.0" - - install: - name: "Install dependencies" - - needs: "validate" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: ${{ matrix.experimental }} - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-18.04" - - "ubuntu-20.04" - - php-version: - - "7.4" - - "8.0" - - "8.1" - - dependencies: - - "highest" - - "lowest" - - experimental: [false] - - include: - - operating-system: "ubuntu-20.04" - php-version: "8.2" - dependencies: "highest" - experimental: true - - operating-system: "ubuntu-20.04" - php-version: "8.2" - dependencies: "lowest" - experimental: true - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}" - - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" - - - name: "Check dependencies with composer" - run: "composer outdated --direct" - - php-cs-fixer: - name: "Check Coding Standards with PHP-CS-Fixer" - - needs: "lint" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: false - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-20.04" - - php-version: - - "7.4" - - dependencies: - - "highest" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}, cs2pr" - - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" - - - name: "Run friendsofphp/php-cs-fixer" - run: "vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr" - - phpcs: - name: "Check Coding Standards with PHPCS" - - needs: "lint" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: false - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-20.04" - - php-version: - - "7.4" - - dependencies: - - "highest" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}, cs2pr" - - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" - - - name: "Run squizlabs/php_codesniffer" - run: "vendor/bin/phpcs --report=checkstyle -q | cs2pr" - - static-code-analysis: - name: "Static Code Analysis with PHPStan" - - needs: "lint" - - runs-on: "${{ matrix.operating-system }}" - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-20.04" - - php-version: - - "7.4" - - dependencies: - - "highest" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}" - - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" - - - name: "Run phpstan/phpstan" - run: "vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=768M --no-progress" - - phpmd: - name: "Check Rules with PHPMD" - - needs: "lint" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: false - - strategy: - fail-fast: false - - matrix: - operating-system: - - "ubuntu-20.04" - - php-version: - - "7.4" - - dependencies: - - "highest" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}, phpmd" - - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" - - - name: "Run phpmd/phpmd" - run: "phpmd src github phpmd.ruleset.xml" + ci: + name: "Run CI" + + uses: "mimmi20/mimmi20/.github/workflows/ci.yml@main" + with: + extensions: "ctype, curl, json, opcache, dom, mbstring, intl, simplexml, tokenizer, xml, xmlwriter" + ini-values: "opcache.enable=1, opcache.fast_shutdown=0, zend.assertions=1, assert.exception=On, intl.default_locale=de, intl.use_exceptions=1, zend.exception_ignore_args=0" + composer-options: "--optimize-autoloader --prefer-dist --prefer-stable -v" + composer-outdated-option: "" + skip-phpstan: false + skip-phplint: false + skip-rector: false + skip-phpmd: false + skip-psalm: true + secrets: + envPAT: "${{ secrets.GITHUB_TOKEN }}" tests: name: "UnitTests with PHPUnit" - needs: "lint" + needs: "ci" runs-on: "${{ matrix.operating-system }}" - + timeout-minutes: 10 continue-on-error: false strategy: @@ -357,42 +45,51 @@ jobs: matrix: operating-system: - - "ubuntu-18.04" - "ubuntu-20.04" + - "ubuntu-22.04" php-version: - - "7.4" - - "8.0" - "8.1" + - "8.2" dependencies: - "highest" - "lowest" + ts: + - "ts" + - "nts" + steps: - name: "Checkout" - uses: "actions/checkout@v2.4.0" + uses: "actions/checkout@v3" with: # Disabling shallow clone is recommended for improving relevancy of reporting fetch-depth: 0 + lfs: false + persist-credentials: false - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" + uses: "shivammathur/setup-php@2.25.4" with: php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" + extensions: "json, opcache, dom, mbstring, intl, simplexml, tokenizer, xml, xmlwriter, curl" + ini-values: "opcache.enable=1, opcache.fast_shutdown=0, zend.assertions=1, assert.exception=On, intl.default_locale=de, intl.use_exceptions=1, zend.exception_ignore_args=0" coverage: "none" - tools: "${{ env.TOOLS }}" + tools: "composer:v2" + env: + fail-fast: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + phpts: "${{ matrix.ts }}" - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@2.2.0" with: dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" + composer-options: "--optimize-autoloader --prefer-dist --prefer-stable -v" - name: "Run unit tests with phpunit/phpunit" - run: "vendor/bin/phpunit -c phpunit.xml --verbose --no-coverage" + run: "vendor/bin/phpunit -c phpunit.xml --no-coverage" code-coverage: name: "Code Coverage with PHPUnit" @@ -400,7 +97,7 @@ jobs: needs: "tests" runs-on: "${{ matrix.operating-system }}" - + timeout-minutes: 10 continue-on-error: false strategy: @@ -408,105 +105,82 @@ jobs: matrix: operating-system: - - "ubuntu-18.04" - "ubuntu-20.04" + - "ubuntu-22.04" php-version: - - "7.4" - - "8.0" - "8.1" + - "8.2" dependencies: - "highest" - "lowest" - coverage-drivers: - - "xdebug" - steps: - name: "Checkout" - uses: "actions/checkout@v2.4.0" + uses: "actions/checkout@v3" with: # Disabling shallow clone is recommended for improving relevancy of reporting fetch-depth: 0 + lfs: false + persist-credentials: false - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" + uses: "shivammathur/setup-php@2.25.4" with: php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "${{ matrix.coverage-drivers }}" - tools: "${{ env.TOOLS }}, infection" + extensions: "json, opcache, dom, mbstring, intl, simplexml, tokenizer, xml, xmlwriter, curl" + ini-values: "opcache.enable=1, opcache.fast_shutdown=0, zend.assertions=1, assert.exception=On, intl.default_locale=de, intl.use_exceptions=1, zend.exception_ignore_args=0, xdebug.mode=coverage" + coverage: "xdebug" + tools: "composer:v2" + env: + fail-fast: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + phpts: "ts" - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@2.2.0" with: dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" + composer-options: "--optimize-autoloader --prefer-dist --prefer-stable -v" - name: "Create cache directory for phpunit/phpunit" run: "mkdir -p .build/coverage" - name: "Collect code coverage with Xdebug and phpunit/phpunit" - run: "vendor/bin/phpunit -c phpunit.xml --verbose --coverage-clover=.build/coverage/clover.xml --coverage-text --coverage-xml=.build/coverage/coverage-xml --log-junit=.build/coverage/phpunit.junit.xml" + run: "vendor/bin/phpunit -c phpunit.xml --coverage-clover=.build/coverage/clover.xml --coverage-text --coverage-xml=.build/coverage/coverage-xml --log-junit=.build/coverage/phpunit.junit.xml" - name: "Upload coverage to Codecov" - uses: "codecov/codecov-action@v2.1.0" + uses: "codecov/codecov-action@v3.1.4" with: file: ".build/coverage/clover.xml" - flags: "phpunit,php-${{ matrix.php-version }},${{ matrix.coverage-drivers }},${{ matrix.php-version }},${{ matrix.operating-system }}" + flags: "phpunit,php-${{ matrix.php-version }},${{ matrix.operating-system }}" verbose: false - name: "Run mutation tests with infection/infection" - run: "infection -s --min-covered-msi=95 --min-msi=95 --coverage=.build/coverage --logger-github" - - roave-backwards-compatibility-check: - name: "Check for Backward Compatibility breaks" - - needs: "lint" - - runs-on: "${{ matrix.operating-system }}" - - continue-on-error: false + env: + STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + run: "vendor/bin/infection --show-mutations --only-covered --min-covered-msi=95 --min-msi=95 --coverage=.build/coverage --logger-github --no-progress -vv" - strategy: - fail-fast: false + # This is a meta job to avoid to have to constantly change the protection rules + # whenever we touch the matrix. + tests-status: + name: "Unit & Integration Tests Status" - matrix: - operating-system: - - "ubuntu-20.04" + runs-on: "ubuntu-22.04" - php-version: - - "8.1" + if: always() - dependencies: - - "highest" + needs: + - "ci" + - "tests" + - "code-coverage" steps: - - name: "Checkout" - uses: "actions/checkout@v2.4.0" - with: - # Disabling shallow clone is recommended for improving relevancy of reporting - fetch-depth: 0 - - - name: "Install PHP" - uses: "shivammathur/setup-php@2.17.0" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.PHP_EXTENSIONS }}, sodium, intl" - ini-values: "${{ env.PHP_INI_VALUES }}" - coverage: "none" - tools: "${{ env.TOOLS }}" - - - name: "Require Roave/BackwardCompatibilityCheck" - run: "composer require --no-update --no-interaction --prefer-dist --prefer-stable --dev \"roave/backward-compatibility-check:^6.1\" \"mimmi20/coding-standard:^2.6\" \"friendsofphp/php-cs-fixer:^3.4\"" - - - name: "Update dependencies with composer" - uses: "ramsey/composer-install@v1" - with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "${{ env.COMPOSER_OPTIONS }}" + - name: Successful run + if: ${{ !(contains(needs.*.result, 'failure')) }} + run: exit 0 - - name: "Check for BC breaks" - run: "vendor/bin/roave-backward-compatibility-check --format=github-actions" + - name: Failing run + if: ${{ contains(needs.*.result, 'failure') }} + run: exit 1 diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000..ee87fd1 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,34 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement + +name: "Dependency Review" + +on: + - pull_request + +permissions: + contents: read + pull-requests: write + +jobs: + dependency-review: + runs-on: "ubuntu-latest" + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + lfs: false + persist-credentials: false + + - name: "Dependency Review" + uses: "actions/dependency-review-action@v3" + with: + "license-check": true + "vulnerability-check": true + "comment-summary-in-pr": true diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index 9ecf90b..5ba35c1 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -5,16 +5,32 @@ name: "Sync labels in the declarative way" on: push: branches: - - master + - "master" + paths: + - ".github/labels.yml" + - ".github/workflows/labels.yml" + +permissions: + contents: read jobs: build: name: "Sync labels" + permissions: + issues: write + runs-on: ubuntu-latest steps: - - uses: "actions/checkout@v2.4.0" + - name: "Checkout" + uses: "actions/checkout@v3" + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + lfs: false + persist-credentials: false + - uses: "micnncim/action-label-syncer@v1.3.0" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lock-closed-issues.yml b/.github/workflows/lock-closed-issues.yml index 096347e..017bf7c 100644 --- a/.github/workflows/lock-closed-issues.yml +++ b/.github/workflows/lock-closed-issues.yml @@ -2,7 +2,8 @@ name: Lock closed issue on: issues: - types: [closed] + types: + - "closed" jobs: lock: diff --git a/.github/workflows/reactions.yml b/.github/workflows/reactions.yml index 326a44d..f86d186 100644 --- a/.github/workflows/reactions.yml +++ b/.github/workflows/reactions.yml @@ -4,9 +4,13 @@ name: 'Reaction Comments' on: issue_comment: - types: [created, edited] + types: + - "created" + - "edited" pull_request_review_comment: - types: [created, edited] + types: + - "created" + - "edited" permissions: actions: write @@ -17,7 +21,7 @@ jobs: action: runs-on: ubuntu-latest steps: - - uses: dessant/reaction-comments@v2 + - uses: dessant/reaction-comments@v3 with: github-token: ${{ secrets.GITHUB_TOKEN }} issue-comment: > diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 2327aff..d2fe7b4 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -6,18 +6,34 @@ on: push: # branches to consider in the event; optional, defaults to all branches: - - master - tags: - - '*' + - "master" + # pull_request event is required only for autolabeler + pull_request: + # Only following types are handled by the action, but one can default to all as well + types: + - "opened" + - "reopened" + - "synchronize" + # pull_request_target event is required for autolabeler to support PRs from forks + # pull_request_target: + +permissions: + contents: read jobs: update-release-draft: + permissions: + # write permission is required to create a GitHub release + contents: write + # write permission is required for autolabeler + # otherwise, read permission is required at least + pull-requests: write - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: # Drafts your next Release notes as Pull Requests are merged into "master" - name: "Release Drafter" - uses: "release-drafter/release-drafter@v5.18.1" + uses: "release-drafter/release-drafter@v5.24.0" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index e0747e5..7ac7073 100644 --- a/.gitignore +++ b/.gitignore @@ -13,10 +13,15 @@ result.txt phpunit.txt resources/browscap-*/ tests/create-tests.php -cache/cache/ +cache/* +!cache/.gitkeep tests/temp/*.php tests/temp/*.ini .php-cs-fixer.cache +.phplint-cache .phpunit.result.cache +.phpcs.cache infection-*.log -clover.xml +rewrite*.php +.reports/ +*.bak diff --git a/.markdown-link-check.json b/.markdown-link-check.json new file mode 100644 index 0000000..084971c --- /dev/null +++ b/.markdown-link-check.json @@ -0,0 +1,7 @@ +{ + "timeout": "30s", + "retryOn429": true, + "retryCount": 5, + "fallbackRetryDelay": "30s", + "aliveStatusCodes": [200, 206] +} diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..38de616 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,27 @@ +VALIDATE_ALL_CODEBASE: true +LOG_LEVEL: INFO +PRINT_ALPACA: false +SHOW_ELAPSED_TIME: true +FILTER_REGEX_EXCLUDE: (vendor/) +ENABLE: + - EDITORCONFIG + - MARKDOWN + - YAML +DISABLE: + - SPELL + #- COPYPASTE +DISABLE_LINTERS: + - MARKDOWN_MARKDOWN_TABLE_FORMATTER + - MARKDOWN_MARKDOWN_LINK_CHECK + - EDITORCONFIG_EDITORCONFIG_CHECKER + - YAML_V8R +EDITORCONFIG_EDITORCONFIG_CHECKER_FILTER_REGEX_EXCLUDE: "(\\.idea|\\.editorconfig|\\.github|\\.phpunit\\.result\\.cache|LICENSE)" +JSON_PRETTIER_FILTER_REGEX_EXCLUDE: "(composer\\.json)" +MARKDOWN_MARKDOWNLINT_FILTER_REGEX_EXCLUDE: "(\\.github)" +MARKDOWN_MARKDOWN_LINK_CHECK_FILTER_REGEX_EXCLUDE: "(\\.github)" +PHP_PHPCS_CONFIG_FILE: "phpcs.xml" +PHP_PHPCS_ARGUMENTS: "-n" +PHP_PHPSTAN_CONFIG_FILE: "phpstan.neon" +PHP_PHPSTAN_FILTER_REGEX_INCLUDE: "(src)" +YAML_YAMLLINT_FILTER_REGEX_EXCLUDE: "(\\.github)" +YAML_PRETTIER_FILTER_REGEX_EXCLUDE: "(\\.github)" diff --git a/.phplint.yml b/.phplint.yml new file mode 100644 index 0000000..605755a --- /dev/null +++ b/.phplint.yml @@ -0,0 +1,8 @@ +path: ./ +jobs: 10 +cache: .phplint.cache +extensions: + - php +exclude: + - vendor +warning: false diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..c167ccd --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,23 @@ +--- + +yaml-files: + - '*.yaml' + - '*.yml' + - '.yamllint' + +rules: + brackets: + forbid: false + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: 0 + max-spaces-inside-empty: 1 + + document-start: disable + + empty-lines: + max: 1 + + line-length: disable + + new-line-at-end-of-file: enable diff --git a/LICENSE.md b/LICENSE.md index c221723..d5497b7 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The MIT License (MIT) -Copyright (c) 2015-2021 Thomas Mรผller +Copyright (c) 2015-2023 Thomas Mรผller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the _Software_), to deal in the Software without restriction, including without limitation the diff --git a/codecov.yml b/codecov.yml index bafa33f..65d180e 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,6 +1,20 @@ codecov: + require_ci_to_pass: false notify: - require_ci_to_pass: yes + wait_for_ci: false + status: + project: + default: + target: 100% + threshold: 1% + informational: true + patch: + default: + informational: true comment: - require_changes: yes + layout: "reach, diff, flags, files" + behavior: default + require_changes: false # if true: only post the comment if coverage changes + require_base: false # [yes :: must have a base report to post] + require_head: false # [yes :: must have a head report to post] diff --git a/composer.json b/composer.json index e83c439..8d2c3cc 100644 --- a/composer.json +++ b/composer.json @@ -16,19 +16,30 @@ ], "homepage": "https://github.com/mimmi20/ua-generic-request", "require": { - "php": "^7.4.3 || ^8.0.0", + "php": "^8.1.0", "ext-json": "*", "ext-mbstring": "*", "laminas/laminas-diactoros": "^2.8.0", "psr/http-message": "^1.0.1" }, "require-dev": { - "mimmi20/coding-standard": "^2.6.3", - "phpstan/extension-installer": "^1.1.0", - "phpstan/phpstan": "^1.4.6", - "phpstan/phpstan-deprecation-rules": "^1.0.0", - "phpstan/phpstan-phpunit": "^1.0.0", - "phpunit/phpunit": "^9.5.13" + "ext-ctype": "*", + "ext-dom": "*", + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "infection/infection": "^0.27.0", + "laminas/laminas-servicemanager": "^3.21.0", + "mimmi20/coding-standard": "^5.1.1", + "nikic/php-parser": "^4.16.0", + "phpstan/extension-installer": "^1.3.1", + "phpstan/phpstan": "^1.10.21", + "phpstan/phpstan-deprecation-rules": "^1.1.3", + "phpstan/phpstan-phpunit": "^1.3.13", + "phpunit/phpunit": "^10.2.2", + "rector/rector": "^0.17.1", + "vimeo/psalm": "^5.13.0" }, "minimum-stability": "stable", "prefer-stable": true, @@ -47,7 +58,8 @@ "sort-packages": true, "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "infection/extension-installer": true } } } diff --git a/infection.json5 b/infection.json5 new file mode 100644 index 0000000..83318fc --- /dev/null +++ b/infection.json5 @@ -0,0 +1,23 @@ +{ + "timeout": 10, + "source": { + "directories": [ + "src" + ] + }, + "phpUnit": { + "configDir": ".", + "customPath": "vendor/bin/phpunit" + }, + "logs": { + "text": "infection-log.log", + "debug": "infection-debug.log", + "stryker": { + "report": "/^.*$/" + } + }, + "mutators": { + "@default": true, + "MBString": false + } +} diff --git a/phpcs.xml b/phpcs.xml index d59ce66..07c6b19 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,8 +1,5 @@ - + ua-generic-request @@ -10,10 +7,15 @@ - + + + + + src tests .php-cs-fixer.php + rector.php diff --git a/phpmd.ruleset.xml b/phpmd.ruleset.xml index fc18ff9..b7ce722 100644 --- a/phpmd.ruleset.xml +++ b/phpmd.ruleset.xml @@ -1,5 +1,5 @@ - + + + + - - + + + + + diff --git a/phpstan.neon b/phpstan.neon index 452a2c4..ba7b4a1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,18 +1,90 @@ parameters: level: max + parallel: maximumNumberOfProcesses: 1 processTimeout: 200.0 + paths: - src - tests + scanFiles: - %currentWorkingDirectory%/vendor/autoload.php - %currentWorkingDirectory%/vendor/squizlabs/php_codesniffer/autoload.php - %currentWorkingDirectory%/vendor/squizlabs/php_codesniffer/src/Util/Tokens.php - checkGenericClassInNonGenericObjectType: false - checkMissingIterableValueType: false + + # reports occurrences of type-checking functions always evaluated to true + checkAlwaysTrueCheckTypeFunctionCall: false + + # reports instanceof occurrences always evaluated to true + checkAlwaysTrueInstanceof: true + + # reports === and !== occurrences always evaluated to true + checkAlwaysTrueStrictComparison: true + + # enable stricter analysis of benevolent union types + checkBenevolentUnionTypes: true + + # reports use of dynamic properties as undefined + checkDynamicProperties: true + + # reports code paths with missing return statement in functions and methods with @return mixed PHPDoc + checkExplicitMixedMissingReturn: true + + # reports function and method calls with incorrect name case + checkFunctionNameCase: true + + # it requires type variables always be specified in typehints + checkGenericClassInNonGenericObjectType: true + + # be strict about values with an unspecified (implicit mixed) type + checkImplicitMixed: false + + # reports references to built-in classes with incorrect name case + checkInternalClassCaseSensitivity: true + + # require that callable signatures are specified + checkMissingCallableSignature: true + + # checks for missing typehints in iterables + checkMissingIterableValueType: true + + # reports return typehints that could be narrowed down because some of the listed types are never returned + checkTooWideReturnTypesInProtectedAndPublicMethods: true + + # reports properties with native types that werenโ€™t initialized in the class constructor + checkUninitializedProperties: true + + # doesnโ€™t require typehints for properties if the types can be inferred from constructor injection + inferPrivatePropertyTypeFromConstructor: false + + # prevents reading key and value variables set in foreach when iterating over a non-empty array + polluteScopeWithAlwaysIterableForeach: false + + # prevents reading variables set in for loop initial statement and while loop condition after the loop + polluteScopeWithLoopInitialAssignments: false + + # report always true last condition in a series of elseif branches and match expression arms + reportAlwaysTrueInLastCondition: true + + # reports violations of parameter type contravariance and return type covariance + reportMaybesInMethodSignatures: true + + # reports violations of property type invariance + reportMaybesInPropertyPhpDocTypes: false + + # reports violations of parameter type contravariance and return type covariance in static methods + reportStaticMethodSignatures: true + + # + reportWrongPhpDocTypeInVarTag: true + + # differentiate between PHPDoc and native types (if false) treatPhpDocTypesAsCertain: false + + tipsOfTheDay: false + exceptions: implicitThrows: false checkedExceptionRegexes: @@ -21,5 +93,6 @@ parameters: check: missingCheckedExceptionInThrows: true tooWideThrowType: true + # ignoreErrors: # - '~MockObject~' diff --git a/phpunit.xml b/phpunit.xml index bdd1bd4..00a4941 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,47 +2,57 @@ + colors="true" + cacheDirectory="./.reports/.coverage-cache" +> - - - - tests/ - + + - + src/ + + + + + tests/ + + + + + + + + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..9c7d891 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..42b1fa5 --- /dev/null +++ b/rector.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types = 1); + +use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; +use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector; +use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector; +use Rector\Php71\Rector\FuncCall\CountOnNullRector; +use Rector\Php81\Rector\Array_\FirstClassCallableRector; +use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; +use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\Set\ValueObject\LevelSetList; +use Rector\Set\ValueObject\SetList; + +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + // $rectorConfig->rule(\Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\InlineConstructorDefaultToPropertyRector::class); + + $rectorConfig->sets([ + SetList::DEAD_CODE, + LevelSetList::UP_TO_PHP_81, + PHPUnitSetList::PHPUNIT_100, + ]); + + $rectorConfig->skip( + [ + NullToStrictStringFuncCallArgRector::class, + RemoveDeadInstanceOfRector::class, + FirstClassCallableRector::class, + RemoveAlwaysTrueIfConditionRector::class, + RemoveParentCallWithoutParentRector::class, + CountOnNullRector::class, + ], + ); + + $rectorConfig->skip([ + ReadOnlyPropertyRector::class => [ + __DIR__ . '/src/LaminasRbacFactory.php', + ], + ]); +}; From 8c8f753520a80477c2c7ffec255f0dff08f7626a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 4 Jul 2023 20:31:59 +0200 Subject: [PATCH 2/4] update dependencies --- composer.json | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 8d2c3cc..e4a6ac2 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "php": "^8.1.0", "ext-json": "*", "ext-mbstring": "*", - "laminas/laminas-diactoros": "^2.8.0", - "psr/http-message": "^1.0.1" + "laminas/laminas-diactoros": "^3.0.0", + "psr/http-message": "^1.1 || ^2.0" }, "require-dev": { "ext-ctype": "*", @@ -30,16 +30,15 @@ "ext-xml": "*", "ext-xmlwriter": "*", "infection/infection": "^0.27.0", - "laminas/laminas-servicemanager": "^3.21.0", - "mimmi20/coding-standard": "^5.1.1", + "mimmi20/coding-standard": "^5.1.4", "nikic/php-parser": "^4.16.0", "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.10.21", + "phpstan/phpstan": "^1.10.23", "phpstan/phpstan-deprecation-rules": "^1.1.3", "phpstan/phpstan-phpunit": "^1.3.13", - "phpunit/phpunit": "^10.2.2", - "rector/rector": "^0.17.1", - "vimeo/psalm": "^5.13.0" + "phpunit/phpunit": "^10.2.3", + "rector/rector": "^0.17.2", + "vimeo/psalm": "^5.13.1" }, "minimum-stability": "stable", "prefer-stable": true, From 967b90e8c9f3af6bc13ba8bbf4e97958983a43db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 4 Jul 2023 22:07:23 +0200 Subject: [PATCH 3/4] fix issues --- .php-cs-fixer.php | 9 +- rector.php | 4 +- src/Constants.php | 2 +- src/GenericRequest.php | 23 +- src/GenericRequestFactory.php | 13 +- src/GenericRequestFactoryInterface.php | 8 +- src/GenericRequestInterface.php | 10 +- src/Header/BaiduFlyflow.php | 15 +- src/Header/DeviceStockUa.php | 25 +- src/Header/HeaderInterface.php | 8 +- src/Header/HeaderLoader.php | 7 +- src/Header/HeaderLoaderInterface.php | 6 +- src/Header/SecChUa.php | 15 +- src/Header/SecChUaArch.php | 15 +- src/Header/SecChUaBitness.php | 15 +- src/Header/SecChUaFullVersion.php | 15 +- src/Header/SecChUaFullVersionList.php | 15 +- src/Header/SecChUaMobile.php | 15 +- src/Header/SecChUaModel.php | 15 +- src/Header/SecChUaPlatform.php | 15 +- src/Header/SecChUaPlatformVersion.php | 15 +- src/Header/UaOs.php | 15 +- src/Header/Useragent.php | 15 +- src/Header/XDeviceUseragent.php | 15 +- src/Header/XOperaminiPhone.php | 15 +- src/Header/XOperaminiPhoneUa.php | 25 +- src/Header/XOriginalUseragent.php | 15 +- src/Header/XPuffinUa.php | 15 +- src/Header/XRequestedWith.php | 15 +- src/Header/XUcbrowserDevice.php | 15 +- src/Header/XUcbrowserDeviceUa.php | 27 +- src/Header/XUcbrowserPhone.php | 17 +- src/Header/XUcbrowserPhoneUa.php | 17 +- src/Header/XUcbrowserUa.php | 17 +- src/NotFoundException.php | 2 +- tests/GenericRequestFactoryTest.php | 60 ++-- tests/GenericRequestTest.php | 334 +++++++++++++------- tests/Header/BaiduFlyflowTest.php | 8 +- tests/Header/DeviceStockUaTest.php | 17 +- tests/Header/HeaderLoaderTest.php | 14 +- tests/Header/SecChUaArchTest.php | 8 +- tests/Header/SecChUaBitnessTest.php | 8 +- tests/Header/SecChUaFullVersionListTest.php | 8 +- tests/Header/SecChUaFullVersionTest.php | 8 +- tests/Header/SecChUaMobileTest.php | 8 +- tests/Header/SecChUaModelTest.php | 8 +- tests/Header/SecChUaPlatformTest.php | 8 +- tests/Header/SecChUaPlatformVersionTest.php | 8 +- tests/Header/SecChUaTest.php | 8 +- tests/Header/UaOsTest.php | 8 +- tests/Header/UseragentTest.php | 8 +- tests/Header/XDeviceUseragentTest.php | 8 +- tests/Header/XOperaminiPhoneTest.php | 8 +- tests/Header/XOperaminiPhoneUaTest.php | 17 +- tests/Header/XOriginalUseragentTest.php | 8 +- tests/Header/XPuffinUaTest.php | 8 +- tests/Header/XRequestedWithTest.php | 8 +- tests/Header/XUcbrowserDeviceTest.php | 8 +- tests/Header/XUcbrowserDeviceUaTest.php | 8 +- tests/Header/XUcbrowserPhoneTest.php | 8 +- tests/Header/XUcbrowserPhoneUaTest.php | 8 +- tests/Header/XUcbrowserUaTest.php | 17 +- 62 files changed, 666 insertions(+), 451 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 0b2ff3b..cebb8aa 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,7 +12,7 @@ $header = <<<'EOF' This file is part of the ua-generic-request package. - Copyright (c) 2015-2021, Thomas Mueller + Copyright (c) 2015-2023, Thomas Mueller For the full copyright and license information, please view the LICENSE file that was distributed with this source code. @@ -23,6 +23,7 @@ ->name('*.php') ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') + ->append([__DIR__ . '/rector.php']) ->append([__FILE__]); $rules = require 'vendor/mimmi20/coding-standard/src/php-cs-fixer.config.php'; @@ -41,8 +42,8 @@ 'location' => 'after_open', 'separate' => 'bottom', ], - ] - ) + ], + ), ) ->setUsingCache(true) ->setFinder($finder); diff --git a/rector.php b/rector.php index 42b1fa5..a299191 100644 --- a/rector.php +++ b/rector.php @@ -1,8 +1,8 @@ + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Constants.php b/src/Constants.php index 10d5790..2903c91 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/GenericRequest.php b/src/GenericRequest.php index 522f476..52bac89 100644 --- a/src/GenericRequest.php +++ b/src/GenericRequest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -56,18 +56,16 @@ final class GenericRequest implements GenericRequestInterface Constants::HEADER_WAP_PROFILE, Constants::HEADER_NB_CONTENT, ]; + /** @var array */ private array $headers = []; /** @var array */ private array $filteredHeaders = []; - private HeaderLoaderInterface $loader; - - public function __construct(MessageInterface $message, HeaderLoaderInterface $loader) + /** @throws void */ + public function __construct(MessageInterface $message, private readonly HeaderLoaderInterface $loader) { - $this->loader = $loader; - foreach (array_keys($message->getHeaders()) as $header) { if (!is_string($header)) { continue; @@ -81,6 +79,8 @@ public function __construct(MessageInterface $message, HeaderLoaderInterface $lo /** * @return array + * + * @throws void */ public function getHeaders(): array { @@ -89,6 +89,8 @@ public function getHeaders(): array /** * @return array + * + * @throws void */ public function getFilteredHeaders(): array { @@ -101,6 +103,7 @@ public function getFilteredHeaders(): array return $headers; } + /** @throws void */ public function getBrowserUserAgent(): string { foreach ($this->filteredHeaders as $header) { @@ -112,6 +115,7 @@ public function getBrowserUserAgent(): string return ''; } + /** @throws void */ public function getDeviceUserAgent(): string { foreach ($this->filteredHeaders as $header) { @@ -123,6 +127,7 @@ public function getDeviceUserAgent(): string return ''; } + /** @throws void */ public function getPlatformUserAgent(): string { foreach ($this->filteredHeaders as $header) { @@ -134,6 +139,7 @@ public function getPlatformUserAgent(): string return ''; } + /** @throws void */ public function getEngineUserAgent(): string { foreach ($this->filteredHeaders as $header) { @@ -145,18 +151,19 @@ public function getEngineUserAgent(): string return ''; } + /** @throws void */ private function filterHeaders(): void { $headers = $this->headers; $filtered = array_filter( self::HEADERS, - static fn ($value): bool => array_key_exists($value, $headers) + static fn ($value): bool => array_key_exists($value, $headers), ); foreach ($filtered as $header) { try { $headerObj = $this->loader->load($header, $this->headers[$header]); - } catch (NotFoundException $e) { + } catch (NotFoundException) { continue; } diff --git a/src/GenericRequestFactory.php b/src/GenericRequestFactory.php index 405ee97..b5d8959 100644 --- a/src/GenericRequestFactory.php +++ b/src/GenericRequestFactory.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -25,6 +25,8 @@ final class GenericRequestFactory implements GenericRequestFactoryInterface { /** * Create a Generic Request from the given $userAgent + * + * @throws void */ public function createRequestFromString(string $userAgent): GenericRequest { @@ -35,6 +37,8 @@ public function createRequestFromString(string $userAgent): GenericRequest * Creates Generic Request from the given HTTP Request (normally $_SERVER). * * @param array $headers HTTP Request + * + * @throws void */ public function createRequestFromArray(array $headers): GenericRequest { @@ -43,7 +47,7 @@ public function createRequestFromArray(array $headers): GenericRequest foreach ($headers as $header => $value) { $upperCaseHeader = mb_strtoupper($header); - if (false === mb_strpos($upperCaseHeader, 'HTTP_')) { + if (mb_strpos($upperCaseHeader, 'HTTP_') === false) { $upperCaseHeader = 'HTTP_' . $upperCaseHeader; } @@ -61,18 +65,21 @@ public function createRequestFromArray(array $headers): GenericRequest /** * Create a Generic Request from a given PSR-7 HTTP message + * + * @throws void */ public function createRequestFromPsr7Message(MessageInterface $message): GenericRequest { return new GenericRequest($message, new HeaderLoader()); } + /** @throws void */ private function filterHeader(string $header): string { return (string) preg_replace( ["#(?:(?:(? + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -20,16 +20,22 @@ interface GenericRequestFactoryInterface * Creates Generic Request from the given HTTP Request (normally $_SERVER). * * @param array $headers HTTP Request + * + * @throws void */ public function createRequestFromArray(array $headers): GenericRequest; /** * Create a Generic Request from the given $userAgent + * + * @throws void */ public function createRequestFromString(string $userAgent): GenericRequest; /** * Create a Generic Request from a given PSR-7 HTTP message + * + * @throws void */ public function createRequestFromPsr7Message(MessageInterface $message): GenericRequest; } diff --git a/src/GenericRequestInterface.php b/src/GenericRequestInterface.php index fbb6215..61c8b70 100644 --- a/src/GenericRequestInterface.php +++ b/src/GenericRequestInterface.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,19 +16,27 @@ interface GenericRequestInterface { /** * @return array + * + * @throws void */ public function getHeaders(): array; /** * @return array + * + * @throws void */ public function getFilteredHeaders(): array; + /** @throws void */ public function getBrowserUserAgent(): string; + /** @throws void */ public function getDeviceUserAgent(): string; + /** @throws void */ public function getPlatformUserAgent(): string; + /** @throws void */ public function getEngineUserAgent(): string; } diff --git a/src/Header/BaiduFlyflow.php b/src/Header/BaiduFlyflow.php index 8468aa9..4fa8040 100644 --- a/src/Header/BaiduFlyflow.php +++ b/src/Header/BaiduFlyflow.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,21 +16,23 @@ final class BaiduFlyflow implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { $hasMatch = preg_match('/;htc;htc;/i', $this->value); @@ -38,16 +40,19 @@ public function hasDeviceInfo(): bool return !$hasMatch; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/DeviceStockUa.php b/src/Header/DeviceStockUa.php index 553401f..168a94f 100644 --- a/src/Header/DeviceStockUa.php +++ b/src/Header/DeviceStockUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,36 +16,47 @@ final class DeviceStockUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { - return (bool) preg_match('/samsung|nokia|blackberry|smartfren|sprint|iphone|lava|gionee|philips|htc|mi 2sc/i', $this->value); + return (bool) preg_match( + '/samsung|nokia|blackberry|smartfren|sprint|iphone|lava|gionee|philips|htc|mi 2sc/i', + $this->value, + ); } + /** @throws void */ public function hasBrowserInfo(): bool { return (bool) preg_match('/opera mini/i', $this->value); } + /** @throws void */ public function hasPlatformInfo(): bool { - return (bool) preg_match('/bada|android|blackberry|brew|iphone|mre|windows|mtk/i', $this->value); + return (bool) preg_match( + '/bada|android|blackberry|brew|iphone|mre|windows|mtk/i', + $this->value, + ); } + /** @throws void */ public function hasEngineInfo(): bool { return (bool) preg_match('/trident|presto|webkit|gecko/i', $this->value); diff --git a/src/Header/HeaderInterface.php b/src/Header/HeaderInterface.php index 2ae2e35..45e4701 100644 --- a/src/Header/HeaderInterface.php +++ b/src/Header/HeaderInterface.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,14 +16,20 @@ interface HeaderInterface { /** * Retrieve header value + * + * @throws void */ public function getValue(): string; + /** @throws void */ public function hasDeviceInfo(): bool; + /** @throws void */ public function hasBrowserInfo(): bool; + /** @throws void */ public function hasPlatformInfo(): bool; + /** @throws void */ public function hasEngineInfo(): bool; } diff --git a/src/Header/HeaderLoader.php b/src/Header/HeaderLoader.php index 36b7fb9..2c83632 100644 --- a/src/Header/HeaderLoader.php +++ b/src/Header/HeaderLoader.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -37,14 +37,13 @@ final class HeaderLoader implements HeaderLoaderInterface Constants::HEADER_UCBROWSER_UA => XUcbrowserUa::class, ]; + /** @throws void */ public function has(string $key): bool { return array_key_exists($key, self::OPTIONS); } - /** - * @throws NotFoundException - */ + /** @throws NotFoundException */ public function load(string $key, string $value): HeaderInterface { if (!$this->has($key)) { diff --git a/src/Header/HeaderLoaderInterface.php b/src/Header/HeaderLoaderInterface.php index b7dbe50..485c4f5 100644 --- a/src/Header/HeaderLoaderInterface.php +++ b/src/Header/HeaderLoaderInterface.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,8 +16,6 @@ interface HeaderLoaderInterface { - /** - * @throws NotFoundException - */ + /** @throws NotFoundException */ public function load(string $key, string $value): HeaderInterface; } diff --git a/src/Header/SecChUa.php b/src/Header/SecChUa.php index 6dae4dc..230220b 100644 --- a/src/Header/SecChUa.php +++ b/src/Header/SecChUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return true; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaArch.php b/src/Header/SecChUaArch.php index d1b1691..20f2212 100644 --- a/src/Header/SecChUaArch.php +++ b/src/Header/SecChUaArch.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaArch implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaBitness.php b/src/Header/SecChUaBitness.php index f6b5501..b56e79c 100644 --- a/src/Header/SecChUaBitness.php +++ b/src/Header/SecChUaBitness.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaBitness implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaFullVersion.php b/src/Header/SecChUaFullVersion.php index 71d8ee6..f694778 100644 --- a/src/Header/SecChUaFullVersion.php +++ b/src/Header/SecChUaFullVersion.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaFullVersion implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return true; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaFullVersionList.php b/src/Header/SecChUaFullVersionList.php index ed99ee0..a194a02 100644 --- a/src/Header/SecChUaFullVersionList.php +++ b/src/Header/SecChUaFullVersionList.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaFullVersionList implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return true; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaMobile.php b/src/Header/SecChUaMobile.php index 28ebc94..02f22c4 100644 --- a/src/Header/SecChUaMobile.php +++ b/src/Header/SecChUaMobile.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaMobile implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaModel.php b/src/Header/SecChUaModel.php index b4af9b4..9f5ccd8 100644 --- a/src/Header/SecChUaModel.php +++ b/src/Header/SecChUaModel.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaModel implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaPlatform.php b/src/Header/SecChUaPlatform.php index 653dbc0..b93a86e 100644 --- a/src/Header/SecChUaPlatform.php +++ b/src/Header/SecChUaPlatform.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaPlatform implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return true; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/SecChUaPlatformVersion.php b/src/Header/SecChUaPlatformVersion.php index ed71fe3..9d2d0d4 100644 --- a/src/Header/SecChUaPlatformVersion.php +++ b/src/Header/SecChUaPlatformVersion.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class SecChUaPlatformVersion implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return true; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/UaOs.php b/src/Header/UaOs.php index 56ed4f1..57de904 100644 --- a/src/Header/UaOs.php +++ b/src/Header/UaOs.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class UaOs implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return true; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/Useragent.php b/src/Header/Useragent.php index 68cb0ae..137d700 100644 --- a/src/Header/Useragent.php +++ b/src/Header/Useragent.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class Useragent implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return true; } + /** @throws void */ public function hasPlatformInfo(): bool { return true; } + /** @throws void */ public function hasEngineInfo(): bool { return true; diff --git a/src/Header/XDeviceUseragent.php b/src/Header/XDeviceUseragent.php index 554b026..c88d788 100644 --- a/src/Header/XDeviceUseragent.php +++ b/src/Header/XDeviceUseragent.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class XDeviceUseragent implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XOperaminiPhone.php b/src/Header/XOperaminiPhone.php index 944c794..8fb1086 100644 --- a/src/Header/XOperaminiPhone.php +++ b/src/Header/XOperaminiPhone.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,36 +17,41 @@ final class XOperaminiPhone implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return !in_array(mb_strtolower($this->value), ['? # ?', 'android #'], true); } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XOperaminiPhoneUa.php b/src/Header/XOperaminiPhoneUa.php index 5a10cbf..9aa7d50 100644 --- a/src/Header/XOperaminiPhoneUa.php +++ b/src/Header/XOperaminiPhoneUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,40 +18,51 @@ final class XOperaminiPhoneUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { if (in_array(mb_strtolower($this->value), ['mozilla/5.0 (bada 2.0.0)', 'motorola'], true)) { return false; } - return (bool) preg_match('/samsung|nokia|blackberry|smartfren|sprint|iphone|lava|gionee|philips|htc|pantech|lg|casio|zte|mi 2sc/i', $this->value); + return (bool) preg_match( + '/samsung|nokia|blackberry|smartfren|sprint|iphone|lava|gionee|philips|htc|pantech|lg|casio|zte|mi 2sc/i', + $this->value, + ); } + /** @throws void */ public function hasBrowserInfo(): bool { return (bool) preg_match('/opera mini/i', $this->value); } + /** @throws void */ public function hasPlatformInfo(): bool { - return (bool) preg_match('/bada|android|blackberry|brew|iphone|mre|windows|mtk/i', $this->value); + return (bool) preg_match( + '/bada|android|blackberry|brew|iphone|mre|windows|mtk/i', + $this->value, + ); } + /** @throws void */ public function hasEngineInfo(): bool { return (bool) preg_match('/trident|presto|webkit|gecko/i', $this->value); diff --git a/src/Header/XOriginalUseragent.php b/src/Header/XOriginalUseragent.php index 50626ee..5c57e1a 100644 --- a/src/Header/XOriginalUseragent.php +++ b/src/Header/XOriginalUseragent.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,36 +14,41 @@ final class XOriginalUseragent implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return true; } + /** @throws void */ public function hasPlatformInfo(): bool { return true; } + /** @throws void */ public function hasEngineInfo(): bool { return true; diff --git a/src/Header/XPuffinUa.php b/src/Header/XPuffinUa.php index 7a1fbdf..4253fc5 100644 --- a/src/Header/XPuffinUa.php +++ b/src/Header/XPuffinUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,36 +16,41 @@ final class XPuffinUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return true; } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return (bool) preg_match('/(?PAndroid|iPhone OS)/', $this->value); } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XRequestedWith.php b/src/Header/XRequestedWith.php index 5ff1447..0454c12 100644 --- a/src/Header/XRequestedWith.php +++ b/src/Header/XRequestedWith.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,36 +16,41 @@ final class XRequestedWith implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return false; } + /** @throws void */ public function hasBrowserInfo(): bool { return 0 >= preg_match('/xmlhttprequest|fake/i', $this->value); } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XUcbrowserDevice.php b/src/Header/XUcbrowserDevice.php index 3b047f5..04c11f5 100644 --- a/src/Header/XUcbrowserDevice.php +++ b/src/Header/XUcbrowserDevice.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,36 +17,41 @@ final class XUcbrowserDevice implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return !in_array(mb_strtolower($this->value), ['j2me', 'opera', 'jblend'], true); } + /** @throws void */ public function hasBrowserInfo(): bool { return false; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XUcbrowserDeviceUa.php b/src/Header/XUcbrowserDeviceUa.php index e978aff..eadf09e 100644 --- a/src/Header/XUcbrowserDeviceUa.php +++ b/src/Header/XUcbrowserDeviceUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,36 +16,47 @@ final class XUcbrowserDeviceUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { - return '?' !== $this->value; + return $this->value !== '?'; } + /** @throws void */ public function hasBrowserInfo(): bool { - return (bool) preg_match('/msie|dorado|safari|obigo|netfront|s40ovibrowser|dolfin|(?value); + return (bool) preg_match( + '/msie|dorado|safari|obigo|netfront|s40ovibrowser|dolfin|(?value, + ); } + /** @throws void */ public function hasPlatformInfo(): bool { - return (bool) preg_match('/bada|android|blackberry|brew|iphone|mre|windows|mtk|symbian|mre/i', $this->value); + return (bool) preg_match( + '/bada|android|blackberry|brew|iphone|mre|windows|mtk|symbian|mre/i', + $this->value, + ); } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XUcbrowserPhone.php b/src/Header/XUcbrowserPhone.php index 8deccfa..7991b3d 100644 --- a/src/Header/XUcbrowserPhone.php +++ b/src/Header/XUcbrowserPhone.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,36 +17,41 @@ final class XUcbrowserPhone implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return !in_array(mb_strtolower($this->value), ['maui browser', 'sunmicro'], true); } + /** @throws void */ public function hasBrowserInfo(): bool { - return 'maui browser' === $this->value; + return $this->value === 'maui browser'; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XUcbrowserPhoneUa.php b/src/Header/XUcbrowserPhoneUa.php index d115ec5..2161486 100644 --- a/src/Header/XUcbrowserPhoneUa.php +++ b/src/Header/XUcbrowserPhoneUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,36 +17,41 @@ final class XUcbrowserPhoneUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { return !in_array(mb_strtolower($this->value), ['maui browser', 'sunmicro'], true); } + /** @throws void */ public function hasBrowserInfo(): bool { - return 'maui browser' === $this->value; + return $this->value === 'maui browser'; } + /** @throws void */ public function hasPlatformInfo(): bool { return false; } + /** @throws void */ public function hasEngineInfo(): bool { return false; diff --git a/src/Header/XUcbrowserUa.php b/src/Header/XUcbrowserUa.php index ed8cb33..77cb0e1 100644 --- a/src/Header/XUcbrowserUa.php +++ b/src/Header/XUcbrowserUa.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,21 +16,23 @@ final class XUcbrowserUa implements HeaderInterface { - private string $value; - - public function __construct(string $value) + /** @throws void */ + public function __construct(private readonly string $value) { - $this->value = $value; + // nothing to do } /** * Retrieve header value + * + * @throws void */ public function getValue(): string { return $this->value; } + /** @throws void */ public function hasDeviceInfo(): bool { $matches = []; @@ -39,14 +41,16 @@ public function hasDeviceInfo(): bool return false; } - return 'j2me' !== $matches['device'] && 'Opera' !== $matches['device']; + return $matches['device'] !== 'j2me' && $matches['device'] !== 'Opera'; } + /** @throws void */ public function hasBrowserInfo(): bool { return (bool) preg_match('/pr\((?P[^\)]+)\);/', $this->value); } + /** @throws void */ public function hasPlatformInfo(): bool { if (preg_match('/ov\((?P[\d_\.]+)\);/', $this->value)) { @@ -56,6 +60,7 @@ public function hasPlatformInfo(): bool return (bool) preg_match('/ov\((?P[^\)]+)\);/', $this->value); } + /** @throws void */ public function hasEngineInfo(): bool { return (bool) preg_match('/re\((?P[^\)]+)\)/', $this->value); diff --git a/src/NotFoundException.php b/src/NotFoundException.php index d8a1db4..7003e50 100644 --- a/src/NotFoundException.php +++ b/src/NotFoundException.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/tests/GenericRequestFactoryTest.php b/tests/GenericRequestFactoryTest.php index 1672cc3..6b2a898 100644 --- a/tests/GenericRequestFactoryTest.php +++ b/tests/GenericRequestFactoryTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -20,7 +20,6 @@ use RecursiveIteratorIterator; use RegexIterator; use RuntimeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Constants; use UaRequest\GenericRequest; use UaRequest\GenericRequestFactory; @@ -41,15 +40,13 @@ final class GenericRequestFactoryTest extends TestCase { private GenericRequestFactory $object; + /** @throws void */ protected function setUp(): void { $this->object = new GenericRequestFactory(); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testCreateRequestFromArray(): void { $userAgent = 'testUA'; @@ -62,10 +59,7 @@ public function testCreateRequestFromArray(): void self::assertSame($userAgent, $result->getBrowserUserAgent()); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testCreateRequestFromEmptyHeaders(): void { $headers = []; @@ -77,10 +71,7 @@ public function testCreateRequestFromEmptyHeaders(): void self::assertSame('', $result->getBrowserUserAgent()); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testCreateRequestFromString(): void { $userAgent = 'testUA'; @@ -93,10 +84,7 @@ public function testCreateRequestFromString(): void self::assertSame($userAgent, $result->getBrowserUserAgent()); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testCreateRequestFromPsr7Message(): void { $userAgent = 'testUA'; @@ -110,7 +98,9 @@ public function testCreateRequestFromPsr7Message(): void Constants::HEADER_UCBROWSER_DEVICE_UA => $deviceUa, ]; - $result = $this->object->createRequestFromPsr7Message(ServerRequestFactory::fromGlobals($headers)); + $result = $this->object->createRequestFromPsr7Message( + ServerRequestFactory::fromGlobals($headers), + ); self::assertInstanceOf(GenericRequest::class, $result); self::assertSame($expectedHeaders, $result->getHeaders()); @@ -118,10 +108,7 @@ public function testCreateRequestFromPsr7Message(): void self::assertSame($deviceUa, $result->getDeviceUserAgent()); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testCreateRequestFromInvalidString(): void { $userAgent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; SQQ52974OEM044059604956O~{โ”ฌยชM~โ”ฌUZUY\nPM)"; @@ -135,10 +122,7 @@ public function testCreateRequestFromInvalidString(): void self::assertSame($resultUa, $result->getBrowserUserAgent()); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testCreateRequestFromInvalidArray(): void { $userAgent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; SQQ52974OEM044059604956O~{โ”ฌยชM~โ”ฌUZUY\nPM)"; @@ -157,13 +141,17 @@ public function testCreateRequestFromInvalidArray(): void /** * @param array $headers * - * @throws InvalidArgumentException * @throws Exception * * @dataProvider providerUa */ - public function testData(array $headers, string $expectedDeviceUa, string $expectedBrowserUa, string $expectedPlatformUa, string $expectedEngineUa): void - { + public function testData( + array $headers, + string $expectedDeviceUa, + string $expectedBrowserUa, + string $expectedPlatformUa, + string $expectedEngineUa, + ): void { $result = $this->object->createRequestFromArray($headers); self::assertInstanceOf(GenericRequest::class, $result); @@ -179,8 +167,9 @@ public function testData(array $headers, string $expectedDeviceUa, string $expec * @phpstan-return array, 1: string, 2: string, 3: string, 4: string}> * * @throws RuntimeException + * @throws UnexpectedValueException */ - public function providerUa(): array + public static function providerUa(): array { $path = 'tests/data'; @@ -200,17 +189,12 @@ public function providerUa(): array assert(is_string($file)); $content = file_get_contents($file); - if (false === $content || '' === $content || PHP_EOL === $content) { + if ($content === false || $content === '' || $content === PHP_EOL) { throw new UnexpectedValueException('empty content'); } try { - $data = json_decode( - $content, - true, - 512, - JSON_THROW_ON_ERROR - ); + $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $e) { throw new UnexpectedValueException('invalid content', 0, $e); } diff --git a/tests/GenericRequestTest.php b/tests/GenericRequestTest.php index cd40627..be8b27b 100644 --- a/tests/GenericRequestTest.php +++ b/tests/GenericRequestTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,7 +16,6 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; use Psr\Http\Message\MessageInterface; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Constants; use UaRequest\GenericRequest; use UaRequest\GenericRequestFactory; @@ -28,10 +27,7 @@ final class GenericRequestTest extends TestCase { - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testConstruct(): void { $userAgent = 'testUA'; @@ -98,12 +94,32 @@ public function testConstruct(): void ->method('hasDeviceInfo') ->willReturn(true); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(3)) + $matcher = self::exactly(3); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_UCBROWSER_UA, $browserUa], [Constants::HEADER_DEVICE_STOCK_UA, $deviceUa], [Constants::HEADER_USERAGENT, $userAgent]) - ->willReturnOnConsecutiveCalls($header1, $header2, $header3); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $browserUa, $deviceUa, $userAgent, $header1, $header2, $header3): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_UCBROWSER_UA, $key), + 2 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_USERAGENT, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($browserUa, $value), + 2 => self::assertSame($deviceUa, $value), + default => self::assertSame($userAgent, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + 2 => $header2, + default => $header3, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $object = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -113,10 +129,7 @@ public function testConstruct(): void self::assertSame($deviceUa, $object->getDeviceUserAgent(), 'device ua mismatch'); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testToarray(): void { $userAgent = 'testUA'; @@ -152,10 +165,7 @@ public function testToarray(): void self::assertSame($expectedHeaders, $object->getHeaders()); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testToarraySimple(): void { $userAgent = 'testUA'; @@ -188,10 +198,7 @@ public function testToarraySimple(): void self::assertSame([Constants::HEADER_USERAGENT => $userAgent], $array); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForDevice(): void { $userAgent = 'testUA'; @@ -224,10 +231,7 @@ public function testForDevice(): void self::assertSame('', $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForDevice2(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -265,12 +269,29 @@ public function testForDevice2(): void $header2->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(2)) + $matcher = self::exactly(2); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_DEVICE_STOCK_UA, $userAgent], [Constants::HEADER_USERAGENT, $userAgent2]) - ->willReturnOnConsecutiveCalls($header1, $header2); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $userAgent, $userAgent2, $header1, $header2): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_USERAGENT, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($userAgent, $value), + default => self::assertSame($userAgent2, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + default => $header2, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -279,10 +300,7 @@ public function testForDevice2(): void self::assertSame($userAgent, $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForBrowser(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -315,10 +333,7 @@ public function testForBrowser(): void self::assertSame('', $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForBrowser2(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -356,12 +371,29 @@ public function testForBrowser2(): void $header2->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(2)) + $matcher = self::exactly(2); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_UCBROWSER_UA, $userAgent2], [Constants::HEADER_DEVICE_STOCK_UA, $userAgent]) - ->willReturnOnConsecutiveCalls($header1, $header2); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $userAgent, $userAgent2, $header1, $header2): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_UCBROWSER_UA, $key), + default => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($userAgent2, $value), + default => self::assertSame($userAgent, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + default => $header2, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -370,10 +402,7 @@ public function testForBrowser2(): void self::assertSame($userAgent2, $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForPlatform(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -407,10 +436,7 @@ public function testForPlatform(): void self::assertSame('', $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForPlatform2(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -448,12 +474,29 @@ public function testForPlatform2(): void $header2->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(2)) + $matcher = self::exactly(2); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_DEVICE_STOCK_UA, $userAgent], [Constants::HEADER_UA_OS, $userAgent2]) - ->willReturnOnConsecutiveCalls($header1, $header2); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $userAgent2, $userAgent, $header1, $header2): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_UA_OS, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($userAgent, $value), + default => self::assertSame($userAgent2, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + default => $header2, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -462,10 +505,7 @@ public function testForPlatform2(): void self::assertSame($userAgent2, $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForEngine(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -499,10 +539,7 @@ public function testForEngine(): void self::assertSame('', $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testForEngine2(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -540,12 +577,29 @@ public function testForEngine2(): void $header2->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(2)) + $matcher = self::exactly(2); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_DEVICE_STOCK_UA, $userAgent], [Constants::HEADER_UA_OS, $userAgent2]) - ->willReturnOnConsecutiveCalls($header1, $header2); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $userAgent2, $userAgent, $header1, $header2): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_UA_OS, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($userAgent, $value), + default => self::assertSame($userAgent2, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + default => $header2, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -554,10 +608,7 @@ public function testForEngine2(): void self::assertSame($userAgent2, $ua); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testGetFilteredHeaders(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -611,12 +662,32 @@ public function testGetFilteredHeaders(): void $header3->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(3)) + $matcher = self::exactly(3); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_UCBROWSER_UA, $browserUa], [Constants::HEADER_DEVICE_STOCK_UA, $deviceUa], [Constants::HEADER_USERAGENT, $userAgent]) - ->willReturn($header1, $header2, $header3); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $browserUa, $deviceUa, $userAgent, $header1, $header2, $header3): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_UCBROWSER_UA, $key), + 2 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_USERAGENT, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($browserUa, $value), + 2 => self::assertSame($deviceUa, $value), + default => self::assertSame($userAgent, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + 2 => $header2, + default => $header3, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -625,10 +696,7 @@ public function testGetFilteredHeaders(): void self::assertSame($expectedHeaders, $resultHeaders); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testGetFilteredHeadersWithLoadException(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -663,10 +731,7 @@ public function testGetFilteredHeadersWithLoadException(): void self::assertSame($expectedHeaders, $resultHeaders); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testGetFilteredHeadersWithLoadException2(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -708,22 +773,32 @@ public function testGetFilteredHeadersWithLoadException2(): void $header2->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->getMock(); - $loader->expects(self::exactly(3)) + $matcher = self::exactly(3); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_UCBROWSER_UA, $browserUa], [Constants::HEADER_DEVICE_STOCK_UA, $deviceUa], [Constants::HEADER_USERAGENT, $userAgent]) - ->willReturnCallback(static function ($headerName) use ($header1, $header2) { - if (Constants::HEADER_UCBROWSER_UA === $headerName) { - return $header1; - } - - if (Constants::HEADER_USERAGENT === $headerName) { - return $header2; - } - - throw new NotFoundException('not-found'); - }); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $browserUa, $deviceUa, $userAgent, $header1, $header2): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_UCBROWSER_UA, $key), + 2 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_USERAGENT, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($browserUa, $value), + 2 => self::assertSame($deviceUa, $value), + default => self::assertSame($userAgent, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + 2 => throw new NotFoundException('not-found'), + default => $header2, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest(ServerRequestFactory::fromGlobals($headers), $loader); @@ -732,10 +807,7 @@ public function testGetFilteredHeadersWithLoadException2(): void self::assertSame($expectedHeaders, $resultHeaders); } - /** - * @throws Exception - * @throws InvalidArgumentException - */ + /** @throws Exception */ public function testGetFilteredHeadersWithLoadException3(): void { $userAgent = 'SAMSUNG-GT-S8500'; @@ -778,23 +850,33 @@ public function testGetFilteredHeadersWithLoadException3(): void $header2->expects(self::never()) ->method('hasDeviceInfo'); - $loader = $this->getMockBuilder(HeaderLoaderInterface::class) + $loader = $this->getMockBuilder(HeaderLoaderInterface::class) ->disableOriginalConstructor() ->getMock(); - $loader->expects(self::exactly(3)) + $matcher = self::exactly(3); + $loader->expects($matcher) ->method('load') - ->withConsecutive([Constants::HEADER_UCBROWSER_UA, $browserUa], [Constants::HEADER_DEVICE_STOCK_UA, $deviceUa], [Constants::HEADER_USERAGENT, $userAgent]) - ->willReturnCallback(static function ($headerName) use ($header1, $header2) { - if (Constants::HEADER_UCBROWSER_UA === $headerName) { - return $header1; - } - - if (Constants::HEADER_USERAGENT === $headerName) { - return $header2; - } - - throw new NotFoundException('not-found'); - }); + ->willReturnCallback( + static function (string $key, string $value) use ($matcher, $browserUa, $deviceUa, $userAgent, $header1, $header2): HeaderInterface { + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame(Constants::HEADER_UCBROWSER_UA, $key), + 2 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $key), + default => self::assertSame(Constants::HEADER_USERAGENT, $key), + }; + + match ($matcher->numberOfInvocations()) { + 1 => self::assertSame($browserUa, $value), + 2 => self::assertSame($deviceUa, $value), + default => self::assertSame($userAgent, $value), + }; + + return match ($matcher->numberOfInvocations()) { + 1 => $header1, + 2 => throw new NotFoundException('not-found'), + default => $header2, + }; + }, + ); $message = $this->getMockBuilder(MessageInterface::class) ->disableOriginalConstructor() @@ -802,10 +884,28 @@ public function testGetFilteredHeadersWithLoadException3(): void $message->expects(self::once()) ->method('getHeaders') ->willReturn($headers); - $message->expects(self::exactly(5)) + $matcher = self::exactly(5); + $message->expects($matcher) ->method('getHeaderLine') - ->withConsecutive([Constants::HEADER_USERAGENT], ['x-unknown-header'], [Constants::HEADER_DEVICE_STOCK_UA], [Constants::HEADER_UCBROWSER_UA], ['via']) - ->willReturnOnConsecutiveCalls($userAgent, 'test', $deviceUa, $browserUa, 'test'); + ->willReturnCallback( + static function (string $name) use ($matcher, $browserUa, $deviceUa, $userAgent): string { + match ($matcher->numberOfInvocations()) { + 2 => self::assertSame('x-unknown-header', $name), + 3 => self::assertSame(Constants::HEADER_DEVICE_STOCK_UA, $name), + 4 => self::assertSame(Constants::HEADER_UCBROWSER_UA, $name), + 5 => self::assertSame('via', $name), + default => self::assertSame(Constants::HEADER_USERAGENT, $name), + }; + + return match ($matcher->numberOfInvocations()) { + 2 => 'test', + 3 => $deviceUa, + 4 => $browserUa, + 5 => 'test', + default => $userAgent, + }; + }, + ); assert($loader instanceof HeaderLoaderInterface); $original = new GenericRequest($message, $loader); diff --git a/tests/Header/BaiduFlyflowTest.php b/tests/Header/BaiduFlyflowTest.php index a844235..3d994ed 100644 --- a/tests/Header/BaiduFlyflowTest.php +++ b/tests/Header/BaiduFlyflowTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\BaiduFlyflow; final class BaiduFlyflowTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo): void /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['Microsoft Windows NT 8.10.14219.0;4.0.30508.0;HUAWEI;HUAWEI W2-U00;4a1b5d7105057f0c0208d83c699276ff92cedbff;2.5.0.12', true], diff --git a/tests/Header/DeviceStockUaTest.php b/tests/Header/DeviceStockUaTest.php index 7058f3b..72e4f94 100644 --- a/tests/Header/DeviceStockUaTest.php +++ b/tests/Header/DeviceStockUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,19 +14,22 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\DeviceStockUa; final class DeviceStockUaTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ - public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, bool $hasPlatformInfo, bool $hasEngineInfo): void - { + public function testData( + string $ua, + bool $hasDeviceInfo, + bool $hasBrowserInfo, + bool $hasPlatformInfo, + bool $hasEngineInfo, + ): void { $header = new DeviceStockUa($ua); self::assertSame($ua, $header->getValue(), 'header mismatch'); @@ -38,8 +41,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S5380D/S5380DZHLB1; U; Bada/2.0; zh-cn) AppleWebKit/534.20 (KHTML, like Gecko) Dolfin/3.0 Mobile HVGA SMM-MMS/1.2.0 OPN-B', true, false, true, true], diff --git a/tests/Header/HeaderLoaderTest.php b/tests/Header/HeaderLoaderTest.php index 02ccdc7..58ced4b 100644 --- a/tests/Header/HeaderLoaderTest.php +++ b/tests/Header/HeaderLoaderTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,6 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Constants; use UaRequest\Header\HeaderInterface; use UaRequest\Header\HeaderLoader; @@ -25,14 +24,13 @@ final class HeaderLoaderTest extends TestCase { private HeaderLoader $subject; + /** @throws void */ protected function setUp(): void { $this->subject = new HeaderLoader(); } - /** - * @throws NotFoundException - */ + /** @throws NotFoundException */ public function testLoadFail(): void { $this->expectException(NotFoundException::class); @@ -43,7 +41,6 @@ public function testLoadFail(): void /** * @throws Exception - * @throws InvalidArgumentException * @throws NotFoundException */ public function testLoadOk(): void @@ -55,10 +52,7 @@ public function testLoadOk(): void self::assertSame($value, $header->getValue()); } - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testHas(): void { self::assertTrue($this->subject->has(Constants::HEADER_USERAGENT)); diff --git a/tests/Header/SecChUaArchTest.php b/tests/Header/SecChUaArchTest.php index 8441761..e3286e2 100644 --- a/tests/Header/SecChUaArchTest.php +++ b/tests/Header/SecChUaArchTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaArch; final class SecChUaArchTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaBitnessTest.php b/tests/Header/SecChUaBitnessTest.php index 58b5b9c..0c33181 100644 --- a/tests/Header/SecChUaBitnessTest.php +++ b/tests/Header/SecChUaBitnessTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaBitness; final class SecChUaBitnessTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaFullVersionListTest.php b/tests/Header/SecChUaFullVersionListTest.php index 81c939c..fe32168 100644 --- a/tests/Header/SecChUaFullVersionListTest.php +++ b/tests/Header/SecChUaFullVersionListTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaFullVersionList; final class SecChUaFullVersionListTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaFullVersionTest.php b/tests/Header/SecChUaFullVersionTest.php index 08c78ab..13b4b58 100644 --- a/tests/Header/SecChUaFullVersionTest.php +++ b/tests/Header/SecChUaFullVersionTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaFullVersion; final class SecChUaFullVersionTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaMobileTest.php b/tests/Header/SecChUaMobileTest.php index e613a89..466d165 100644 --- a/tests/Header/SecChUaMobileTest.php +++ b/tests/Header/SecChUaMobileTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaMobile; final class SecChUaMobileTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaModelTest.php b/tests/Header/SecChUaModelTest.php index a47b064..0098b79 100644 --- a/tests/Header/SecChUaModelTest.php +++ b/tests/Header/SecChUaModelTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaModel; final class SecChUaModelTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaPlatformTest.php b/tests/Header/SecChUaPlatformTest.php index 479ffc6..201727b 100644 --- a/tests/Header/SecChUaPlatformTest.php +++ b/tests/Header/SecChUaPlatformTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaPlatform; final class SecChUaPlatformTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaPlatformVersionTest.php b/tests/Header/SecChUaPlatformVersionTest.php index 2ba6753..ad07a5b 100644 --- a/tests/Header/SecChUaPlatformVersionTest.php +++ b/tests/Header/SecChUaPlatformVersionTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUaPlatformVersion; final class SecChUaPlatformVersionTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/SecChUaTest.php b/tests/Header/SecChUaTest.php index c84c268..762d253 100644 --- a/tests/Header/SecChUaTest.php +++ b/tests/Header/SecChUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\SecChUa; final class SecChUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/UaOsTest.php b/tests/Header/UaOsTest.php index 15c1774..59ab4c1 100644 --- a/tests/Header/UaOsTest.php +++ b/tests/Header/UaOsTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\UaOs; final class UaOsTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/UseragentTest.php b/tests/Header/UseragentTest.php index 988bfe2..26bd1e8 100644 --- a/tests/Header/UseragentTest.php +++ b/tests/Header/UseragentTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\Useragent; final class UseragentTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Windows CE (Smartphone) - Version 5.2'; diff --git a/tests/Header/XDeviceUseragentTest.php b/tests/Header/XDeviceUseragentTest.php index b9ab586..e104f8c 100644 --- a/tests/Header/XDeviceUseragentTest.php +++ b/tests/Header/XDeviceUseragentTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XDeviceUseragent; final class XDeviceUseragentTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo): void /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['Nokia6288/2.0 (05.94) Profile/MIDP-2.0 Configuration/CLDC-1.1', true], diff --git a/tests/Header/XOperaminiPhoneTest.php b/tests/Header/XOperaminiPhoneTest.php index e868854..a367d4d 100644 --- a/tests/Header/XOperaminiPhoneTest.php +++ b/tests/Header/XOperaminiPhoneTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XOperaminiPhone; final class XOperaminiPhoneTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo): void /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['RIM # BlackBerry 8520', true], diff --git a/tests/Header/XOperaminiPhoneUaTest.php b/tests/Header/XOperaminiPhoneUaTest.php index 4e41360..aedae53 100644 --- a/tests/Header/XOperaminiPhoneUaTest.php +++ b/tests/Header/XOperaminiPhoneUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,19 +14,22 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XOperaminiPhoneUa; final class XOperaminiPhoneUaTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ - public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, bool $hasPlatformInfo, bool $hasEngineInfo): void - { + public function testData( + string $ua, + bool $hasDeviceInfo, + bool $hasBrowserInfo, + bool $hasPlatformInfo, + bool $hasEngineInfo, + ): void { $header = new XOperaminiPhoneUa($ua); self::assertSame($ua, $header->getValue(), 'header mismatch'); @@ -38,8 +41,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['BlackBerry8520/5.0.0.681 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/613', true, false, true, false], diff --git a/tests/Header/XOriginalUseragentTest.php b/tests/Header/XOriginalUseragentTest.php index 27ba56c..568e7c3 100644 --- a/tests/Header/XOriginalUseragentTest.php +++ b/tests/Header/XOriginalUseragentTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,15 +14,11 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XOriginalUseragent; final class XOriginalUseragentTest extends TestCase { - /** - * @throws ExpectationFailedException - * @throws InvalidArgumentException - */ + /** @throws ExpectationFailedException */ public function testData(): void { $ua = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3'; diff --git a/tests/Header/XPuffinUaTest.php b/tests/Header/XPuffinUaTest.php index 7a28dcd..53f2d61 100644 --- a/tests/Header/XPuffinUaTest.php +++ b/tests/Header/XPuffinUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XPuffinUa; final class XPuffinUaTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasPlatformInfo) /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['iPhone OS/iPad4,1/1536x2048', true, true], diff --git a/tests/Header/XRequestedWithTest.php b/tests/Header/XRequestedWithTest.php index 68d7618..2b15b79 100644 --- a/tests/Header/XRequestedWithTest.php +++ b/tests/Header/XRequestedWithTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XRequestedWith; final class XRequestedWithTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasBrowserInfo): void /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['com.browser2345', true], diff --git a/tests/Header/XUcbrowserDeviceTest.php b/tests/Header/XUcbrowserDeviceTest.php index 9d38990..f1fce0c 100644 --- a/tests/Header/XUcbrowserDeviceTest.php +++ b/tests/Header/XUcbrowserDeviceTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XUcbrowserDevice; final class XUcbrowserDeviceTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo): void /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['nokia#200', true], diff --git a/tests/Header/XUcbrowserDeviceUaTest.php b/tests/Header/XUcbrowserDeviceUaTest.php index 0ca98b2..259b11b 100644 --- a/tests/Header/XUcbrowserDeviceUaTest.php +++ b/tests/Header/XUcbrowserDeviceUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XUcbrowserDeviceUa; final class XUcbrowserDeviceUaTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['Mozilla/5.0 (Linux; U; Android 2.3.5; en-US; Micromax_A36 Build/MocorDroid2.3.5_Trout) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1', true, true, true], diff --git a/tests/Header/XUcbrowserPhoneTest.php b/tests/Header/XUcbrowserPhoneTest.php index a4994ed..b4cdfb9 100644 --- a/tests/Header/XUcbrowserPhoneTest.php +++ b/tests/Header/XUcbrowserPhoneTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XUcbrowserPhone; final class XUcbrowserPhoneTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo): /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['maui browser', false, true], diff --git a/tests/Header/XUcbrowserPhoneUaTest.php b/tests/Header/XUcbrowserPhoneUaTest.php index 0c22feb..2d89cf7 100644 --- a/tests/Header/XUcbrowserPhoneUaTest.php +++ b/tests/Header/XUcbrowserPhoneUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,14 +14,12 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XUcbrowserPhoneUa; final class XUcbrowserPhoneUaTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ @@ -38,8 +36,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo): /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['maui browser', false, true], diff --git a/tests/Header/XUcbrowserUaTest.php b/tests/Header/XUcbrowserUaTest.php index ed44287..393b5bd 100644 --- a/tests/Header/XUcbrowserUaTest.php +++ b/tests/Header/XUcbrowserUaTest.php @@ -2,7 +2,7 @@ /** * This file is part of the ua-generic-request package. * - * Copyright (c) 2015-2021, Thomas Mueller + * Copyright (c) 2015-2023, Thomas Mueller * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,19 +14,22 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use UaRequest\Header\XUcbrowserUa; final class XUcbrowserUaTest extends TestCase { /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * * @dataProvider providerUa */ - public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, bool $hasPlatformInfo, bool $hasEngineInfo): void - { + public function testData( + string $ua, + bool $hasDeviceInfo, + bool $hasBrowserInfo, + bool $hasPlatformInfo, + bool $hasEngineInfo, + ): void { $header = new XUcbrowserUa($ua); self::assertSame($ua, $header->getValue(), 'header mismatch'); @@ -38,8 +41,10 @@ public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, /** * @return array> + * + * @throws void */ - public function providerUa(): array + public static function providerUa(): array { return [ ['pf(Linux);la(en-US);re(AppleWebKit/534.31 (KHTML, like Gecko));dv(Lenovo A369i Build/JDQ39);pr(UCBrowser/9.1.0.297);ov(Android 4.2.2);pi(480*762);ss(480*762);up(U3/0.8.0);er(U);bt(GZ);pm(1);bv(1);nm(0);im(0);sr(0);nt(3);', true, true, true, true], From 3610ef3832c5f82b13a10c71e62990e3cf19fb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 4 Jul 2023 22:20:44 +0200 Subject: [PATCH 4/4] fix issues --- tests/GenericRequestFactoryTest.php | 4 ++-- tests/Header/BaiduFlyflowTest.php | 8 +++----- tests/Header/DeviceStockUaTest.php | 8 +++----- tests/Header/XDeviceUseragentTest.php | 8 +++----- tests/Header/XOperaminiPhoneTest.php | 8 +++----- tests/Header/XOperaminiPhoneUaTest.php | 8 +++----- tests/Header/XPuffinUaTest.php | 8 +++----- tests/Header/XRequestedWithTest.php | 8 +++----- tests/Header/XUcbrowserDeviceTest.php | 8 +++----- tests/Header/XUcbrowserDeviceUaTest.php | 8 +++----- tests/Header/XUcbrowserPhoneTest.php | 8 +++----- tests/Header/XUcbrowserPhoneUaTest.php | 8 +++----- tests/Header/XUcbrowserUaTest.php | 8 +++----- 13 files changed, 38 insertions(+), 62 deletions(-) diff --git a/tests/GenericRequestFactoryTest.php b/tests/GenericRequestFactoryTest.php index 6b2a898..5084f98 100644 --- a/tests/GenericRequestFactoryTest.php +++ b/tests/GenericRequestFactoryTest.php @@ -14,6 +14,7 @@ use JsonException; use Laminas\Diactoros\ServerRequestFactory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; use RecursiveDirectoryIterator; @@ -142,9 +143,8 @@ public function testCreateRequestFromInvalidArray(): void * @param array $headers * * @throws Exception - * - * @dataProvider providerUa */ + #[DataProvider('providerUa')] public function testData( array $headers, string $expectedDeviceUa, diff --git a/tests/Header/BaiduFlyflowTest.php b/tests/Header/BaiduFlyflowTest.php index 3d994ed..4431a34 100644 --- a/tests/Header/BaiduFlyflowTest.php +++ b/tests/Header/BaiduFlyflowTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\BaiduFlyflow; final class BaiduFlyflowTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo): void { $header = new BaiduFlyflow($ua); diff --git a/tests/Header/DeviceStockUaTest.php b/tests/Header/DeviceStockUaTest.php index 72e4f94..e4277a7 100644 --- a/tests/Header/DeviceStockUaTest.php +++ b/tests/Header/DeviceStockUaTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\DeviceStockUa; final class DeviceStockUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData( string $ua, bool $hasDeviceInfo, diff --git a/tests/Header/XDeviceUseragentTest.php b/tests/Header/XDeviceUseragentTest.php index e104f8c..b84d954 100644 --- a/tests/Header/XDeviceUseragentTest.php +++ b/tests/Header/XDeviceUseragentTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XDeviceUseragent; final class XDeviceUseragentTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo): void { $header = new XDeviceUseragent($ua); diff --git a/tests/Header/XOperaminiPhoneTest.php b/tests/Header/XOperaminiPhoneTest.php index a367d4d..15b2837 100644 --- a/tests/Header/XOperaminiPhoneTest.php +++ b/tests/Header/XOperaminiPhoneTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XOperaminiPhone; final class XOperaminiPhoneTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo): void { $header = new XOperaminiPhone($ua); diff --git a/tests/Header/XOperaminiPhoneUaTest.php b/tests/Header/XOperaminiPhoneUaTest.php index aedae53..d528798 100644 --- a/tests/Header/XOperaminiPhoneUaTest.php +++ b/tests/Header/XOperaminiPhoneUaTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XOperaminiPhoneUa; final class XOperaminiPhoneUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData( string $ua, bool $hasDeviceInfo, diff --git a/tests/Header/XPuffinUaTest.php b/tests/Header/XPuffinUaTest.php index 53f2d61..e5327ad 100644 --- a/tests/Header/XPuffinUaTest.php +++ b/tests/Header/XPuffinUaTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XPuffinUa; final class XPuffinUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo, bool $hasPlatformInfo): void { $header = new XPuffinUa($ua); diff --git a/tests/Header/XRequestedWithTest.php b/tests/Header/XRequestedWithTest.php index 2b15b79..3ca6747 100644 --- a/tests/Header/XRequestedWithTest.php +++ b/tests/Header/XRequestedWithTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XRequestedWith; final class XRequestedWithTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasBrowserInfo): void { $header = new XRequestedWith($ua); diff --git a/tests/Header/XUcbrowserDeviceTest.php b/tests/Header/XUcbrowserDeviceTest.php index f1fce0c..52a2bdd 100644 --- a/tests/Header/XUcbrowserDeviceTest.php +++ b/tests/Header/XUcbrowserDeviceTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XUcbrowserDevice; final class XUcbrowserDeviceTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo): void { $header = new XUcbrowserDevice($ua); diff --git a/tests/Header/XUcbrowserDeviceUaTest.php b/tests/Header/XUcbrowserDeviceUaTest.php index 259b11b..2e112b7 100644 --- a/tests/Header/XUcbrowserDeviceUaTest.php +++ b/tests/Header/XUcbrowserDeviceUaTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XUcbrowserDeviceUa; final class XUcbrowserDeviceUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo, bool $hasPlatformInfo): void { $header = new XUcbrowserDeviceUa($ua); diff --git a/tests/Header/XUcbrowserPhoneTest.php b/tests/Header/XUcbrowserPhoneTest.php index b4cdfb9..9769732 100644 --- a/tests/Header/XUcbrowserPhoneTest.php +++ b/tests/Header/XUcbrowserPhoneTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XUcbrowserPhone; final class XUcbrowserPhoneTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo): void { $header = new XUcbrowserPhone($ua); diff --git a/tests/Header/XUcbrowserPhoneUaTest.php b/tests/Header/XUcbrowserPhoneUaTest.php index 2d89cf7..8dcd973 100644 --- a/tests/Header/XUcbrowserPhoneUaTest.php +++ b/tests/Header/XUcbrowserPhoneUaTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XUcbrowserPhoneUa; final class XUcbrowserPhoneUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData(string $ua, bool $hasDeviceInfo, bool $hasBrowserInfo): void { $header = new XUcbrowserPhoneUa($ua); diff --git a/tests/Header/XUcbrowserUaTest.php b/tests/Header/XUcbrowserUaTest.php index 393b5bd..100570b 100644 --- a/tests/Header/XUcbrowserUaTest.php +++ b/tests/Header/XUcbrowserUaTest.php @@ -12,17 +12,15 @@ namespace UaRequestTest\Header; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use UaRequest\Header\XUcbrowserUa; final class XUcbrowserUaTest extends TestCase { - /** - * @throws ExpectationFailedException - * - * @dataProvider providerUa - */ + /** @throws ExpectationFailedException */ + #[DataProvider('providerUa')] public function testData( string $ua, bool $hasDeviceInfo,