Skip to content

Commit

Permalink
Release 7.x (#35)
Browse files Browse the repository at this point in the history
* Update composer.json

Update composer.json to mobiledetectlib 4.8

* Update MobileDetector.php

Update MobileDetector.php to mobiledetectlib 4.8

* Update MobileDetectorInterface.php

update compatibility

* Update README.md

* Update composer.json

* Update composer.json

* docs should reflect Symfony 7

Arguably, that first line should match the description (Symfony 5.4-7.0).  

But arguably anyone using unmaintained versions of Symfony could go back to the original bundle this was forked from.

* chore: fix ci deprecations

* Update composer.json

* Update MobileDetectExtension.php

* Update DeviceView.php

* Update DeviceDataCollector.php

* Remove MobileDetectorInterface and modernize code

* Upgrade PHPStan from level 1 to level 7

* Fix yaml error

* Remove prefer-dist

* Explicitly add symfony/http-kernel

* Explicitly add dependencies

* Update github actions

* Update github actions

* Update github actions

* Update github actions

* PHPUnit config file

* Move license to root folder

* Rename full to desktop

* desktopViewUrl had too many return 3 allowed

* Update image

* Update image

* Update image

* Add migration guide

---------

Co-authored-by: xpanel <[email protected]>
Co-authored-by: Tac Tacelosky <[email protected]>
Co-authored-by: chris <[email protected]>
  • Loading branch information
4 people authored Dec 27, 2024
1 parent b335b89 commit ef03cf9
Show file tree
Hide file tree
Showing 29 changed files with 575 additions and 1,234 deletions.
112 changes: 49 additions & 63 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.2.*]
is-current: [true]
include:
- php: '8.3'
symfony-version: 7.2.*
stability: prefer-stable
- php: '8.4'
symfony-version: 7.2.*
stability: prefer-stable

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

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

- name: Install PHP with PCOV
- 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
- name: Configure minimum stability of dependencies
run: composer config minimum-stability ${{ matrix.stability }}
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: Install dependencies with Composer
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: --prefer-dist
- name: PHP-CS-Fixer
continue-on-error: ${{ !matrix.is-current }}
run: vendor/bin/php-cs-fixer fix --dry-run --ansi -vvv

- 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: PHP_CodeSniffer
continue-on-error: ${{ !matrix.is-current }}
run: 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 7

- 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@v3

- 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
33 changes: 7 additions & 26 deletions .php-cs-fixer.dist.php → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,13 @@
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PhpCsFixer:risky' => true,
'@PhpCsFixer' => true,
'@PHPUnit84Migration:risky' => true,
'@PSR1' => true,
'@PSR12:risky' => true,
'@PSR12' => true,
'@PSR2' => true,
'@Symfony:risky' => true,
'@PER-CS:risky' => true,
'@PER-CS' => true,
'@PHP82Migration:risky' => true,
'@PHP84Migration' => true,
'@PHPUnit100Migration:risky' => true,
'@Symfony' => true,
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short',
],
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'linebreak_after_opening_tag' => true,
'list_syntax' => [
'syntax' => 'short',
],
'@Symfony:risky' => true,
'no_extra_blank_lines' => [
'tokens' => [
'break',
Expand All @@ -48,7 +30,6 @@
'use',
],
],
'no_superfluous_phpdoc_tags' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
Expand All @@ -68,7 +49,7 @@
'single_line_comment_style' => true,
'strict_comparison' => true,
'strict_param' => true,
'void_return' => false,
'php_unit_test_class_requires_covers' => false,
])
->setFinder($finder)
;
File renamed without changes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
all: test

phpunit:
php vendor/bin/phpunit
XDEBUG_MODE=coverage | php vendor/bin/phpunit --display-phpunit-deprecations

lint:
php vendor/bin/php-cs-fixer fix --diff
php vendor/bin/phpcs --report=code
php vendor/bin/phpstan analyse
php vendor/bin/phpstan analyse src tests --level 7 --memory-limit=-1

test: lint phpunit
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
MobileDetectBundle
==================

Symfony 3.4.x-6.0.x bundle to detect mobile devices, manage mobile view and redirect to the mobile and tablet version.
Symfony 5.4.x-7.0 bundle to detect mobile devices, manage mobile view and redirect to the mobile and tablet version.

