diff --git a/.github/workflows/latest.yml b/.github/workflows/latest.yml new file mode 100644 index 0000000..86881a8 --- /dev/null +++ b/.github/workflows/latest.yml @@ -0,0 +1,59 @@ +name: Latest + +# Triggers the workflow on push or pull request events +on: [push, pull_request] + +jobs: + matrix-build: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php-version: [7.4, 8.0] + laravel-version: [8.28] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php-version }} + + - name: Composer update + run: composer self-update >/dev/null 2>&1 + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Lock laravel/framework version + env: + LARAVEL_VERSION: ${{ matrix.laravel-version }} + run: composer require laravel/framework:${{ matrix.laravel-version }} --no-update + + - name: Vendor update + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer update --prefer-source --no-interaction + + - name: Run test suites + run: composer run-script test + + - name: Analyze + run: vendor/bin/phpstan analyse -c phpstan.neon ./src/ + + - name: phpcs + run: php vendor/bin/phpcs --standard=PSR12 ./src/ + + - name: Coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: php vendor/bin/php-coveralls -v \ No newline at end of file diff --git a/.github/workflows/test-php7.yml b/.github/workflows/test-php7.yml new file mode 100644 index 0000000..12cefb0 --- /dev/null +++ b/.github/workflows/test-php7.yml @@ -0,0 +1,79 @@ +name: PHP7 + +# Manual run +on: workflow_dispatch + +jobs: + matrix-build: + # Ubuntu latest will be ubuntu-20.04 which doesn't support php 7.3 + runs-on: ubuntu-18.04 + + strategy: + fail-fast: false + matrix: + php-version: [7.3] + laravel-version: + [ + 6.2, + 6.4, + 6.5, + 6.8, + 6.12, + 6.18, + 6.19, + 6.20.0, + 7.0, + 7.3, + 7.6, + 7.12, + 7.25, + 7.28, + 7.29, + 7.30.1, + 8.0, + 8.12, + 8.13, + 8.14, + 8.15, + 8.16, + 8.17, + 8.18, + 8.19, + 8.20.1, + 8.21, + 8.22, + 8.23, + 8.24, + 8.25, + 8.26, + 8.27, + 8.28, + ] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php-version }} + + - name: Composer update + run: composer self-update >/dev/null 2>&1 + + - name: Lock laravel/framework version + env: + LARAVEL_VERSION: ${{ matrix.laravel-version }} + run: composer require laravel/framework:${{ matrix.laravel-version }} --no-update + + - name: Vendor update + run: composer update --prefer-source --no-interaction + + - name: Run test suites + run: composer run-script test + + - name: Analyze + run: vendor/bin/phpstan analyse -c phpstan.neon ./src/ + + - name: phpcs + run: php vendor/bin/phpcs --standard=PSR12 ./src/ diff --git a/.github/workflows/test-php8.yml b/.github/workflows/test-php8.yml new file mode 100644 index 0000000..e22cec7 --- /dev/null +++ b/.github/workflows/test-php8.yml @@ -0,0 +1,65 @@ +name: PHP8 + +# Manual run +on: workflow_dispatch + +jobs: + matrix-build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php-version: [8.0] + # these versions supports php8 in their composer.json + laravel-version: + [ + 6.20.0, + 7.29, + 7.30.1, + 8.12, + 8.13, + 8.14, + 8.15, + 8.16, + 8.17, + 8.18, + 8.19, + 8.20.1, + 8.21, + 8.22, + 8.23, + 8.24, + 8.25, + 8.26, + 8.27, + 8.28, + ] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php-version }} + + - name: Composer update + run: composer self-update >/dev/null 2>&1 + + - name: Lock laravel/framework version + env: + LARAVEL_VERSION: ${{ matrix.laravel-version }} + run: composer require laravel/framework:${{ matrix.laravel-version }} --no-update + + - name: Vendor update + run: composer update --prefer-source --no-interaction + + - name: Run test suites + run: composer run-script test + + - name: Analyze + run: vendor/bin/phpstan analyse -c phpstan.neon ./src/ + + - name: phpcs + run: php vendor/bin/phpcs --standard=PSR12 ./src/ diff --git a/.travis.yml b/.travis.yml index 48521d7..a18d615 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php php: - 7.3 + - 8.0 env: - LARAVEL_VERSION=6.2 @@ -9,6 +10,20 @@ env: - LARAVEL_VERSION=6.4 - LARAVEL_VERSION=6.5 - LARAVEL_VERSION=7.0 + - LARAVEL_VERSION=8.0 + +matrix: + exclude: + - php: 8.0 + env: LARAVEL_VERSION=6.2 + - php: 8.0 + env: LARAVEL_VERSION=6.3 + - php: 8.0 + env: LARAVEL_VERSION=6.4 + - php: 8.0 + env: LARAVEL_VERSION=6.5 + - php: 8.0 + env: LARAVEL_VERSION=7.0 before_install: - composer self-update >/dev/null 2>&1 @@ -19,9 +34,9 @@ install: composer update --prefer-source --no-interaction script: composer run-script test after_success: - - "if [ $LARAVEL_VERSION = '7.0' ]; then vendor/bin/phpstan analyse -c phpstan.neon ./src/; fi" - - "if [ $LARAVEL_VERSION = '7.0' ]; then php vendor/bin/phpcs --standard=PSR12 ./src/; fi" - - "if [ $LARAVEL_VERSION = '7.0' ]; then php vendor/bin/coveralls -v; fi" + - "if [ $LARAVEL_VERSION = '8.0' ]; then vendor/bin/phpstan analyse -c phpstan.neon ./src/; fi" + - "if [ $LARAVEL_VERSION = '8.0' ]; then php vendor/bin/phpcs --standard=PSR12 ./src/; fi" + - "if [ $LARAVEL_VERSION = '8.0' ]; then php vendor/bin/coveralls -v; fi" notifications: email: diff --git a/CHANGELOG.md b/CHANGELOG.md index 4927e27..637d9f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### Changes in 4.4.0 + +--- + +- Support for Laravel 8.x +- Support for PHP 8.x +- New github actions tests to cover an even bigger test matrix +- Fixes some PHPStan testing issue + ### Changes in 4.3.0 --- diff --git a/README.md b/README.md index 9d2f0c2..48a8f0a 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -## Browser Detection v4.3 by _[hisorange](https://hisorange.me)_ +## Browser Detection v4.4 by _[hisorange](https://hisorange.me)_ [![Latest Stable Version](https://poser.pugx.org/hisorange/browser-detect/v/stable)](https://packagist.org/packages/hisorange/browser-detect) -[![Build Status](https://travis-ci.org/hisorange/browser-detect.svg?branch=stable)](https://travis-ci.org/hisorange/browser-detect) +[![Build](https://github.com/hisorange/browser-detect/actions/workflows/latest.yml/badge.svg?branch=stable)](https://github.com/hisorange/browser-detect/actions/workflows/latest.yml) [![Coverage Status](https://coveralls.io/repos/github/hisorange/browser-detect/badge.svg)](https://coveralls.io/github/hisorange/browser-detect) [![Total Downloads](https://poser.pugx.org/hisorange/browser-detect/downloads)](https://packagist.org/packages/hisorange/browser-detect) [![License](https://poser.pugx.org/hisorange/browser-detect/license)](https://packagist.org/packages/hisorange/browser-detect) Easy to use package to identify the visitor's browser details and device type. Magic is **not** involved the results are generated by multiple well tested and developed packages. -Supporting **every laravel** version between **4.0 » 7.0**, also tested on **every PHP** version between **5.6 » 7.3**. +Supporting **every laravel** version between **4.0 » 8.0**, also tested on **every PHP** version between **5.6 » 8.0**. ### How to install @@ -81,7 +81,7 @@ Easy peasy, ain't it? --- -The following matrix is has been continuously tested by the great and awesome [Travis CI](https://travis-ci.org/hisorange)! +The following matrix is has been continuously tested by the great and awesome **Github Actions**! | ----- | Browser Detect 1.x | Browser Detect 2.x | Browser Detect 3.x | Browser Detect 4.x | | :---------: | :----------------: | :----------------: | :----------------: | :----------------: | @@ -89,6 +89,7 @@ The following matrix is has been continuously tested by the great and awesome [T | Laravel 5.x | - | ✓ | ✓ | - | | Laravel 6.x | - | - | - | ✓ | | Laravel 7.x | - | - | - | ✓ | +| Laravel 8.x | - | - | - | 4.4+ | | Standalone | - | - | - | 4.2+ | Since 2013 the package runs tests on every possible PHP / Laravel version matrix. @@ -217,6 +218,10 @@ with new Laravel and PHP versions, but not planning to do any new features. Thank You for your support over the years, and worry not, the library is stable, and has all the features You ever need. +~ Update on this :D + +No major features are added in the past months, but with the help of [Raymund Ács](https://github.com/PoOwAa) we are patching and continuing the support for micro features and version ports. + ### Changelog --- diff --git a/composer.json b/composer.json index 676b00a..01264a9 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,14 @@ "email": "hello@hisorange.me" } ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/mustangostang/spyc" + } + ], "require": { - "php": ">=7.2", + "php": "^7.2 || ^8.0", "ua-parser/uap-php": "~3.9", "league/pipeline": "^1.0", "mobiledetect/mobiledetectlib": "~2.8", @@ -31,8 +37,8 @@ "matomo/device-detector": "^4.0" }, "require-dev": { - "phpunit/phpunit": "~5.0 || ~6.0 || ~7.0 || ~8.0", - "orchestra/testbench": "~4.0 || ~5.0", + "phpunit/phpunit": "~5.0 || ~6.0 || ~7.0 || ~8.0 || ~9.0", + "orchestra/testbench": "~4.0 || ~5.0 || ~6.0", "php-coveralls/php-coveralls": "~1.0 || ~2.0", "squizlabs/php_codesniffer": "^3.5", "phpstan/phpstan": "^0.12.11" @@ -62,4 +68,4 @@ "test-dev": "phpunit --coverage-text", "test": "phpunit --coverage-clover ./tests/logs/clover.xml" } -} +} \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index d2fdb11..54ef2ec 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,5 +4,4 @@ parameters: checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false ignoreErrors: - - '%Call to an undefined method Illuminate\\\Cache\\\CacheManager::remember\(\).%' - - '%Parameter #1 \$function of function call_user_func_array expects callable\(\)\: mixed, array\(hisorange\\BrowserDetect\\Contracts\\ResultInterface, string\) given\.%' \ No newline at end of file + - '%Call to an undefined method Illuminate\\\Cache\\\CacheManager::remember\(\).%' \ No newline at end of file diff --git a/src/Parser.php b/src/Parser.php index 64c016b..58459d7 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -15,7 +15,7 @@ * * @package hisorange\BrowserDetect */ -class Parser implements ParserInterface +final class Parser implements ParserInterface { /** * @var CacheManager|null @@ -44,7 +44,7 @@ class Parser implements ParserInterface /** * Singleton used in standalone mode. * - * @var self + * @var self|null */ protected static $instance; @@ -58,19 +58,11 @@ class Parser implements ParserInterface public function __construct($cache = null, $request = null, array $config = []) { if ($cache !== null) { - if ($cache instanceof CacheManager) { - $this->cache = $cache; - } else { - throw new InvalidArgumentException('Invalid cache manager instance!'); - } + $this->cache = $cache; } if ($request !== null) { - if ($request instanceof Request) { - $this->request = $request; - } else { - throw new InvalidArgumentException('Invalid request instance!'); - } + $this->request = $request; } $this->config = array_replace_recursive( @@ -107,6 +99,7 @@ public function __call(string $method, array $params) // Reflect a method. if (method_exists($result, $method)) { + /* @phpstan-ignore-next-line */ return call_user_func_array([$result, $method], $params); } @@ -129,6 +122,7 @@ public static function __callStatic(string $method, array $params) static::$instance = new static(); } + /* @phpstan-ignore-next-line */ return call_user_func_array([static::$instance, $method], $params); } @@ -208,7 +202,7 @@ protected function makeHashKey(string $agent): string */ protected function process(string $agent): ResultInterface { - return (new Pipeline) + return (new Pipeline()) ->pipe(new Stages\UAParser()) ->pipe(new Stages\MobileDetect()) ->pipe(new Stages\CrawlerDetect()) diff --git a/src/Stages/BrowserDetect.php b/src/Stages/BrowserDetect.php index bd14117..125a493 100644 --- a/src/Stages/BrowserDetect.php +++ b/src/Stages/BrowserDetect.php @@ -122,8 +122,12 @@ public function __invoke(PayloadInterface $payload): ResultInterface * @param PayloadInterface $payload * @return bool */ - protected function detectIsInApp(PayloadInterface $payload): bool { - return preg_match('%(WebView|(iPhone|iPod|iPad)(?!.*Safari\/)|Android.*(wv|\.0\.0\.0))%', $payload->getAgent()); + protected function detectIsInApp(PayloadInterface $payload): bool + { + return (bool) preg_match( + '%(WebView|(iPhone|iPod|iPad)(?!.*Safari\/)|Android.*(wv|\.0\.0\.0))%', + $payload->getAgent() + ); } /** diff --git a/tests/ParserTest.php b/tests/ParserTest.php index f47b852..929f16a 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -52,26 +52,6 @@ public function testStandaloneConstruct() $this->assertInstanceOf(ResultInterface::class, (new Parser())->parse('test')); } - /** - * @covers ::__construct() - */ - public function testBadCacheProvider() - { - $this->expectException(InvalidArgumentException::class); - - new Parser("invalid"); - } - - /** - * @covers ::__construct() - */ - public function testBadRequestProvider() - { - $this->expectException(InvalidArgumentException::class); - - new Parser(null, "invalid"); - } - /** * @covers ::__callStatic() * @covers ::getUserAgentString()