Skip to content

Commit 956bb8a

Browse files
committed
feat: ready for symfony 5.3, add github actions, merged from orginal repo suncat2000#143, suncat2000#144, suncat2000#135, suncat2000#133
1 parent c03eb57 commit 956bb8a

File tree

22 files changed

+364
-346
lines changed

22 files changed

+364
-346
lines changed

.github/workflows/code_checks.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# .github/workflows/code_checks.yaml
2+
name: Code_Checks
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
tests:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php: ['7.2', '7.3', '7.4', '8.0']
13+
stability: [ prefer-lowest, prefer-stable ]
14+
15+
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests
16+
steps:
17+
# basically git clone
18+
- uses: actions/checkout@v2
19+
20+
- name: Cache dependencies
21+
uses: actions/cache@v1
22+
with:
23+
path: ~/.composer/cache/files
24+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
25+
26+
# use PHP of specific version
27+
- uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: ${{ matrix.php }}
30+
extensions: pcov, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
31+
coverage: pcov # none, disable xdebug, pcov
32+
33+
- name: Install dependencies
34+
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
35+
36+
- name: Execute tests
37+
run: vendor/bin/phpunit --verbose
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# .github/workflows/code_coverage.yaml
2+
name: Code_Coverage
3+
4+
on: ["push", "pull_request"]
5+
6+
jobs:
7+
code_coverage:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: shivammathur/setup-php@v2
12+
with:
13+
php-version: 8.0
14+
coverage: pcov
15+
16+
- run: composer install --no-progress
17+
18+
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
19+
20+
- uses: codecov/codecov-action@v1.3.1
21+
with:
22+
token: ${{ secrets.CODECOV_TOKEN }}
23+
files: build/logs/clover.xml

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ build/
33
composer.phar
44
composer.lock
55
phpunit.xml
6+
.php_cs.cache
7+
.phpcs-cache
8+
.phpunit.result.cache
69
release.sh
10+
.idea/
11+
_gsdata_/

.travis.yml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,33 @@ cache:
99

1010
php:
1111
- hhvm
12+
- 7.1
1213
- 7.2
13-
- 7.3
1414

1515
dist: trusty
1616

1717
matrix:
1818
allow_failures:
19-
- php: hhvm
19+
- php: hhvm
2020
fast_finish: true
2121
include:
22-
- php: 7.2
23-
env: SYMFONY_VERSION='4.4.*'
24-
- php: 7.2
25-
env: SYMFONY_VERSION='5.1.*'
26-
- php: 7.2
27-
env: SYMFONY_VERSION='5.2.*'
28-
- php: 7.3
29-
env: SYMFONY_VERSION='4.4.*'
30-
- php: 7.3
31-
env: SYMFONY_VERSION='5.1.*'
32-
- php: 7.3
33-
env: SYMFONY_VERSION='5.2.*'
34-
- php: 7.4
35-
env: SYMFONY_VERSION='4.4.*'
36-
- php: 7.4
37-
env: SYMFONY_VERSION='5.1.*'
38-
- php: 7.4
39-
env: SYMFONY_VERSION='5.2.*'
22+
- php: 7.1
23+
env: SYMFONY_VERSION='4.0.*'
24+
- php: 7.2
25+
env: SYMFONY_VERSION='4.0.*'
26+
- php: 7.2
27+
env: SYMFONY_VERSION='5.0.*'
4028