[![Github Actions Status](https://github.com/tattali/MobileDetectBundle/actions/workflows/main.yml/badge.svg?branch=main
)](https://github.com/tattali/MobileDetectBundle/actions/workflows/main.yml?query=branch%3Amain) [![Latest Stable Version](http://poser.pugx.org/tattali/mobile-detect-bundle/v)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![Total Downloads](http://poser.pugx.org/tattali/mobile-detect-bundle/downloads)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![codecov](https://codecov.io/gh/tattali/MobileDetectBundle/branch/main/graph/badge.svg?token=HWV1OYRSD9)](https://codecov.io/gh/tattali/MobileDetectBundle) [![License](http://poser.pugx.org/tattali/mobile-detect-bundle/license)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![PHP Version Require](http://poser.pugx.org/tattali/mobile-detect-bundle/require/php)](https://packagist.org/packages/tattali/mobile-detect-bundle)
)](https://github.com/tattali/MobileDetectBundle/actions/workflows/main.yml?query=branch%3Amain) [![Latest Stable Version](https://poser.pugx.org/tattali/mobile-detect-bundle/v)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![Total Downloads](https://poser.pugx.org/tattali/mobile-detect-bundle/downloads)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=tattali_MobileDetectBundle&metric=coverage)](https://sonarcloud.io/summary/new_code?id=tattali_MobileDetectBundle) [![License](https://poser.pugx.org/tattali/mobile-detect-bundle/license)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![PHP Version Require](https://poser.pugx.org/tattali/mobile-detect-bundle/require/php)](https://packagist.org/packages/tattali/mobile-detect-bundle)

*This bundle is a fork of [suncat2000/MobileDetectBundle](https://github.com/suncat2000/MobileDetectBundle). As this project doesn't look maintained anymore, we decided to create & maintain a fork. For more information read our [manifest](https://github.com/tattali/MobileDetectBundle/issues/8).*

Introduction
------------

This Bundle use [Mobile_Detect](https://github.com/serbanghita/Mobile-Detect) class and provides the following features:
This Bundle use [MobileDetect](https://github.com/serbanghita/Mobile-Detect) class and provides the following features:

* Detect the various mobile devices by Name, OS, browser User-Agent
* Manages site views for the various mobile devices (`mobile`, `tablet`, `full`)
* Manages site views for the various mobile devices (`mobile`, `tablet`, `desktop`)
* Redirects to mobile and tablet sites

* **[Migrate to 7x](src/Resources/doc/migration-7x.md)**

Documentation
-------------

Expand All @@ -32,9 +34,9 @@ composer require tattali/mobile-detect-bundle
#### Checking device

```php
use MobileDetectBundle\DeviceDetector\MobileDetectorInterface;
use Detection\MobileDetect;

public function someaction(MobileDetectorInterface $mobileDetector)
public function someaction(MobileDetect $mobileDetector)
{
$mobileDetector->isMobile();
$mobileDetector->isTablet();
Expand All @@ -55,11 +57,11 @@ Available User-Agents (uaMatch) with the php `is()` and twig `is_device()` [here
For switch device view, use `device_view` GET parameter:

```url
http://localhost:8000?device_view={full/mobile/tablet}
https://localhost:8000?device_view={desktop/mobile/tablet}
```

Or using the Symfony toolbar
![mbd-bundle-sf-toolbar](https://user-images.githubusercontent.com/10502887/161488224-aaedde1c-d3c3-4636-8761-a207fbd5d4ff.png)
![mbd-bundle-sf-toolbar](src/Resources/doc/sf-toolbar.png)

#### Going further

Expand All @@ -75,6 +77,6 @@ Any feedback and contribution will be very appreciated.
License and credits
-------

This bundle is under the MIT license. See the complete [license](src/Resources/meta/LICENSE) in the bundle
This bundle is under the MIT license. See the complete [license](LICENSE) in the bundle

Original authors: [suncat2000](https://github.com/suncat2000), [HenriVesala](https://github.com/HenriVesala), [netmikey](https://github.com/netmikey) and [all contributors](https://github.com/suncat2000/MobileDetectBundle/graphs/contributors)
8 changes: 0 additions & 8 deletions codecov.yml

This file was deleted.

32 changes: 17 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@
],
"require": {
"php": ">=8.2",
"mobiledetect/mobiledetectlib": "^2.8.15",
"symfony/dependency-injection": "^7.0",
"symfony/event-dispatcher": "^7.0",
"symfony/framework-bundle": "^7.0",
"symfony/yaml": "^7.0",
"twig/twig": "^2.0 || ^3.0"
"mobiledetect/mobiledetectlib": "^4.8",
"symfony/config": "^7.2",
"symfony/dependency-injection": "^7.2",
"symfony/event-dispatcher": "^7.2",
"symfony/http-kernel": "^7.2",
"symfony/routing": "^7.2",
"symfony/yaml": "^7.2",
"twig/twig": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.8",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-nette": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6",
"symfony/dotenv": "^7.0",
"symfony/phpunit-bridge": "^7.0"
"friendsofphp/php-cs-fixer": "^3.65",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpunit/phpunit": "^11.5",
"squizlabs/php_codesniffer": "^3.11",
"symfony/dotenv": "^7.2",
"symfony/phpunit-bridge": "^7.2"
},
"config": {
"sort-packages": true,
Expand Down
6 changes: 0 additions & 6 deletions phpstan.neon.dist

This file was deleted.

58 changes: 30 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/9.5/configuration.html -->
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
backupGlobals="false"
bootstrap="./vendor/autoload.php"
colors="true">
<coverage includeUncoveredFiles="true">
<include>
<directory>src</directory>
</include>
<report>
<clover outputFile="build/coverage.xml"/>
<html outputDirectory="build/coverage"/>
<xml outputDirectory="build/coverage-xml"/>
</report>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=0"/>
</php>
<testsuites>
<testsuite name="MobileDetectBundle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging/>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>./src/</directory>
</include>
</source>

<coverage>
<report>
<clover outputFile="build/coverage.xml"/>
<html outputDirectory="build/coverage"/>
<xml outputDirectory="build/coverage-xml"/>
</report>
</coverage>
</phpunit>
Loading

0 comments on commit ef03cf9

Please sign in to comment.