Skip to content

Commit c92be28

Browse files
committed
Update PHP minimum version to 8.0 and dependencies to latest compatible version
1 parent 914e25b commit c92be28

19 files changed

+43
-52
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
16-
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
16+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
1717
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1818
steps:
1919
- name: Checkout
@@ -28,7 +28,7 @@ jobs:
2828
run: php -v
2929
- name: Cache Composer packages
3030
id: composer-cache
31-
uses: actions/cache@v3
31+
uses: actions/cache@v4
3232
with:
3333
path: vendor
3434
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
command: phpcs-run
1212
use_website_config: false
1313
environment:
14-
php: 7.4.0
14+
php: 8.0
1515
filter:
1616
excluded_paths:
1717
- 'tests/*'

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/de9d4291c12e4761a83f69a1446dd5b5)](https://app.codacy.com/gh/platine-php/user-agent/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
1313

1414
### Requirements
15-
- **PHP >= 7.4**, **PHP 8**
15+
- **PHP >= 8.0**
1616

1717
### Installation
1818
#### Using composer (recommended)

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
},
2020

2121
"require": {
22-
"php": "^7.4 || ^8"
22+
"php": "^8"
2323
},
2424

2525
"require-dev": {
2626
"phpmd/phpmd": "@stable",
27-
"phpstan/phpstan": "^1.8",
28-
"phpunit/phpunit": "^9.5",
29-
"platine-php/dev": "^1.0",
27+
"phpstan/phpstan": "^2.0",
28+
"phpunit/phpunit": "^9.6",
29+
"platine-php/dev": "^2.0",
3030
"squizlabs/php_codesniffer": "3.*"
3131
},
3232

src/Detector/AbstractDetector.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
use Platine\UserAgent\Util\Helper;
5656

5757
/**
58-
* Class AbstractDetector
58+
* @class AbstractDetector
5959
* @package Platine\UserAgent\Detector
6060
*/
6161
abstract class AbstractDetector
@@ -92,7 +92,7 @@ abstract class AbstractDetector
9292
* The current entity
9393
* @var Browser|Cpu|Os|Device|Engine
9494
*/
95-
protected $entity;
95+
protected Browser|Cpu|Os|Device|Engine $entity;
9696

