Skip to content

Commit

Permalink
Remove MobileDetectorInterface and modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
tattali committed Dec 20, 2024
1 parent adc72c0 commit 08e9a71
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 723 deletions.
110 changes: 48 additions & 62 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,90 +14,76 @@ on:
workflow_dispatch:

jobs:
phpunit:
name: Test on PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony-require }}
tests:
environment: main
runs-on: ubuntu-latest
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-require }}

strategy:
fail-fast: false
matrix:
php:
- 8.2
dependencies:
- highest
stability:
- stable
symfony-require:
# Test latest stable version
- 7.*
php: ['8.2']
stability: [prefer-stable]
minimum-stability: [stable]
symfony-version: [7.0.*]
is-current: [true]
include:
- php: '8.3'
symfony-version: 7.0.*
stability: prefer-stable
- php: '8.4'
symfony-version: 7.0.*
stability: prefer-stable

name: PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony-require }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP with PCOV
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: composer-packages-${{ hashFiles('composer.lock') }}

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov
ini-values: zend.assertions=1
coverage: xdebug

- name: Globally install symfony/flex
- name: Install dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins symfony/flex
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins symfony/flex
composer config minimum-stability ${{ matrix.minimum-stability }}
composer update --no-interaction --prefer-dist
- name: Configure minimum stability of dependencies
run: composer config minimum-stability ${{ matrix.stability }}
- name: PHP-CS-Fixer
continue-on-error: ${{ !matrix.is-current }}
run: vendor/bin/php-cs-fixer fix --dry-run --ansi -vvv

- name: Install dependencies with Composer
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: --prefer-dist
- name: PHP_CodeSniffer
continue-on-error: ${{ !matrix.is-current }}
run: vendor/bin/phpcs --report=code

- name: Lint via PHP Coding Standards Fixer and PHP_CodeSniffer
run: |
vendor/bin/php-cs-fixer fix --dry-run --diff --ansi -vvv
vendor/bin/phpcs --report=code
- name: Static Analysis via PHPStan
run: vendor/bin/phpstan analyse
- name: PHPStan
continue-on-error: ${{ !matrix.is-current }}
run: vendor/bin/phpstan analyse src tests --level 9

- name: Unit and Feature tests via PHPUnit
run: php vendor/bin/phpunit
env:
SYMFONY_DEPRECATIONS_HELPER: weak
run: vendor/bin/phpunit

- name: Upload coverage file
uses: actions/upload-artifact@v3
with:
name: phpunit-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}.coverage
path: build/coverage.xml
- name: SonarCloud Scan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
uses: sonarsource/sonarcloud-github-action@v2

- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true

upload_coverage:
name: Upload coverage to Codecov
runs-on: ubuntu-latest
needs:
- phpunit

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download coverage files
uses: actions/download-artifact@v3
with:
path: reports

- name: Upload to Codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v2
with:
directory: reports
File renamed without changes.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"twig/twig": "^3.14"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"friendsofphp/php-cs-fixer": "^3.65",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-nette": "^1.3",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.4",
"squizlabs/php_codesniffer": "^3.10",
"symfony/dotenv": "^7.1",
Expand Down
4 changes: 2 additions & 2 deletions src/DataCollector/DeviceDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(DeviceView $deviceView)
public function collect(
Request $request,
Response $response,
?\Throwable $exception = null
?\Throwable $exception = null,
): void {
$this->data['currentView'] = $this->deviceView->getViewType();
$this->data['views'] = [
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function canUseView(string $view, ?string $host): bool

private function generateSwitchLink(
Request $request,
string $view
string $view,
): ?string {
$requestSwitchView = $request->duplicate();
$requestSwitchView->query->set($this->deviceView->getSwitchParam(), $view);
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/MobileDetectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;

class MobileDetectExtension extends Extension
{
Expand Down
22 changes: 0 additions & 22 deletions src/DeviceDetector/MobileDetector.php

This file was deleted.

Loading

0 comments on commit 08e9a71

Please sign in to comment.