4129
before_install:
42-
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi
30+
- if [[ "$TRAVIS_PHP_VERSION" != "5.6" && "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi
4331
- composer self-update
4432
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/framework-bundle:${SYMFONY_VERSION}; fi
4533

4634
install: composer update $COMPOSER_FLAGS --dev --no-interaction --prefer-dist
35+
36+
script:
37+
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then mkdir -p build/logs; fi
38+
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; else vendor/bin/phpunit; fi
39+
40+
after_script:
41+
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php vendor/bin/coveralls -v; fi

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
],
2222
"require": {
2323
"php": ">=7.2",
24-
"symfony/framework-bundle": "4.*|5.*",
24+
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
2525
"mobiledetect/mobiledetectlib": "^2.8",
2626
"twig/twig": "2.*|3.*"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^8.4",
30-
"symfony/phpunit-bridge": "4.*|5.*",
31-
"satooshi/php-coveralls": "^2.0.0"
29+
"phpunit/phpunit": "^8.4|^9.0",
30+
"symfony/phpunit-bridge": "^4.4|^5.0|^6.0",
31+
"php-coveralls/php-coveralls": "^2.0.0"
3232
},
3333
"autoload": {
3434
"psr-4": {

phpunit.xml.dist

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,42 @@
1111
stopOnError="false"
1212
stopOnIncomplete="false"
1313
stopOnSkipped="false"
14-
syntaxCheck="false"
1514
bootstrap="tests/bootstrap.php"
1615
>
16+
17+
<php>
18+
<ini name="error_reporting" value="-1" />
19+
<server name="APP_ENV" value="test" force="true" />
20+
<server name="SHELL_VERBOSITY" value="-1" />
21+
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
22+
<server name="SYMFONY_PHPUNIT_VERSION" value="9" />
23+
24+
<server name="KERNEL_CLASS" value="App\Tests\App\AppKernel"/>
25+
<server name="KERNEL_DIR" value="./Tests/App"/>
26+
<ini name="zend.enable_gc" value="0"/>
27+
</php>
28+
1729
<testsuites>
1830
<testsuite name="MobileDetectBundle Test Suite">
1931
<directory>Tests</directory>
2032
</testsuite>
2133
</testsuites>
22-
<filter>
23-
<whitelist>
24-
<directory suffix=".php">./</directory>
34+
35+
36+
<coverage processUncoveredFiles="false">
37+
<include>
38+
<directory suffix=".php">./</directory>
39+
</include>
2540
<exclude>
41+
<directory>.github</directory>
2642
<directory>./src/Resources</directory>
2743
<directory>./Tests</directory>
2844
<directory>./vendor</directory>
2945
<file>./tests/bootstrap.php</file>
3046
</exclude>
31-
</whitelist>
32-
</filter>
47+
<report>
48+
<clover outputFile="build/logs/clover.xml"/>
49+
</report>
50+
</coverage>
51+
3352
</phpunit>

src/DataCollector/DeviceDataCollector.php

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace SunCat\MobileDetectBundle\DataCollector;
1313

14-
use Exception;
1514
use SunCat\MobileDetectBundle\EventListener\RequestResponseListener;
1615
use SunCat\MobileDetectBundle\Helper\DeviceView;
1716
use Symfony\Component\HttpFoundation\Request;
@@ -50,9 +49,9 @@ public function __construct(DeviceView $deviceView)
5049
/**
5150
* Collects data for the given Request and Response.
5251
*
53-
* @param Request $request A Request instance
54-
* @param Response $response A Response instance
55-
* @param Exception $exception An Exception instance
52+
* @param Request $request A Request instance
53+
* @param Response $response A Response instance
54+
* @param Throwable|null $exception An Exception instance
5655
*
5756
* @api
5857
*/
@@ -96,25 +95,17 @@ public function collect(
9695
);
9796
}
9897

99-
/**
100-
* @return string
101-
*/
98+
10299
public function getCurrentView(): string
103100
{
104101
return $this->data['currentView'];
105102
}
106103

107-
/**
108-
* @return array
109-
*/
110104
public function getViews(): array
111105
{
112106
return $this->data['views'];
113107
}
114108

115-
/**
116-
* @param array $redirectConfig
117-
*/
118109
public function setRedirectConfig(array $redirectConfig)
119110
{
120111
$this->redirectConfig = $redirectConfig;
@@ -123,22 +114,14 @@ public function setRedirectConfig(array $redirectConfig)
123114
/**
124115
* Returns the name of the collector.
125116
*
126-
* @return string The collector name
127-
*
128117
* @api
129118
*/
130119
public function getName(): string
131120
{
132121
return 'device.collector';
133122
}
134123

135-
/**
136-
* @param $view
137-
* @param $host
138-
*
139-
* @return bool
140-
*/
141-
protected function canUseView($view, $host): bool
124+
protected function canUseView(string $view, ?string $host): bool
142125
{
143126
if (!is_array($this->redirectConfig)) {
144127
return true;
@@ -174,17 +157,11 @@ protected function canUseView($view, $host): bool
174157
return true;
175158
}
176159

177-
/**
178-
* @param Request $request
179-
* @param $view
180-
*
181-
* @return string
182-
*/
183-
private function generateSwitchLink(
184-
Request $request,
185-
$view
186-
) {
160+
161+
private function generateSwitchLink(Request $request, string $view): ?string
162+
{
187163
$requestSwitchView = $request->duplicate();
164+
188165
$requestSwitchView->query->set($this->deviceView->getSwitchParam(), $view);
189166
$requestSwitchView->server->set(
190167
'QUERY_STRING',

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class Configuration implements ConfigurationInterface
3030
public function getConfigTreeBuilder(): TreeBuilder
3131
{
3232
$treeBuilder = new TreeBuilder('mobile_detect');
33-
$rootNode = $treeBuilder->getRootNode();
33+
# Fallback-Solution for symfony 4
34+
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('mobile_detect');
3435

3536
$rootNode
3637
->children()

src/DeviceDetector/MobileDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
* @author suncat2000 <nikolay.kotovsky@gmail.com>
2020
*
2121
*/
22-
class MobileDetector extends MobileDetect
22+
class MobileDetector extends MobileDetect implements MobileDetectorInterface
2323
{
2424
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the MobileDetectBundle.
5+
*
6+
* (c) Nikolay Ivlev <nikolay.kotovsky@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace SunCat\MobileDetectBundle\DeviceDetector;
13+
14+
/**
15+
* MobileDetectorInterface interface
16+
*
17+
* @author pierrickmartos <pierrick.martos@gmail.com>
18+
*
19+
*/
20+
interface MobileDetectorInterface
21+
{
22+
/**
23+
* Check if the device is mobile.
24+
* Returns true if any type of mobile device detected, including special ones
25+
* @param null $userAgent deprecated
26+
* @param null $httpHeaders deprecated
27+
* @return bool
28+
*/
29+
public function isMobile($userAgent = null, $httpHeaders = null);
30+
31+
/**
32+
* Check if the device is a tablet.
33+
* Return true if any type of tablet device is detected.
34+
*
35+
* @param string $userAgent deprecated
36+
* @param array $httpHeaders deprecated
37+
* @return bool
38+
*/
39+
public function isTablet($userAgent = null, $httpHeaders = null);
40+
41+
/**
42+
* This method checks for a certain property in the
43+
* userAgent.
44+
* @todo: The httpHeaders part is not yet used.
45+
*
46+
* @param string $key
47+
* @param string $userAgent deprecated
48+
* @param string $httpHeaders deprecated
49+
* @return bool|int|null
50+
*/
51+
public function is($key, $userAgent = null, $httpHeaders = null);
52+
53+
/**
54+
* Some detection rules are relative (not standard),
55+
* because of the diversity of devices, vendors and
56+
* their conventions in representing the User-Agent or
57+
* the HTTP headers.
58+
*
59+
* This method will be used to check custom regexes against
60+
* the User-Agent string.
61+
*
62+
* @param $regex
63+
* @param string $userAgent
64+
* @return bool
65+
*
66+
* @todo: search in the HTTP headers too.
67+
*/
68+
public function match($regex, $userAgent = null);
69+
70+
/**
71+
* Retrieve the mobile grading, using self::MOBILE_GRADE_* constants.
72+
*
73+
* @return string One of the self::MOBILE_GRADE_* constants.
74+
*/
75+
public function mobileGrade();
76+
}

0 commit comments

Comments
 (0)