9797
/**
9898
* Create new instance
@@ -113,7 +113,7 @@ public function detect(string $userAgent): void
113113
$regex = $this->regex();
114114
$regexLength = count($regex);
115115
$i = 0;
116-
$match = null;
116+
$match = '';
117117
$matches = [];
118118

119119
while ($i < $regexLength && ! $matches) {
@@ -155,26 +155,25 @@ public function detect(string $userAgent): void
155155
$functionName = Helper::replaceFirst('__', '', $q[1]);
156156
$args = explode('.', $q[2]);
157157
$argument = $this->maps();
158-
if (is_array($args)) {
159-
foreach ($args as $key) {
160-
$argument = $argument[$key];
161-
}
158+
foreach ($args as $key) {
159+
$argument = $argument[$key];
162160
}
161+
163162
$result = null;
164163
if (method_exists($this, $functionName)) {
165164
$result = $this->{$functionName}($match, $argument);
166165
}
167166
$this->fillEntity([$q[0] => $result]);
168167
} else {
169-
$replacedMatch = preg_replace($q[1], $q[2], $match);
168+
$replacedMatch = preg_replace($q[1], $q[2], (string)$match);
170169
if ($replacedMatch !== null) {
171170
$this->fillEntity([$q[0] => $replacedMatch]);
172171
}
173172
}
174173
} elseif (count($q) === 4) {
175174
if (Helper::startsWith($q[3], '__')) {
176175
$functionName = Helper::replaceFirst('__', '', $q[3]);
177-
$result = preg_replace($q[1], $q[2], $match);
176+
$result = preg_replace($q[1], $q[2], (string)$match);
178177
if (method_exists($this, $functionName)) {
179178
$result = $this->{$functionName}($result);
180179
}
@@ -197,7 +196,7 @@ public function detect(string $userAgent): void
197196
* Return the entity instance
198197
* @return Browser|Cpu|Os|Device|Engine
199198
*/
200-
public function entity()
199+
public function entity(): Browser|Cpu|Os|Device|Engine
201200
{
202201
return $this->entity;
203202
}
@@ -243,7 +242,7 @@ protected function lowerize(string $value): string
243242
* @param string $str
244243
* @return string|string[]|null
245244
*/
246-
protected function trim(string $str)
245+
protected function trim(string $str): string|array|null
247246
{
248247
return preg_replace(
249248
'/^[\s\xA0]+|[\s\xA0]+$/',

src/Detector/BrowserDetector.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Platine\UserAgent\Entity\Browser;
5151

5252
/**
53-
* Class BrowserDetector
53+
* @class BrowserDetector
5454
* @package Platine\UserAgent\Detector
5555
*/
5656
class BrowserDetector extends AbstractDetector
@@ -93,20 +93,16 @@ public function regex(): array
9393
{
9494
return [
9595
[
96-
9796
// Presto based
9897
'/(opera\smini)\/([\w\.-]+)/i', // Opera Mini
9998
'/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i', // Opera Mobi/Tablet
10099
'/(opera).+version\/([\w\.]+)/i', // Opera > 9.80
101100
'/(opera)[\/\s]+([\w\.]+)/i' // Opera < 9.80
102101
], [self::NAME, self::VERSION], [
103-
104102
'/(opios)[\/\s]+([\w\.]+)/i' // Opera mini on iphone >= 8.0
105103
], [[self::NAME, 'Opera Mini'], self::VERSION], [
106-
107104
'/\s(opr)\/([\w\.]+)/i' // Opera Webkit
108105
], [[self::NAME, 'Opera'], self::VERSION], [
109-
110106
// Mixed
111107
'/(kindle)\/([\w\.]+)/i', // Kindle
112108
'/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i',
@@ -123,19 +119,14 @@ public function regex(): array
123119
'/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i'
124120
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
125121
], [self::NAME, self::VERSION], [
126-
127122
'/(konqueror)\/([\w\.]+)/i' // Konqueror
128123
], [[self::NAME, 'Konqueror'], self::VERSION], [
129-
130124
'/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i' // IE11
131125
], [[self::NAME, 'IE'], self::VERSION], [
132-
133126
'/(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i' // Microsoft Edge
134127
], [[self::NAME, 'Edge'], self::VERSION], [
135-
136128
'/(yabrowser)\/([\w\.]+)/i' // Yandex
137129
], [[self::NAME, 'Yandex'], self::VERSION], [
138-
139130
'/(puffin)\/([\w\.]+)/i' // Puffin
140131
], [[self::NAME, 'Puffin'], self::VERSION], [
141132

src/Detector/CpuDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Platine\UserAgent\Entity\Cpu;
5151

5252
/**
53-
* Class CpuDetector
53+
* @class CpuDetector
5454
* @package Platine\UserAgent\Detector
5555
*/
5656
class CpuDetector extends AbstractDetector

src/Detector/DeviceDetector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Platine\UserAgent\Entity\Device;
5151

5252
/**
53-
* Class DeviceDetector
53+
* @class DeviceDetector
5454
* @package Platine\UserAgent\Detector
5555
*/
5656
class DeviceDetector extends AbstractDetector
@@ -347,7 +347,6 @@ public function regex(): array
347347

348348
'/(android[\w\.\s\-]{0,9});.+build/i' // Generic Android Device
349349
], [self::MODEL, [self::VENDOR, 'Generic']]
350-
351350
];
352351
}
353352
}

src/Detector/EngineDetector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Platine\UserAgent\Entity\Engine;
5151

5252
/**
53-
* Class EngineDetector
53+
* @class EngineDetector
5454
* @package Platine\UserAgent\Detector
5555
*/
5656
class EngineDetector extends AbstractDetector
@@ -80,7 +80,6 @@ public function regex(): array
8080
{
8181
return [
8282
[
83-
8483
'/windows.+\sedge\/([\w\.]+)/i ' // EdgeHTML
8584
], [self::VERSION, [self::NAME, 'EdgeHTML']], [
8685

@@ -96,7 +95,6 @@ public function regex(): array
9695

9796
'/rv\:([\w\.]{1,9}).+(gecko)/i' // Gecko
9897
], [self::VERSION, self::NAME]
99-
10098
];
10199
}
102100
}

src/Detector/OsDetector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Platine\UserAgent\Entity\Os;
5151

5252
/**
53-
* Class OsDetector
53+
* @class OsDetector
5454
* @package Platine\UserAgent\Detector
5555
*/
5656
class OsDetector extends AbstractDetector
@@ -97,7 +97,6 @@ public function regex(): array
9797
{
9898
return [
9999
[
100-
101100
// Windows based
102101
'/microsoft\s(windows)\s(vista|xp)/i' // Windows (iTunes)
103102
], [self::NAME, self::VERSION], [

0 commit comments

Comments
 (0)