diff --git a/.gitattributes b/.gitattributes index 51f42b4cf4..69b0800ba5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,5 +10,4 @@ phpunit.xml.dist text eol=lf export-ignore .gitignore text eol=lf export-ignore .gitattributes text eol=lf export-ignore .phpcs.xml text eol=lf export-ignore -phpstan.neon text eol=lf export-ignore .yamllint text eol=lf export-ignore diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml deleted file mode 100644 index f4d2625406..0000000000 --- a/.github/workflows/phpcs.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: PHPCS check - -permissions: - actions: read - checks: read - contents: read - deployments: none - issues: read - packages: none - pull-requests: read - repository-projects: none - security-events: none - statuses: none - -on: - pull_request: - push: - branches: [ master ] - -jobs: - phpcs: - name: PHPCS - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: composer install --dev --prefer-dist --no-progress --no-suggest --ignore-platform-reqs - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.2' - tools: cs2pr - - name: Run phpcs - run: ./vendor/bin/phpcs -q --report=checkstyle | cs2pr diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml deleted file mode 100644 index e30505f0d9..0000000000 --- a/.github/workflows/phpstan.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: PHPStan check - -on: - pull_request: - push: - branches: [ master ] - -permissions: - actions: read - checks: read - contents: read - deployments: none - issues: read - packages: none - pull-requests: read - repository-projects: none - security-events: none - statuses: none - -jobs: - phpstan: - name: PHPStan - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - tools: composer:v2 - - name: "Composer install" - run: | - composer install --ignore-platform-reqs - - name: PHPStan - run: | - php -v - ./vendor/bin/phpstan analyse -c phpstan.neon diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 3829b4bd2a..2d97f4f0fa 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -24,18 +24,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest, windows-latest] - php-version: ['7.2', '8.3'] - include: - - php-version: 7.3 - operating-system: ubuntu-latest - - php-version: 7.4 - operating-system: ubuntu-latest - - php-version: 8.0 - operating-system: ubuntu-latest - - php-version: 8.1 - operating-system: ubuntu-latest - - php-version: 8.2 - operating-system: ubuntu-latest + php-version: ['7.1'] steps: - uses: actions/checkout@v2 - name: Install PHP @@ -59,7 +48,7 @@ jobs: strategy: matrix: operating-system: [macOS-latest] - php-version: [ '7.2', '8.3' ] + php-version: [ '7.1' ] steps: - uses: actions/checkout@v2 - name: Install PHP diff --git a/Cache/CacheInterface.php b/Cache/CacheInterface.php index bca17449af..208dc4d6db 100644 --- a/Cache/CacheInterface.php +++ b/Cache/CacheInterface.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Cache; interface CacheInterface @@ -19,14 +17,14 @@ interface CacheInterface * * @return mixed */ - public function fetch(string $id); + public function fetch($id); /** * @param string $id * * @return bool */ - public function contains(string $id): bool; + public function contains($id); /** * @param string $id @@ -35,17 +33,17 @@ public function contains(string $id): bool; * * @return bool */ - public function save(string $id, $data, int $lifeTime = 0): bool; + public function save($id, $data, $lifeTime = 0); /** * @param string $id * * @return bool */ - public function delete(string $id): bool; + public function delete($id); /** * @return bool */ - public function flushAll(): bool; + public function flushAll(); } diff --git a/Cache/DoctrineBridge.php b/Cache/DoctrineBridge.php index b89c1957bf..7f3838ec07 100644 --- a/Cache/DoctrineBridge.php +++ b/Cache/DoctrineBridge.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Cache; use Doctrine\Common\Cache\CacheProvider; @@ -32,7 +30,7 @@ public function __construct(CacheProvider $cache) /** * @inheritDoc */ - public function fetch(string $id) + public function fetch($id) { return $this->cache->fetch($id); } @@ -40,7 +38,7 @@ public function fetch(string $id) /** * @inheritDoc */ - public function contains(string $id): bool + public function contains($id) { return $this->cache->contains($id); } @@ -48,7 +46,7 @@ public function contains(string $id): bool /** * @inheritDoc */ - public function save(string $id, $data, int $lifeTime = 0): bool + public function save($id, $data, $lifeTime = 0) { return $this->cache->save($id, $data, $lifeTime); } @@ -56,7 +54,7 @@ public function save(string $id, $data, int $lifeTime = 0): bool /** * @inheritDoc */ - public function delete(string $id): bool + public function delete($id) { return $this->cache->delete($id); } @@ -64,7 +62,7 @@ public function delete(string $id): bool /** * @inheritDoc */ - public function flushAll(): bool + public function flushAll() { return $this->cache->flushAll(); } diff --git a/Cache/LaravelCache.php b/Cache/LaravelCache.php index 61d51003ed..187f673181 100644 --- a/Cache/LaravelCache.php +++ b/Cache/LaravelCache.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Cache; use Illuminate\Support\Facades\Cache; @@ -19,7 +17,7 @@ class LaravelCache implements CacheInterface /** * @inheritDoc */ - public function fetch(string $id) + public function fetch($id) { return Cache::get($id); } @@ -27,7 +25,7 @@ public function fetch(string $id) /** * @inheritDoc */ - public function contains(string $id): bool + public function contains($id) { return Cache::has($id); } @@ -35,7 +33,7 @@ public function contains(string $id): bool /** * @inheritDoc */ - public function save(string $id, $data, int $lifeTime = 0): bool + public function save($id, $data, $lifeTime = 0) { return Cache::put($id, $data, \func_num_args() < 3 ? null : $lifeTime); } @@ -43,7 +41,7 @@ public function save(string $id, $data, int $lifeTime = 0): bool /** * @inheritDoc */ - public function delete(string $id): bool + public function delete($id) { return Cache::forget($id); } @@ -51,7 +49,7 @@ public function delete(string $id): bool /** * @inheritDoc */ - public function flushAll(): bool + public function flushAll() { return Cache::flush(); } diff --git a/Cache/PSR16Bridge.php b/Cache/PSR16Bridge.php index 8f16a127dc..a5b2803087 100644 --- a/Cache/PSR16Bridge.php +++ b/Cache/PSR16Bridge.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Cache; use Psr\SimpleCache\CacheInterface as PsrCacheInterface; @@ -33,7 +31,7 @@ public function __construct(PsrCacheInterface $cache) /** * @inheritDoc */ - public function fetch(string $id) + public function fetch($id) { return $this->cache->get($id, false); } @@ -41,7 +39,7 @@ public function fetch(string $id) /** * @inheritDoc */ - public function contains(string $id): bool + public function contains($id) { return $this->cache->has($id); } @@ -49,7 +47,7 @@ public function contains(string $id): bool /** * @inheritDoc */ - public function save(string $id, $data, int $lifeTime = 0): bool + public function save($id, $data, $lifeTime = 0) { return $this->cache->set($id, $data, \func_num_args() < 3 ? null : $lifeTime); } @@ -57,7 +55,7 @@ public function save(string $id, $data, int $lifeTime = 0): bool /** * @inheritDoc */ - public function delete(string $id): bool + public function delete($id) { return $this->cache->delete($id); } @@ -65,7 +63,7 @@ public function delete(string $id): bool /** * @inheritDoc */ - public function flushAll(): bool + public function flushAll() { return $this->cache->clear(); } diff --git a/Cache/PSR6Bridge.php b/Cache/PSR6Bridge.php index c11d105977..911cc01d2b 100644 --- a/Cache/PSR6Bridge.php +++ b/Cache/PSR6Bridge.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Cache; use Psr\Cache\CacheItemPoolInterface; @@ -33,7 +31,7 @@ public function __construct(CacheItemPoolInterface $pool) /** * @inheritDoc */ - public function fetch(string $id) + public function fetch($id) { $item = $this->pool->getItem($id); @@ -43,7 +41,7 @@ public function fetch(string $id) /** * @inheritDoc */ - public function contains(string $id): bool + public function contains($id) { return $this->pool->hasItem($id); } @@ -51,7 +49,7 @@ public function contains(string $id): bool /** * @inheritDoc */ - public function save(string $id, $data, int $lifeTime = 0): bool + public function save($id, $data, $lifeTime = 0) { $item = $this->pool->getItem($id); $item->set($data); @@ -66,7 +64,7 @@ public function save(string $id, $data, int $lifeTime = 0): bool /** * @inheritDoc */ - public function delete(string $id): bool + public function delete($id) { return $this->pool->deleteItem($id); } @@ -74,7 +72,7 @@ public function delete(string $id): bool /** * @inheritDoc */ - public function flushAll(): bool + public function flushAll() { return $this->pool->clear(); } diff --git a/Cache/StaticCache.php b/Cache/StaticCache.php index f2790e164a..eec0755f66 100644 --- a/Cache/StaticCache.php +++ b/Cache/StaticCache.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Cache; /** @@ -29,7 +27,7 @@ class StaticCache implements CacheInterface /** * @inheritdoc */ - public function fetch(string $id) + public function fetch($id) { return $this->contains($id) ? self::$staticCache[$id] : false; } @@ -37,7 +35,7 @@ public function fetch(string $id) /** * @inheritdoc */ - public function contains(string $id): bool + public function contains($id) { return isset(self::$staticCache[$id]) || \array_key_exists($id, self::$staticCache); } @@ -45,7 +43,7 @@ public function contains(string $id): bool /** * @inheritdoc */ - public function save(string $id, $data, int $lifeTime = 0): bool + public function save($id, $data, $lifeTime = 0) { self::$staticCache[$id] = $data; @@ -55,7 +53,7 @@ public function save(string $id, $data, int $lifeTime = 0): bool /** * @inheritdoc */ - public function delete(string $id): bool + public function delete($id) { unset(self::$staticCache[$id]); @@ -65,7 +63,7 @@ public function delete(string $id): bool /** * @inheritdoc */ - public function flushAll(): bool + public function flushAll() { self::$staticCache = []; diff --git a/ClientHints.php b/ClientHints.php index d7b9a16d9a..46e89aaffb 100644 --- a/ClientHints.php +++ b/ClientHints.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector; class ClientHints @@ -89,7 +87,7 @@ class ClientHints * @param string $bitness `Sec-CH-UA-Bitness` * @param string $app `HTTP_X-REQUESTED-WITH` */ - public function __construct(string $model = '', string $platform = '', string $platformVersion = '', string $uaFullVersion = '', array $fullVersionList = [], bool $mobile = false, string $architecture = '', string $bitness = '', string $app = '') // phpcs:ignore Generic.Files.LineLength + public function __construct($model = '', $platform = '', $platformVersion = '', $uaFullVersion = '', $fullVersionList = [], $mobile = false, $architecture = '', $bitness = '', $app = '') // phpcs:ignore Generic.Files.LineLength { $this->model = $model; $this->platform = $platform; @@ -111,7 +109,7 @@ public function __construct(string $model = '', string $platform = '', string $p * * @throws \Exception */ - public function __get(string $variable) + public function __get($variable) { if (\property_exists($this, $variable)) { return $this->$variable; @@ -125,7 +123,7 @@ public function __get(string $variable) * * @return bool */ - public function isMobile(): bool + public function isMobile() { return $this->mobile; } @@ -135,7 +133,7 @@ public function isMobile(): bool * * @return string */ - public function getArchitecture(): string + public function getArchitecture() { return $this->architecture; } @@ -145,7 +143,7 @@ public function getArchitecture(): string * * @return string */ - public function getBitness(): string + public function getBitness() { return $this->bitness; } @@ -155,7 +153,7 @@ public function getBitness(): string * * @return string */ - public function getModel(): string + public function getModel() { return $this->model; } @@ -165,7 +163,7 @@ public function getModel(): string * * @return string */ - public function getOperatingSystem(): string + public function getOperatingSystem() { return $this->platform; } @@ -175,7 +173,7 @@ public function getOperatingSystem(): string * * @return string */ - public function getOperatingSystemVersion(): string + public function getOperatingSystemVersion() { return $this->platformVersion; } @@ -185,14 +183,13 @@ public function getOperatingSystemVersion(): string * * @return array */ - public function getBrandList(): array + public function getBrandList() { if (\is_array($this->fullVersionList) && \count($this->fullVersionList)) { $brands = \array_column($this->fullVersionList, 'brand'); $versions = \array_column($this->fullVersionList, 'version'); if (\count($brands) === \count($versions)) { - // @phpstan-ignore-next-line return \array_combine($brands, $versions); } } @@ -205,7 +202,7 @@ public function getBrandList(): array * * @return string */ - public function getBrandVersion(): string + public function getBrandVersion() { if (!empty($this->uaFullVersion)) { return $this->uaFullVersion; @@ -219,7 +216,7 @@ public function getBrandVersion(): string * * @return string */ - public function getApp(): string + public function getApp() { return $this->app; } @@ -231,7 +228,7 @@ public function getApp(): string * * @return ClientHints */ - public static function factory(array $headers): ClientHints + public static function factory(array $headers) { $model = $platform = $platformVersion = $uaFullVersion = $architecture = $bitness = ''; $app = ''; diff --git a/DeviceDetector.php b/DeviceDetector.php index e813adf12b..633d4652f5 100644 --- a/DeviceDetector.php +++ b/DeviceDetector.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector; use DeviceDetector\Cache\CacheInterface; @@ -68,12 +66,12 @@ class DeviceDetector /** * Current version number of DeviceDetector */ - public const VERSION = '6.3.1'; + const VERSION = '6.3.1'; /** * Constant used as value for unknown browser / os */ - public const UNKNOWN = 'UNK'; + const UNKNOWN = 'UNK'; /** * Holds all registered client types @@ -182,10 +180,10 @@ class DeviceDetector /** * Constructor * - * @param string $userAgent UA to parse + * @param string $userAgent UA to parse * @param ClientHints $clientHints Browser client hints to parse */ - public function __construct(string $userAgent = '', ?ClientHints $clientHints = null) + public function __construct($userAgent = '', $clientHints = null) { if ('' !== $userAgent) { $this->setUserAgent($userAgent); @@ -220,7 +218,7 @@ public function __construct(string $userAgent = '', ?ClientHints $clientHints = * * @return bool */ - public function __call(string $methodName, array $arguments): bool + public function __call($methodName, array $arguments) { foreach (AbstractDeviceParser::getAvailableDeviceTypes() as $deviceName => $deviceType) { if (\strtolower($methodName) === 'is' . \strtolower(\str_replace(' ', '', $deviceName))) { @@ -242,7 +240,7 @@ public function __call(string $methodName, array $arguments): bool * * @param string $userAgent */ - public function setUserAgent(string $userAgent): void + public function setUserAgent($userAgent) { if ($this->userAgent !== $userAgent) { $this->reset(); @@ -256,7 +254,7 @@ public function setUserAgent(string $userAgent): void * * @param ?ClientHints $clientHints */ - public function setClientHints(?ClientHints $clientHints = null): void + public function setClientHints($clientHints = null) { if ($this->clientHints !== $clientHints) { $this->reset(); @@ -270,7 +268,7 @@ public function setClientHints(?ClientHints $clientHints = null): void * * @throws \Exception */ - public function addClientParser(AbstractClientParser $parser): void + public function addClientParser(AbstractClientParser $parser) { $this->clientParsers[] = $parser; $this->clientTypes[] = $parser->getName(); @@ -279,7 +277,7 @@ public function addClientParser(AbstractClientParser $parser): void /** * @return array */ - public function getClientParsers(): array + public function getClientParsers() { return $this->clientParsers; } @@ -289,7 +287,7 @@ public function getClientParsers(): array * * @throws \Exception */ - public function addDeviceParser(AbstractDeviceParser $parser): void + public function addDeviceParser(AbstractDeviceParser $parser) { $this->deviceParsers[] = $parser; } @@ -297,7 +295,7 @@ public function addDeviceParser(AbstractDeviceParser $parser): void /** * @return array */ - public function getDeviceParsers(): array + public function getDeviceParsers() { return $this->deviceParsers; } @@ -305,7 +303,7 @@ public function getDeviceParsers(): array /** * @param AbstractBotParser $parser */ - public function addBotParser(AbstractBotParser $parser): void + public function addBotParser(AbstractBotParser $parser) { $this->botParsers[] = $parser; } @@ -313,7 +311,7 @@ public function addBotParser(AbstractBotParser $parser): void /** * @return array */ - public function getBotParsers(): array + public function getBotParsers() { return $this->botParsers; } @@ -325,7 +323,7 @@ public function getBotParsers(): array * * @param bool $discard */ - public function discardBotInformation(bool $discard = true): void + public function discardBotInformation($discard = true) { $this->discardBotInformation = $discard; } @@ -337,7 +335,7 @@ public function discardBotInformation(bool $discard = true): void * * @param bool $skip */ - public function skipBotDetection(bool $skip = true): void + public function skipBotDetection($skip = true) { $this->skipBotDetection = $skip; } @@ -350,7 +348,7 @@ public function skipBotDetection(bool $skip = true): void * @see bots.yml for a list of detected bots * */ - public function isBot(): bool + public function isBot() { return !empty($this->bot); } @@ -362,7 +360,7 @@ public function isBot(): bool * * @return bool */ - public function isTouchEnabled(): bool + public function isTouchEnabled() { $regex = 'Touch'; @@ -374,7 +372,7 @@ public function isTouchEnabled(): bool * * @return bool */ - public function isMobile(): bool + public function isMobile() { // Client hints indicate a mobile device if ($this->clientHints instanceof ClientHints && $this->clientHints->isMobile()) { @@ -427,7 +425,7 @@ public function isMobile(): bool * @see OperatingSystem::$desktopOsArray * */ - public function isDesktop(): bool + public function isDesktop() { $osName = $this->getOsAttribute('name'); @@ -452,7 +450,7 @@ public function isDesktop(): bool * * @return array|string|null */ - public function getOs(string $attr = '') + public function getOs($attr = '') { if ('' === $attr) { return $this->os; @@ -470,7 +468,7 @@ public function getOs(string $attr = '') * * @return array|string|null */ - public function getClient(string $attr = '') + public function getClient($attr = '') { if ('' === $attr) { return $this->client; @@ -487,7 +485,7 @@ public function getClient(string $attr = '') * @see AbstractDeviceParser::$deviceTypes for available device types * */ - public function getDevice(): ?int + public function getDevice() { return $this->device; } @@ -500,7 +498,7 @@ public function getDevice(): ?int * @see AbstractDeviceParser::$deviceTypes for available device types * */ - public function getDeviceName(): string + public function getDeviceName() { if (null !== $this->getDevice()) { return AbstractDeviceParser::getDeviceName($this->getDevice()); @@ -518,7 +516,7 @@ public function getDeviceName(): string * * @deprecated since 4.0 - short codes might be removed in next major release */ - public function getBrand(): string + public function getBrand() { return AbstractDeviceParser::getShortCode($this->brand); } @@ -531,7 +529,7 @@ public function getBrand(): string * @see self::$deviceBrand for available device brands * */ - public function getBrandName(): string + public function getBrandName() { return $this->brand; } @@ -541,7 +539,7 @@ public function getBrandName(): string * * @return string */ - public function getModel(): string + public function getModel() { return $this->model; } @@ -551,7 +549,7 @@ public function getModel(): string * * @return string */ - public function getUserAgent(): string + public function getUserAgent() { return $this->userAgent; } @@ -561,7 +559,7 @@ public function getUserAgent(): string * * @return ?ClientHints */ - public function getClientHints(): ?ClientHints + public function getClientHints() { return $this->clientHints; } @@ -581,7 +579,7 @@ public function getBot() * * @return bool */ - public function isParsed(): bool + public function isParsed() { return $this->parsed; } @@ -589,7 +587,7 @@ public function isParsed(): bool /** * Triggers the parsing of the current user agent */ - public function parse(): void + public function parse() { if ($this->isParsed()) { return; @@ -639,7 +637,7 @@ public function parse(): void * @internal * */ - public static function getInfoFromUserAgent(string $ua, ?ClientHints $clientHints = null): array + public static function getInfoFromUserAgent($ua, $clientHints = null) { static $deviceDetector; @@ -675,7 +673,7 @@ public static function getInfoFromUserAgent(string $ua, ?ClientHints $clientHint /** @var array $os */ $os = $deviceDetector->getOs(); - $osFamily = $os['family'] ?? 'Unknown'; + $osFamily = isset($os['family']) ? $os['family'] : 'Unknown'; unset($os['short_name'], $os['family']); @@ -698,7 +696,7 @@ public static function getInfoFromUserAgent(string $ua, ?ClientHints $clientHint * * @param CacheInterface $cache */ - public function setCache(CacheInterface $cache): void + public function setCache(CacheInterface $cache) { $this->cache = $cache; } @@ -708,7 +706,7 @@ public function setCache(CacheInterface $cache): void * * @return CacheInterface */ - public function getCache(): CacheInterface + public function getCache() { if (!empty($this->cache)) { return $this->cache; @@ -722,7 +720,7 @@ public function getCache(): CacheInterface * * @param YamlParser $yamlParser */ - public function setYamlParser(YamlParser $yamlParser): void + public function setYamlParser(YamlParser $yamlParser) { $this->yamlParser = $yamlParser; } @@ -732,7 +730,7 @@ public function setYamlParser(YamlParser $yamlParser): void * * @return YamlParser */ - public function getYamlParser(): YamlParser + public function getYamlParser() { if (!empty($this->yamlParser)) { return $this->yamlParser; @@ -746,7 +744,7 @@ public function getYamlParser(): YamlParser * * @return string */ - protected function getClientAttribute(string $attr): string + protected function getClientAttribute($attr) { if (!isset($this->client[$attr])) { return self::UNKNOWN; @@ -760,7 +758,7 @@ protected function getClientAttribute(string $attr): string * * @return string */ - protected function getOsAttribute(string $attr): string + protected function getOsAttribute($attr) { if (!isset($this->os[$attr])) { return self::UNKNOWN; @@ -774,7 +772,7 @@ protected function getOsAttribute(string $attr): string * * @return bool */ - protected function hasAndroidTableFragment(): bool + protected function hasAndroidTableFragment() { $regex = 'Android( [\.0-9]+)?; Tablet;|.*\-tablet$'; @@ -786,7 +784,7 @@ protected function hasAndroidTableFragment(): bool * * @return bool */ - protected function hasAndroidMobileFragment(): bool + protected function hasAndroidMobileFragment() { $regex = 'Android( [\.0-9]+)?; Mobile;|.*\-mobile$'; @@ -798,7 +796,7 @@ protected function hasAndroidMobileFragment(): bool * * @return bool */ - protected function hasAndroidVRFragment(): bool + protected function hasAndroidVRFragment() { $regex = 'Android( [\.0-9]+)?; Mobile VR;| VR '; @@ -810,7 +808,7 @@ protected function hasAndroidVRFragment(): bool * * @return bool */ - protected function hasDesktopFragment(): bool + protected function hasDesktopFragment() { $regex = 'Desktop(?: (x(?:32|64)|WOW64))?;'; @@ -822,7 +820,7 @@ protected function hasDesktopFragment(): bool * * @return bool */ - protected function usesMobileBrowser(): bool + protected function usesMobileBrowser() { return 'browser' === $this->getClient('type') && Browser::isMobileOnlyBrowser($this->getClientAttribute('name')); @@ -831,7 +829,7 @@ protected function usesMobileBrowser(): bool /** * Parses the UA for bot information using the Bot parser */ - protected function parseBot(): void + protected function parseBot() { if ($this->skipBotDetection) { $this->bot = false; @@ -864,7 +862,7 @@ protected function parseBot(): void /** * Tries to detect the client (e.g. browser, mobile app, ...) */ - protected function parseClient(): void + protected function parseClient() { $parsers = $this->getClientParsers(); @@ -886,7 +884,7 @@ protected function parseClient(): void /** * Tries to detect the device type, model and brand */ - protected function parseDevice(): void + protected function parseDevice() { $parsers = $this->getDeviceParsers(); @@ -919,7 +917,7 @@ protected function parseDevice(): void $vendorParser = new VendorFragment($this->getUserAgent()); $vendorParser->setYamlParser($this->getYamlParser()); $vendorParser->setCache($this->getCache()); - $this->brand = $vendorParser->parse()['brand'] ?? ''; + $this->brand = isset($vendorParser->parse()['brand']) ? $vendorParser->parse()['brand'] : ''; } $osName = $this->getOsAttribute('name'); @@ -1100,7 +1098,7 @@ protected function parseDevice(): void /** * Tries to detect the operating system */ - protected function parseOs(): void + protected function parseOs() { $osParser = new OperatingSystem(); $osParser->setUserAgent($this->getUserAgent()); @@ -1115,7 +1113,7 @@ protected function parseOs(): void * * @return array|null */ - protected function matchUserAgent(string $regex): ?array + protected function matchUserAgent($regex) { $regex = '/(?:^|[^A-Z_-])(?:' . \str_replace('/', '\/', $regex) . ')/i'; @@ -1129,7 +1127,7 @@ protected function matchUserAgent(string $regex): ?array /** * Resets all detected data */ - protected function reset(): void + protected function reset() { $this->bot = null; $this->client = null; diff --git a/Parser/AbstractBotParser.php b/Parser/AbstractBotParser.php index ea5c7e5609..005799d7a0 100644 --- a/Parser/AbstractBotParser.php +++ b/Parser/AbstractBotParser.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser; /** @@ -22,5 +20,5 @@ abstract class AbstractBotParser extends AbstractParser /** * Enables information discarding */ - abstract public function discardDetails(): void; + abstract public function discardDetails(); } diff --git a/Parser/AbstractParser.php b/Parser/AbstractParser.php index 6f7d82209e..41c3bb1c4c 100644 --- a/Parser/AbstractParser.php +++ b/Parser/AbstractParser.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser; use DeviceDetector\Cache\CacheInterface; @@ -84,30 +82,30 @@ abstract class AbstractParser * Versioning constant used to set max versioning to major version only * Version examples are: 3, 5, 6, 200, 123, ... */ - public const VERSION_TRUNCATION_MAJOR = 0; + const VERSION_TRUNCATION_MAJOR = 0; /** * Versioning constant used to set max versioning to minor version * Version examples are: 3.4, 5.6, 6.234, 0.200, 1.23, ... */ - public const VERSION_TRUNCATION_MINOR = 1; + const VERSION_TRUNCATION_MINOR = 1; /** * Versioning constant used to set max versioning to path level * Version examples are: 3.4.0, 5.6.344, 6.234.2, 0.200.3, 1.2.3, ... */ - public const VERSION_TRUNCATION_PATCH = 2; + const VERSION_TRUNCATION_PATCH = 2; /** * Versioning constant used to set versioning to build number * Version examples are: 3.4.0.12, 5.6.334.0, 6.234.2.3, 0.200.3.1, 1.2.3.0, ... */ - public const VERSION_TRUNCATION_BUILD = 3; + const VERSION_TRUNCATION_BUILD = 3; /** * Versioning constant used to set versioning to unlimited (no truncation) */ - public const VERSION_TRUNCATION_NONE = -1; + const VERSION_TRUNCATION_NONE = -1; /** * @var CacheInterface|null @@ -124,7 +122,7 @@ abstract class AbstractParser * * @return array|null */ - abstract public function parse(): ?array; + abstract public function parse(); /** * AbstractParser constructor. @@ -132,7 +130,7 @@ abstract public function parse(): ?array; * @param string $ua * @param ?ClientHints $clientHints */ - public function __construct(string $ua = '', ?ClientHints $clientHints = null) + public function __construct($ua = '', $clientHints = null) { $this->setUserAgent($ua); $this->setClientHints($clientHints); @@ -142,7 +140,7 @@ public function __construct(string $ua = '', ?ClientHints $clientHints = null) * Set how DeviceDetector should return versions * @param int $type Any of the VERSION_TRUNCATION_* constants */ - public static function setVersionTruncation(int $type): void + public static function setVersionTruncation($type) { if (!\in_array($type, [ self::VERSION_TRUNCATION_BUILD, @@ -163,7 +161,7 @@ public static function setVersionTruncation(int $type): void * * @param string $ua user agent */ - public function setUserAgent(string $ua): void + public function setUserAgent($ua) { $this->userAgent = $ua; } @@ -173,7 +171,7 @@ public function setUserAgent(string $ua): void * * @param ?ClientHints $clientHints client hints */ - public function setClientHints(?ClientHints $clientHints): void + public function setClientHints($clientHints) { $this->clientHints = $clientHints; } @@ -183,7 +181,7 @@ public function setClientHints(?ClientHints $clientHints): void * * @return string */ - public function getName(): string + public function getName() { return $this->parserName; } @@ -193,7 +191,7 @@ public function getName(): string * * @param CacheInterface $cache */ - public function setCache(CacheInterface $cache): void + public function setCache(CacheInterface $cache) { $this->cache = $cache; } @@ -203,7 +201,7 @@ public function setCache(CacheInterface $cache): void * * @return CacheInterface */ - public function getCache(): CacheInterface + public function getCache() { if (!empty($this->cache)) { return $this->cache; @@ -217,7 +215,7 @@ public function getCache(): CacheInterface * * @param YamlParser $yamlParser */ - public function setYamlParser(YamlParser $yamlParser): void + public function setYamlParser(YamlParser $yamlParser) { $this->yamlParser = $yamlParser; } @@ -227,7 +225,7 @@ public function setYamlParser(YamlParser $yamlParser): void * * @return YamlParser */ - public function getYamlParser(): YamlParser + public function getYamlParser() { if (!empty($this->yamlParser)) { return $this->yamlParser; @@ -241,7 +239,7 @@ public function getYamlParser(): YamlParser * * @return array */ - protected function getRegexes(): array + protected function getRegexes() { if (empty($this->regexList)) { $cacheKey = 'DeviceDetector-' . DeviceDetector::VERSION . 'regexes-' . $this->getName(); @@ -277,7 +275,7 @@ protected function getRegexes(): array * * @return string */ - protected function applyClientHintMapping(string $name): string + protected function applyClientHintMapping($name) { foreach (static::$clientHintMapping as $mappedName => $clientHints) { foreach ($clientHints as $clientHint) { @@ -293,7 +291,7 @@ protected function applyClientHintMapping(string $name): string /** * @return string */ - protected function getRegexesDirectory(): string + protected function getRegexesDirectory() { return \dirname(__DIR__); } @@ -307,7 +305,7 @@ protected function getRegexesDirectory(): string * * @throws \Exception */ - protected function matchUserAgent(string $regex): ?array + protected function matchUserAgent($regex) { $matches = []; @@ -335,14 +333,14 @@ protected function matchUserAgent(string $regex): ?array * * @return string */ - protected function buildByMatch(string $item, array $matches): string + protected function buildByMatch($item, array $matches) { $search = []; $replace = []; for ($nb = 1; $nb <= \count($matches); $nb++) { $search[] = '$' . $nb; - $replace[] = $matches[$nb] ?? ''; + $replace[] = isset($matches[$nb]) ? $matches[$nb] : ''; } return \trim(\str_replace($search, $replace, $item)); @@ -361,7 +359,7 @@ protected function buildByMatch(string $item, array $matches): string * * @return string */ - protected function buildVersion(string $versionString, array $matches): string + protected function buildVersion($versionString, array $matches) { $versionString = $this->buildByMatch($versionString, $matches); $versionString = \str_replace('_', '.', $versionString); @@ -387,7 +385,7 @@ protected function buildVersion(string $versionString, array $matches): string * * @return ?array */ - protected function preMatchOverall(): ?array + protected function preMatchOverall() { $regexes = $this->getRegexes(); @@ -421,7 +419,7 @@ protected function preMatchOverall(): ?array * * @return bool */ - protected function fuzzyCompare(string $value1, string $value2): bool + protected function fuzzyCompare($value1, $value2) { return \str_replace(' ', '', \strtolower($value1)) === \str_replace(' ', '', \strtolower($value2)); diff --git a/Parser/Bot.php b/Parser/Bot.php index 49348e93ae..95264996aa 100644 --- a/Parser/Bot.php +++ b/Parser/Bot.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser; /** @@ -39,7 +37,7 @@ class Bot extends AbstractBotParser /** * Enables information discarding */ - public function discardDetails(): void + public function discardDetails() { $this->discardDetails = true; } @@ -62,7 +60,7 @@ public function discardDetails(): void * * @return array|null */ - public function parse(): ?array + public function parse() { $result = null; diff --git a/Parser/Client/AbstractClientParser.php b/Parser/Client/AbstractClientParser.php index 90c10a05a7..4220937126 100644 --- a/Parser/Client/AbstractClientParser.php +++ b/Parser/Client/AbstractClientParser.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; use DeviceDetector\Parser\AbstractParser; @@ -41,7 +39,7 @@ abstract class AbstractClientParser extends AbstractParser * * @return array|null */ - public function parse(): ?array + public function parse() { $result = null; @@ -71,9 +69,9 @@ public function parse(): ?array * * @return array */ - public static function getAvailableClients(): array + public static function getAvailableClients() { - $instance = new static(); // @phpstan-ignore-line + $instance = new static(); $regexes = $instance->getRegexes(); $names = []; diff --git a/Parser/Client/Browser.php b/Parser/Client/Browser.php index ce76f5f950..656ca3e13a 100644 --- a/Parser/Client/Browser.php +++ b/Parser/Client/Browser.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; use DeviceDetector\Cache\CacheInterface; @@ -786,7 +784,7 @@ class Browser extends AbstractClientParser * @param string $ua * @param ClientHints|null $clientHints */ - public function __construct(string $ua = '', ?ClientHints $clientHints = null) + public function __construct($ua = '', $clientHints = null) { $this->browserHints = new BrowserHints($ua, $clientHints); parent::__construct($ua, $clientHints); @@ -797,7 +795,7 @@ public function __construct(string $ua = '', ?ClientHints $clientHints = null) * * @param ?ClientHints $clientHints client hints */ - public function setClientHints(?ClientHints $clientHints): void + public function setClientHints($clientHints) { parent::setClientHints($clientHints); $this->browserHints->setClientHints($clientHints); @@ -808,7 +806,7 @@ public function setClientHints(?ClientHints $clientHints): void * * @param string $ua user agent */ - public function setUserAgent(string $ua): void + public function setUserAgent($ua) { parent::setUserAgent($ua); $this->browserHints->setUserAgent($ua); @@ -819,7 +817,7 @@ public function setUserAgent(string $ua): void * * @param CacheInterface $cache */ - public function setCache(CacheInterface $cache): void + public function setCache(CacheInterface $cache) { parent::setCache($cache); $this->browserHints->setCache($cache); @@ -829,7 +827,7 @@ public function setCache(CacheInterface $cache): void * Returns list of all available browsers * @return array */ - public static function getAvailableBrowsers(): array + public static function getAvailableBrowsers() { return self::$availableBrowsers; } @@ -838,7 +836,7 @@ public static function getAvailableBrowsers(): array * Returns list of all available browser families * @return array */ - public static function getAvailableBrowserFamilies(): array + public static function getAvailableBrowserFamilies() { return self::$browserFamilies; } @@ -848,7 +846,7 @@ public static function getAvailableBrowserFamilies(): array * * @return string */ - public static function getBrowserShortName(string $name): ?string + public static function getBrowserShortName($name) { foreach (self::getAvailableBrowsers() as $browserShort => $browserName) { if (\strtolower($name) === \strtolower($browserName)) { @@ -864,7 +862,7 @@ public static function getBrowserShortName(string $name): ?string * * @return string|null If null, "Unknown" */ - public static function getBrowserFamily(string $browserLabel): ?string + public static function getBrowserFamily($browserLabel) { if (\in_array($browserLabel, self::$availableBrowsers)) { $browserLabel = \array_search($browserLabel, self::$availableBrowsers); @@ -886,7 +884,7 @@ public static function getBrowserFamily(string $browserLabel): ?string * * @return bool */ - public static function isMobileOnlyBrowser(string $browser): bool + public static function isMobileOnlyBrowser($browser) { return \in_array($browser, self::$mobileOnlyBrowsers) || (\in_array($browser, self::$availableBrowsers) && \in_array(\array_search($browser, self::$availableBrowsers), self::$mobileOnlyBrowsers)); @@ -897,7 +895,7 @@ public static function isMobileOnlyBrowser(string $browser): bool * * @param YamlParser $yamlParser */ - public function setYamlParser(YamlParser $yamlParser): void + public function setYamlParser(YamlParser $yamlParser) { parent::setYamlParser($yamlParser); $this->browserHints->setYamlParser($this->getYamlParser()); @@ -906,7 +904,7 @@ public function setYamlParser(YamlParser $yamlParser): void /** * @inheritdoc */ - public function parse(): ?array + public function parse() { $browserFromClientHints = $this->parseBrowserFromClientHints(); $browserFromUserAgent = $this->parseBrowserFromUserAgent(); @@ -931,8 +929,8 @@ public function parse(): ?array if (\preg_match('/^15/', $version) && \preg_match('/^114/', $browserFromUserAgent['version'])) { $name = '360 Secure Browser'; $short = '3B'; - $engine = $browserFromUserAgent['engine'] ?? ''; - $engineVersion = $browserFromUserAgent['engine_version'] ?? ''; + $engine = isset($browserFromUserAgent['engine']) ? $browserFromUserAgent['engine'] : ''; + $engineVersion = isset($browserFromUserAgent['engine_version']) ? $browserFromUserAgent['engine_version'] : ''; } if ('Atom' === $name || 'Huawei Browser' === $name) { @@ -944,8 +942,8 @@ public function parse(): ?array } if ('Vewd Browser' === $name) { - $engine = $browserFromUserAgent['engine'] ?? ''; - $engineVersion = $browserFromUserAgent['engine_version'] ?? ''; + $engine = isset($browserFromUserAgent['engine']) ? $browserFromUserAgent['engine'] : ''; + $engineVersion = isset($browserFromUserAgent['engine_version']) ? $browserFromUserAgent['engine_version'] : ''; } // If client hints report Chromium, but user agent detects a Chromium based browser, we favor this instead @@ -968,13 +966,13 @@ public function parse(): ?array if ($name !== $browserFromUserAgent['name'] && self::getBrowserFamily($name) === self::getBrowserFamily($browserFromUserAgent['name']) ) { - $engine = $browserFromUserAgent['engine'] ?? ''; - $engineVersion = $browserFromUserAgent['engine_version'] ?? ''; + $engine = isset($browserFromUserAgent['engine']) ? $browserFromUserAgent['engine'] : ''; + $engineVersion = isset($browserFromUserAgent['engine_version']) ? $browserFromUserAgent['engine_version'] : ''; } if ($name === $browserFromUserAgent['name']) { - $engine = $browserFromUserAgent['engine'] ?? ''; - $engineVersion = $browserFromUserAgent['engine_version'] ?? ''; + $engine = isset($browserFromUserAgent['engine']) ? $browserFromUserAgent['engine'] : ''; + $engineVersion = isset($browserFromUserAgent['engine_version']) ? $browserFromUserAgent['engine_version'] : ''; // In case the user agent reports a more detailed version, we try to use this instead if (!empty($browserFromUserAgent['version']) @@ -1002,7 +1000,7 @@ public function parse(): ?array if (\preg_match('~Chrome/.+ Safari/537.36~i', $this->userAgent)) { $engine = 'Blink'; - $family = self::getBrowserFamily((string) $short) ?? 'Chrome'; + $family = self::getBrowserFamily((string)$short) !== null ? self::getBrowserFamily((string) $short) : 'Chrome'; $engineVersion = $this->buildEngineVersion($engine); } @@ -1048,7 +1046,7 @@ public function parse(): ?array * * @return array */ - protected function parseBrowserFromClientHints(): array + protected function parseBrowserFromClientHints() { $name = $version = $short = ''; @@ -1094,7 +1092,7 @@ protected function parseBrowserFromClientHints(): array * * @throws \Exception */ - protected function parseBrowserFromUserAgent(): array + protected function parseBrowserFromUserAgent() { foreach ($this->getRegexes() as $regex) { $matches = $this->matchUserAgent($regex['regex']); @@ -1119,7 +1117,7 @@ protected function parseBrowserFromUserAgent(): array if (null !== $browserShort) { $version = $this->buildVersion((string) $regex['version'], $matches); - $engine = $this->buildEngine($regex['engine'] ?? [], $version); + $engine = $this->buildEngine(isset($regex['engine']) ? $regex['engine'] : [], $version); $engineVersion = $this->buildEngineVersion($engine); return [ @@ -1145,7 +1143,7 @@ protected function parseBrowserFromUserAgent(): array * * @return string */ - protected function buildEngine(array $engineData, string $browserVersion): string + protected function buildEngine(array $engineData, $browserVersion) { $engine = ''; @@ -1172,7 +1170,7 @@ protected function buildEngine(array $engineData, string $browserVersion): strin $engineParser->setCache($this->getCache()); $engineParser->setUserAgent($this->userAgent); $result = $engineParser->parse(); - $engine = $result['engine'] ?? ''; + $engine = isset($result['engine']) ? $result['engine'] : ''; } return $engine; @@ -1183,11 +1181,11 @@ protected function buildEngine(array $engineData, string $browserVersion): strin * * @return string */ - protected function buildEngineVersion(string $engine): string + protected function buildEngineVersion($engine) { $engineVersionParser = new Engine\Version($this->userAgent, $engine); $result = $engineVersionParser->parse(); - return $result['version'] ?? ''; + return isset($result['version']) ? $result['version'] : ''; } } diff --git a/Parser/Client/Browser/Engine.php b/Parser/Client/Browser/Engine.php index 9dab525d72..26ad42ada4 100644 --- a/Parser/Client/Browser/Engine.php +++ b/Parser/Client/Browser/Engine.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client\Browser; use DeviceDetector\Parser\Client\AbstractClientParser; @@ -62,7 +60,7 @@ class Engine extends AbstractClientParser * Returns list of all available browser engines * @return array */ - public static function getAvailableEngines(): array + public static function getAvailableEngines() { return self::$availableEngines; } @@ -70,7 +68,7 @@ public static function getAvailableEngines(): array /** * @inheritdoc */ - public function parse(): ?array + public function parse() { $matches = false; diff --git a/Parser/Client/Browser/Engine/Version.php b/Parser/Client/Browser/Engine/Version.php index 25c5ca838e..93ccddc968 100644 --- a/Parser/Client/Browser/Engine/Version.php +++ b/Parser/Client/Browser/Engine/Version.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client\Browser\Engine; use DeviceDetector\Parser\Client\AbstractClientParser; @@ -32,7 +30,7 @@ class Version extends AbstractClientParser * @param string $ua * @param string $engine */ - public function __construct(string $ua, string $engine) + public function __construct($ua, $engine) { parent::__construct($ua); @@ -42,7 +40,7 @@ public function __construct(string $ua, string $engine) /** * @inheritdoc */ - public function parse(): ?array + public function parse() { if (empty($this->engine)) { return null; diff --git a/Parser/Client/FeedReader.php b/Parser/Client/FeedReader.php index 900263c56f..2a20e1d289 100644 --- a/Parser/Client/FeedReader.php +++ b/Parser/Client/FeedReader.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; /** diff --git a/Parser/Client/Hints/AppHints.php b/Parser/Client/Hints/AppHints.php index 5ab1709748..5583c04588 100644 --- a/Parser/Client/Hints/AppHints.php +++ b/Parser/Client/Hints/AppHints.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client\Hints; use DeviceDetector\Parser\AbstractParser; @@ -31,14 +29,14 @@ class AppHints extends AbstractParser * * @return array|null */ - public function parse(): ?array + public function parse() { if (null === $this->clientHints) { return null; } $appId = $this->clientHints->getApp(); - $name = $this->getRegexes()[$appId] ?? null; + $name = isset($this->getRegexes()[$appId]) ? $this->getRegexes()[$appId] : null; if ('' === (string) $name) { return null; diff --git a/Parser/Client/Hints/BrowserHints.php b/Parser/Client/Hints/BrowserHints.php index d1252b94ba..f21a93f68d 100644 --- a/Parser/Client/Hints/BrowserHints.php +++ b/Parser/Client/Hints/BrowserHints.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client\Hints; use DeviceDetector\Parser\AbstractParser; @@ -31,14 +29,14 @@ class BrowserHints extends AbstractParser * * @return array|null */ - public function parse(): ?array + public function parse() { if (null === $this->clientHints) { return null; } $appId = $this->clientHints->getApp(); - $name = $this->getRegexes()[$appId] ?? null; + $name = isset($this->getRegexes()[$appId]) ? $this->getRegexes()[$appId] : null; if ('' === (string) $name) { return null; diff --git a/Parser/Client/Library.php b/Parser/Client/Library.php index a4c84fe47f..7bfb0e37c1 100644 --- a/Parser/Client/Library.php +++ b/Parser/Client/Library.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; /** diff --git a/Parser/Client/MediaPlayer.php b/Parser/Client/MediaPlayer.php index 78d4c00a3f..00b19c4af2 100644 --- a/Parser/Client/MediaPlayer.php +++ b/Parser/Client/MediaPlayer.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; /** diff --git a/Parser/Client/MobileApp.php b/Parser/Client/MobileApp.php index d5c0a1edce..8a33278649 100644 --- a/Parser/Client/MobileApp.php +++ b/Parser/Client/MobileApp.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; use DeviceDetector\Cache\CacheInterface; @@ -45,7 +43,7 @@ class MobileApp extends AbstractClientParser * @param string $ua * @param ClientHints|null $clientHints */ - public function __construct(string $ua = '', ?ClientHints $clientHints = null) + public function __construct($ua = '', $clientHints = null) { $this->appHints = new AppHints($ua, $clientHints); parent::__construct($ua, $clientHints); @@ -56,7 +54,7 @@ public function __construct(string $ua = '', ?ClientHints $clientHints = null) * * @param ?ClientHints $clientHints client hints */ - public function setClientHints(?ClientHints $clientHints): void + public function setClientHints($clientHints) { parent::setClientHints($clientHints); $this->appHints->setClientHints($clientHints); @@ -67,7 +65,7 @@ public function setClientHints(?ClientHints $clientHints): void * * @param string $ua user agent */ - public function setUserAgent(string $ua): void + public function setUserAgent($ua) { parent::setUserAgent($ua); $this->appHints->setUserAgent($ua); @@ -78,7 +76,7 @@ public function setUserAgent(string $ua): void * * @param CacheInterface $cache */ - public function setCache(CacheInterface $cache): void + public function setCache(CacheInterface $cache) { parent::setCache($cache); $this->appHints->setCache($cache); @@ -89,7 +87,7 @@ public function setCache(CacheInterface $cache): void * * @param YamlParser $yamlParser */ - public function setYamlParser(YamlParser $yamlParser): void + public function setYamlParser(YamlParser $yamlParser) { parent::setYamlParser($yamlParser); $this->appHints->setYamlParser($this->getYamlParser()); @@ -101,11 +99,11 @@ public function setYamlParser(YamlParser $yamlParser): void * * @return array|null */ - public function parse(): ?array + public function parse() { $result = parent::parse(); - $name = $result['name'] ?? ''; - $version = $result['version'] ?? ''; + $name = isset($result['name']) ? $result['name'] : ''; + $version = isset($result['version']) ? $result['version'] : ''; $appHash = $this->appHints->parse(); if (null !== $appHash && $appHash['name'] !== $name) { diff --git a/Parser/Client/PIM.php b/Parser/Client/PIM.php index 0db32692f4..75def94de5 100644 --- a/Parser/Client/PIM.php +++ b/Parser/Client/PIM.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Client; /** diff --git a/Parser/Device/AbstractDeviceParser.php b/Parser/Device/AbstractDeviceParser.php index 9e6c614778..10066b53f8 100644 --- a/Parser/Device/AbstractDeviceParser.php +++ b/Parser/Device/AbstractDeviceParser.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; use DeviceDetector\Parser\AbstractParser; @@ -36,20 +34,20 @@ abstract class AbstractDeviceParser extends AbstractParser */ protected $brand = ''; - public const DEVICE_TYPE_DESKTOP = 0; - public const DEVICE_TYPE_SMARTPHONE = 1; - public const DEVICE_TYPE_TABLET = 2; - public const DEVICE_TYPE_FEATURE_PHONE = 3; - public const DEVICE_TYPE_CONSOLE = 4; - public const DEVICE_TYPE_TV = 5; // including set top boxes, blu-ray players,... - public const DEVICE_TYPE_CAR_BROWSER = 6; - public const DEVICE_TYPE_SMART_DISPLAY = 7; - public const DEVICE_TYPE_CAMERA = 8; - public const DEVICE_TYPE_PORTABLE_MEDIA_PAYER = 9; - public const DEVICE_TYPE_PHABLET = 10; - public const DEVICE_TYPE_SMART_SPEAKER = 11; - public const DEVICE_TYPE_WEARABLE = 12; // including set watches, headsets - public const DEVICE_TYPE_PERIPHERAL = 13; // including portable terminal, portable projector + const DEVICE_TYPE_DESKTOP = 0; + const DEVICE_TYPE_SMARTPHONE = 1; + const DEVICE_TYPE_TABLET = 2; + const DEVICE_TYPE_FEATURE_PHONE = 3; + const DEVICE_TYPE_CONSOLE = 4; + const DEVICE_TYPE_TV = 5; // including set top boxes, blu-ray players,... + const DEVICE_TYPE_CAR_BROWSER = 6; + const DEVICE_TYPE_SMART_DISPLAY = 7; + const DEVICE_TYPE_CAMERA = 8; + const DEVICE_TYPE_PORTABLE_MEDIA_PAYER = 9; + const DEVICE_TYPE_PHABLET = 10; + const DEVICE_TYPE_SMART_SPEAKER = 11; + const DEVICE_TYPE_WEARABLE = 12; // including set watches, headsets + const DEVICE_TYPE_PERIPHERAL = 13; // including portable terminal, portable projector /** * Detectable device types @@ -1936,7 +1934,7 @@ abstract class AbstractDeviceParser extends AbstractParser * * @return int|null */ - public function getDeviceType(): ?int + public function getDeviceType() { return $this->deviceType; } @@ -1948,7 +1946,7 @@ public function getDeviceType(): ?int * * @return array */ - public static function getAvailableDeviceTypes(): array + public static function getAvailableDeviceTypes() { return self::$deviceTypes; } @@ -1958,7 +1956,7 @@ public static function getAvailableDeviceTypes(): array * * @return array */ - public static function getAvailableDeviceTypeNames(): array + public static function getAvailableDeviceTypeNames() { return \array_keys(self::$deviceTypes); } @@ -1970,7 +1968,7 @@ public static function getAvailableDeviceTypeNames(): array * * @return string */ - public static function getDeviceName(int $deviceType): string + public static function getDeviceName($deviceType) { $deviceName = \array_search($deviceType, self::$deviceTypes); @@ -1986,7 +1984,7 @@ public static function getDeviceName(int $deviceType): string * * @return string */ - public function getModel(): string + public function getModel() { return $this->model; } @@ -1996,7 +1994,7 @@ public function getModel(): string * * @return string */ - public function getBrand(): string + public function getBrand() { return $this->brand; } @@ -2008,7 +2006,7 @@ public function getBrand(): string * * @return string */ - public static function getFullName(string $brandId): string + public static function getFullName($brandId) { if (\array_key_exists($brandId, self::$deviceBrands)) { return self::$deviceBrands[$brandId]; @@ -2026,7 +2024,7 @@ public static function getFullName(string $brandId): string * * @deprecated since 4.0 - short codes might be removed in next major release */ - public static function getShortCode(string $brand): string + public static function getShortCode($brand) { return (string) \array_search($brand, self::$deviceBrands) ?: ''; } @@ -2036,7 +2034,7 @@ public static function getShortCode(string $brand): string * * @param string $userAgent */ - public function setUserAgent(string $userAgent): void + public function setUserAgent($userAgent) { $this->reset(); parent::setUserAgent($userAgent); @@ -2045,10 +2043,10 @@ public function setUserAgent(string $userAgent): void /** * @inheritdoc */ - public function parse(): ?array + public function parse() { $resultClientHint = $this->parseClientHints(); - $deviceModel = $resultClientHint['model'] ?? ''; + $deviceModel = isset($resultClientHint['model']) ? $resultClientHint['model'] : ''; // is freeze user-agent then restoring the original UA for the device definition if ('' !== $deviceModel && \preg_match('~Android 10[.\d]*; K(?: Build/|[;)])~i', $this->userAgent)) { @@ -2137,7 +2135,7 @@ public function parse(): ?array * * @return string */ - protected function buildModel(string $model, array $matches): string + protected function buildModel($model, array $matches) { $model = $this->buildByMatch($model, $matches); @@ -2155,7 +2153,7 @@ protected function buildModel(string $model, array $matches): string /** * @return array|null */ - protected function parseClientHints(): ?array + protected function parseClientHints() { if ($this->clientHints && $this->clientHints->getModel()) { return [ @@ -2173,7 +2171,7 @@ protected function parseClientHints(): ?array * * @return bool */ - protected function hasDesktopFragment(): bool + protected function hasDesktopFragment() { $regexExcludeDesktopFragment = \implode('|', [ 'CE-HTML', @@ -2189,7 +2187,7 @@ protected function hasDesktopFragment(): bool /** * Resets the stored values */ - protected function reset(): void + protected function reset() { $this->deviceType = null; $this->model = ''; @@ -2199,7 +2197,7 @@ protected function reset(): void /** * @return array */ - protected function getResult(): array + protected function getResult() { return [ 'deviceType' => $this->deviceType, diff --git a/Parser/Device/Camera.php b/Parser/Device/Camera.php index ce7a1b2724..15c2029601 100644 --- a/Parser/Device/Camera.php +++ b/Parser/Device/Camera.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -32,7 +30,7 @@ class Camera extends AbstractDeviceParser /** * @inheritdoc */ - public function parse(): ?array + public function parse() { if (!$this->preMatchOverall()) { return null; diff --git a/Parser/Device/CarBrowser.php b/Parser/Device/CarBrowser.php index 59edcd3db0..dcced8e8fe 100644 --- a/Parser/Device/CarBrowser.php +++ b/Parser/Device/CarBrowser.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -32,7 +30,7 @@ class CarBrowser extends AbstractDeviceParser /** * @inheritdoc */ - public function parse(): ?array + public function parse() { if (!$this->preMatchOverall()) { return null; diff --git a/Parser/Device/Console.php b/Parser/Device/Console.php index f3d0599075..9bf357ede9 100644 --- a/Parser/Device/Console.php +++ b/Parser/Device/Console.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -32,7 +30,7 @@ class Console extends AbstractDeviceParser /** * @inheritdoc */ - public function parse(): ?array + public function parse() { if (!$this->preMatchOverall()) { return null; diff --git a/Parser/Device/HbbTv.php b/Parser/Device/HbbTv.php index 34e6080725..89c4a6f0fa 100644 --- a/Parser/Device/HbbTv.php +++ b/Parser/Device/HbbTv.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -36,7 +34,7 @@ class HbbTv extends AbstractDeviceParser * * @return array|null */ - public function parse(): ?array + public function parse() { // only parse user agents containing fragments: hbbtv if (null === $this->isHbbTv()) { @@ -56,11 +54,11 @@ public function parse(): ?array * * @return string|null */ - public function isHbbTv(): ?string + public function isHbbTv() { $regex = 'HbbTV/([1-9]{1}(?:\.[0-9]{1}){1,2})'; $match = $this->matchUserAgent($regex); - return $match[1] ?? null; + return isset($match[1]) ? $match[1] : null; } } diff --git a/Parser/Device/Mobile.php b/Parser/Device/Mobile.php index d04856b17d..56e981e845 100644 --- a/Parser/Device/Mobile.php +++ b/Parser/Device/Mobile.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** diff --git a/Parser/Device/Notebook.php b/Parser/Device/Notebook.php index c607d77f59..92f3942bcf 100644 --- a/Parser/Device/Notebook.php +++ b/Parser/Device/Notebook.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -26,7 +24,7 @@ class Notebook extends AbstractDeviceParser /** * @inheritdoc */ - public function parse(): ?array + public function parse() { if (!$this->matchUserAgent('FBMD/')) { return null; diff --git a/Parser/Device/PortableMediaPlayer.php b/Parser/Device/PortableMediaPlayer.php index 7a60f6e2ad..b011819382 100644 --- a/Parser/Device/PortableMediaPlayer.php +++ b/Parser/Device/PortableMediaPlayer.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -32,7 +30,7 @@ class PortableMediaPlayer extends AbstractDeviceParser /** * @inheritdoc */ - public function parse(): ?array + public function parse() { if (!$this->preMatchOverall()) { return null; diff --git a/Parser/Device/ShellTv.php b/Parser/Device/ShellTv.php index dda4bc5e84..3c96eb689c 100644 --- a/Parser/Device/ShellTv.php +++ b/Parser/Device/ShellTv.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser\Device; /** @@ -34,7 +32,7 @@ class ShellTv extends AbstractDeviceParser * * @throws \Exception */ - public function isShellTv(): bool + public function isShellTv() { $regex = '[a-z]+[ _]Shell[ _]\w{6}|tclwebkit(\d+[\.\d]*)'; $match = $this->matchUserAgent($regex); @@ -49,7 +47,7 @@ public function isShellTv(): bool * * @return array|null */ - public function parse(): ?array + public function parse() { // only parse user agents containing fragments: {brand} shell if (false === $this->isShellTv()) { diff --git a/Parser/OperatingSystem.php b/Parser/OperatingSystem.php index 15e95ccb00..03eae49de6 100644 --- a/Parser/OperatingSystem.php +++ b/Parser/OperatingSystem.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser; use DeviceDetector\ClientHints; @@ -322,7 +320,7 @@ class OperatingSystem extends AbstractParser * * @return array */ - public static function getAvailableOperatingSystems(): array + public static function getAvailableOperatingSystems() { return self::$operatingSystems; } @@ -332,7 +330,7 @@ public static function getAvailableOperatingSystems(): array * * @return array */ - public static function getAvailableOperatingSystemFamilies(): array + public static function getAvailableOperatingSystemFamilies() { return self::$osFamilies; } @@ -344,7 +342,7 @@ public static function getAvailableOperatingSystemFamilies(): array * * @return array */ - public static function getShortOsData(string $name): array + public static function getShortOsData($name) { $short = 'UNK'; @@ -365,7 +363,7 @@ public static function getShortOsData(string $name): array /** * @inheritdoc */ - public function parse(): ?array + public function parse() { $osFromClientHints = $this->parseOsFromClientHints(); $osFromUserAgent = $this->parseOsFromUserAgent(); @@ -395,10 +393,18 @@ public function parse(): ?array } if ('Fire OS' === $osFromUserAgent['name']) { - $majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0'); - - $version = $this->fireOsVersionMapping[$version] - ?? $this->fireOsVersionMapping[$majorVersion] ?? ''; + $majorVersion = (int) (isset(\explode('.', $version, 1)[0]) ? \explode('.', $version, 1)[0] : '0'); + + $isHaveVersion = isset($this->fireOsVersionMapping[$version]); + $isHaveMajorVersion = isset($this->fireOsVersionMapping[$majorVersion]); + + if ($isHaveVersion) { + $version = $this->fireOsVersionMapping[$version]; + } elseif ($isHaveMajorVersion) { + $version = $this->fireOsVersionMapping[$majorVersion]; + } else { + $version = ''; + } } } @@ -436,22 +442,41 @@ public function parse(): ?array } if ('org.lineageos.jelly' === $this->clientHints->getApp() && 'Lineage OS' !== $name) { - $majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0'); + $majorVersion = (int) (isset(\explode('.', $version, 1)[0]) ? \explode('.', $version, 1)[0] : '0'); $name = 'Lineage OS'; $family = 'Android'; $short = 'LEN'; - $version = $this->lineageOsVersionMapping[$version] - ?? $this->lineageOsVersionMapping[$majorVersion] ?? ''; + + $isHaveVersion = isset($this->lineageOsVersionMapping[$version]); + $isHaveMajorVersion = isset($this->lineageOsVersionMapping[$majorVersion]); + + if ($isHaveVersion) { + $version = $this->lineageOsVersionMapping[$version]; + } elseif ($isHaveMajorVersion) { + $version = $this->lineageOsVersionMapping[$majorVersion]; + } else { + $version = ''; + } } if ('org.mozilla.tv.firefox' === $this->clientHints->getApp() && 'Fire OS' !== $name) { - $majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0'); + $majorVersion = (int) (isset(\explode('.', $version, 1)[0]) ? \explode('.', $version, 1)[0] : '0'); $name = 'Fire OS'; $family = 'Android'; $short = 'FIR'; - $version = $this->fireOsVersionMapping[$version] ?? $this->fireOsVersionMapping[$majorVersion] ?? ''; + + $isHaveVersion = isset($this->fireOsVersionMapping[$version]); + $isHaveMajorVersion = isset($this->fireOsVersionMapping[$majorVersion]); + + if ($isHaveVersion) { + $version = $this->fireOsVersionMapping[$version]; + } elseif ($isHaveMajorVersion) { + $version = $this->fireOsVersionMapping[$majorVersion]; + } else { + $version = ''; + } } } @@ -477,7 +502,7 @@ public function parse(): ?array * * @return string|null If null, "Unknown" */ - public static function getOsFamily(string $osLabel): ?string + public static function getOsFamily($osLabel) { if (\in_array($osLabel, self::$operatingSystems)) { $osLabel = \array_search($osLabel, self::$operatingSystems); @@ -499,7 +524,7 @@ public static function getOsFamily(string $osLabel): ?string * * @return bool */ - public static function isDesktopOs(string $osName): bool + public static function isDesktopOs($osName) { $osFamily = self::getOsFamily($osName); @@ -514,7 +539,7 @@ public static function isDesktopOs(string $osName): bool * * @return ?string */ - public static function getNameFromId(string $os, ?string $ver = null): ?string + public static function getNameFromId($os, $ver = null) { if (\array_key_exists($os, self::$operatingSystems)) { $osFullName = self::$operatingSystems[$os]; @@ -530,7 +555,7 @@ public static function getNameFromId(string $os, ?string $ver = null): ?string * * @return array */ - protected function parseOsFromClientHints(): array + protected function parseOsFromClientHints() { $name = $version = $short = ''; @@ -549,7 +574,7 @@ protected function parseOsFromClientHints(): array $version = $this->clientHints->getOperatingSystemVersion(); if ('Windows' === $name) { - $majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0'); + $majorVersion = (int) (isset(\explode('.', $version, 1)[0]) ? \explode('.', $version, 1)[0] : '0'); if ($majorVersion > 0 && $majorVersion < 11) { $version = '10'; @@ -577,7 +602,7 @@ protected function parseOsFromClientHints(): array * * @throws \Exception */ - protected function parseOsFromUserAgent(): array + protected function parseOsFromUserAgent() { $osRegex = $matches = []; $name = $version = $short = ''; @@ -592,13 +617,16 @@ protected function parseOsFromUserAgent(): array if (!empty($matches)) { $name = $this->buildByMatch($osRegex['name'], $matches); - ['name' => $name, 'short' => $short] = self::getShortOsData($name); + $shortData = self::getShortOsData($name); + $name = $shortData['name']; + $short = $shortData['short']; $version = \array_key_exists('version', $osRegex) ? $this->buildVersion((string) $osRegex['version'], $matches) : ''; - foreach ($osRegex['versions'] ?? [] as $regex) { + $versions = isset($osRegex['versions']) && is_array($osRegex['versions']) ? $osRegex['versions'] : []; + foreach ($versions as $regex) { $matches = $this->matchUserAgent($regex['regex']); if (!$matches) { @@ -607,7 +635,9 @@ protected function parseOsFromUserAgent(): array if (\array_key_exists('name', $regex)) { $name = $this->buildByMatch($regex['name'], $matches); - ['name' => $name, 'short' => $short] = self::getShortOsData($name); + $shortData = self::getShortOsData($name); + $name = $shortData['name']; + $short = $shortData['short']; } if (\array_key_exists('version', $regex)) { @@ -630,7 +660,7 @@ protected function parseOsFromUserAgent(): array * * @return string */ - protected function parsePlatform(): string + protected function parsePlatform() { // Use architecture from client hints if available if ($this->clientHints instanceof ClientHints && $this->clientHints->getArchitecture()) { diff --git a/Parser/VendorFragment.php b/Parser/VendorFragment.php index faf0d7a77a..cf415face4 100644 --- a/Parser/VendorFragment.php +++ b/Parser/VendorFragment.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Parser; /** @@ -37,7 +35,7 @@ class VendorFragment extends AbstractParser /** * @inheritdoc */ - public function parse(): ?array + public function parse() { foreach ($this->getRegexes() as $brand => $regexes) { foreach ($regexes as $regex) { @@ -55,7 +53,7 @@ public function parse(): ?array /** * @return string|null */ - public function getMatchedRegex(): ?string + public function getMatchedRegex() { return $this->matchedRegex; } diff --git a/README.md b/README.md index 5df621b005..2f36498943 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ DeviceDetector ## Code Status ![PHPUnit](https://github.com/matomo-org/device-detector/workflows/PHPUnit/badge.svg?branch=master) -![PHPStan](https://github.com/matomo-org/device-detector/workflows/PHPStan%20check/badge.svg?branch=master) ![PHPCS](https://github.com/matomo-org/device-detector/workflows/PHPCS%20check/badge.svg?branch=master) ![YAML Lint](https://github.com/matomo-org/device-detector/workflows/YAML%20Lint/badge.svg?branch=master) [![Validate regular Expressions](https://github.com/matomo-org/device-detector/actions/workflows/regular_expressions.yml/badge.svg)](https://github.com/matomo-org/device-detector/actions/workflows/regular_expressions.yml) diff --git a/Tests/Cache/PSR16CacheTest.php b/Tests/Cache/PSR16CacheTest.php index 5832f0fba7..1a9dc3823c 100644 --- a/Tests/Cache/PSR16CacheTest.php +++ b/Tests/Cache/PSR16CacheTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Cache; use DeviceDetector\Cache\PSR16Bridge; @@ -19,7 +17,7 @@ class PSR16CacheTest extends TestCase { - protected function setUp(): void + protected function setUp() { if (!\class_exists('\MatthiasMullie\Scrapbook\Adapters\MemoryStore')) { $this->markTestSkipped('class \MatthiasMullie\Scrapbook\Adapters\MemoryStore required for tests'); @@ -31,13 +29,13 @@ protected function setUp(): void $cache->flushAll(); } - public function testSetNotPresent(): void + public function testSetNotPresent() { $cache = new PSR16Bridge(new SimpleCache(new MemoryStore())); $this->assertFalse($cache->fetch('NotExistingKey')); } - public function testSetAndGet(): void + public function testSetAndGet() { $cache = new PSR16Bridge(new SimpleCache(new MemoryStore())); diff --git a/Tests/Cache/PSR6CacheTest.php b/Tests/Cache/PSR6CacheTest.php index 1077efbfa2..34de998437 100644 --- a/Tests/Cache/PSR6CacheTest.php +++ b/Tests/Cache/PSR6CacheTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Cache; use DeviceDetector\Cache\PSR6Bridge; @@ -19,7 +17,7 @@ class PSR6CacheTest extends TestCase { - protected function setUp(): void + protected function setUp() { if (!\class_exists('\MatthiasMullie\Scrapbook\Adapters\MemoryStore')) { $this->markTestSkipped('class \MatthiasMullie\Scrapbook\Adapters\MemoryStore required for tests'); @@ -31,13 +29,13 @@ protected function setUp(): void $cache->flushAll(); } - public function testSetNotPresent(): void + public function testSetNotPresent() { $cache = new PSR6Bridge(new Pool(new MemoryStore())); $this->assertFalse($cache->fetch('NotExistingKey')); } - public function testSetAndGet(): void + public function testSetAndGet() { $cache = new PSR6Bridge(new Pool(new MemoryStore())); diff --git a/Tests/Cache/StaticCacheTest.php b/Tests/Cache/StaticCacheTest.php index 09327c1aeb..02056f7abf 100644 --- a/Tests/Cache/StaticCacheTest.php +++ b/Tests/Cache/StaticCacheTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Cache; use DeviceDetector\Cache\StaticCache; @@ -17,19 +15,19 @@ class StaticCacheTest extends TestCase { - protected function setUp(): void + protected function setUp() { $cache = new StaticCache(); $cache->flushAll(); } - public function testSetNotPresent(): void + public function testSetNotPresent() { $cache = new StaticCache(); $this->assertFalse($cache->fetch('NotExistingKey')); } - public function testSetAndGet(): void + public function testSetAndGet() { $cache = new StaticCache(); diff --git a/Tests/ClientHintsTest.php b/Tests/ClientHintsTest.php index 9cdc0ba651..94df475a8a 100644 --- a/Tests/ClientHintsTest.php +++ b/Tests/ClientHintsTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests; use DeviceDetector\ClientHints; @@ -17,7 +15,7 @@ class ClientHintsTest extends TestCase { - public function testHeaders(): void + public function testHeaders() { $headers = [ 'sec-ch-ua' => '"Opera";v="83", " Not;A Brand";v="99", "Chromium";v="98"', @@ -37,7 +35,7 @@ public function testHeaders(): void ], $ch->getBrandList()); } - public function testHeadersHttp(): void + public function testHeadersHttp() { $headers = [ 'HTTP_SEC_CH_UA_FULL_VERSION_LIST' => '" Not A;Brand";v="99.0.0.0", "Chromium";v="98.0.4758.82", "Opera";v="98.0.4758.82"', @@ -61,7 +59,7 @@ public function testHeadersHttp(): void self::assertSame('DN2103', $ch->getModel()); } - public function testHeadersJavascript(): void + public function testHeadersJavascript() { $headers = [ 'fullVersionList' => [ @@ -87,7 +85,7 @@ public function testHeadersJavascript(): void self::assertSame('', $ch->getModel()); } - public function testIncorrectVersionListIsDiscarded(): void + public function testIncorrectVersionListIsDiscarded() { $headers = [ 'fullVersionList' => [ diff --git a/Tests/DeviceDetectorTest.php b/Tests/DeviceDetectorTest.php index 416b68a276..e52c409c1e 100644 --- a/Tests/DeviceDetectorTest.php +++ b/Tests/DeviceDetectorTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests; use Closure; @@ -27,21 +25,21 @@ class DeviceDetectorTest extends TestCase { - public function testAddClientParserInvalid(): void + public function testAddClientParserInvalid() { - $this->expectException(\Throwable::class); + $this->setExpectedException('TypeError'); $dd = new DeviceDetector(); $dd->addClientParser('Invalid'); } - public function testAddDeviceParserInvalid(): void + public function testAddDeviceParserInvalid() { - $this->expectException(\Throwable::class); + $this->setExpectedException('TypeError'); $dd = new DeviceDetector(); $dd->addDeviceParser('Invalid'); } - public function testDevicesYmlFiles(): void + public function testDevicesYmlFiles() { $allowedKeys = ['regex', 'device', 'models', 'model', 'brand']; $fixtureFiles = \glob(\realpath(__DIR__) . '/../regexes/device/*.yml'); @@ -105,7 +103,7 @@ public function testDevicesYmlFiles(): void } if (\array_key_exists('models', $regex)) { - $this->assertIsArray($regex['models']); + $this->assertNotEmpty($regex['models']); foreach ($regex['models'] as $model) { $keys = \array_keys($model); @@ -164,20 +162,20 @@ public function testDevicesYmlFiles(): void } else { $this->assertArrayHasKey('device', $regex); $this->assertArrayHasKey('model', $regex); - $this->assertIsString($regex['model']); + $this->assertNotNull($regex['model']); } } } } - public function testSetCacheInvalid(): void + public function testSetCacheInvalid() { - $this->expectException(\TypeError::class); + $this->setExpectedException('TypeError'); $dd = new DeviceDetector(); $dd->setCache('Invalid'); } - public function testCacheSetAndGet(): void + public function testCacheSetAndGet() { if (!\extension_loaded('memcached') || !\class_exists('\Doctrine\Common\Cache\MemcachedCache')) { $this->markTestSkipped('memcached not enabled'); @@ -191,7 +189,7 @@ public function testCacheSetAndGet(): void $this->assertInstanceOf(DoctrineBridge::class, $dd->getCache()); } - public function testParseEmptyUA(): void + public function testParseEmptyUA() { $dd = new DeviceDetector(''); $dd->parse(); @@ -200,7 +198,7 @@ public function testParseEmptyUA(): void $this->assertFalse($dd->isMobile()); } - public function testParseInvalidUA(): void + public function testParseInvalidUA() { $dd = new DeviceDetector('12345'); $dd->parse(); @@ -208,7 +206,7 @@ public function testParseInvalidUA(): void $this->assertFalse($dd->isMobile()); } - public function testIsParsed(): void + public function testIsParsed() { $dd = new DeviceDetector('Mozilla/5.0 (Linux; Android 4.2.2; ARCHOS 101 PLATINUM Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Safari/537.36'); $this->assertFalse($dd->isParsed()); @@ -219,7 +217,7 @@ public function testIsParsed(): void /** * @dataProvider getFixtures */ - public function testParse(array $fixtureData): void + public function testParse(array $fixtureData) { $ua = $fixtureData['user_agent']; $clientHints = !empty($fixtureData['headers']) ? ClientHints::factory($fixtureData['headers']) : null; @@ -239,7 +237,7 @@ public function testParse(array $fixtureData): void $errorMessage = \sprintf( "UserAgent: %s\nHeaders: %s", $ua, - \print_r($fixtureData['headers'] ?? null, true) + \print_r(isset($fixtureData['headers']) ? $fixtureData['headers'] : null, true) ); unset($fixtureData['headers']); // ignore headers in result @@ -247,7 +245,7 @@ public function testParse(array $fixtureData): void $this->assertEquals($fixtureData, $uaInfo, $errorMessage); } - public function getFixtures(): array + public function getFixtures() { $fixtures = []; $fixtureFiles = \glob(\realpath(__DIR__) . '/fixtures/*.yml'); @@ -271,7 +269,7 @@ public function getFixtures(): array /** * @dataProvider getFixturesClient */ - public function testParseClient(array $fixtureData): void + public function testParseClient(array $fixtureData) { $ua = $fixtureData['user_agent']; $clientHints = !empty($fixtureData['headers']) ? ClientHints::factory($fixtureData['headers']) : null; @@ -301,7 +299,7 @@ public function testParseClient(array $fixtureData): void $this->assertEquals($fixtureData['client'], $uaInfo['client'], $messageError); } - public function getFixturesClient(): array + public function getFixturesClient() { $fixtures = []; $fixtureFiles = \glob(\realpath(__DIR__) . '/Parser/Client/fixtures/*.yml'); @@ -320,7 +318,7 @@ public function getFixturesClient(): array /** * @dataProvider getFixturesDevice */ - public function testParseDevice(array $fixtureData): void + public function testParseDevice(array $fixtureData) { $ua = $fixtureData['user_agent']; $clientHints = !empty($fixtureData['headers']) ? ClientHints::factory($fixtureData['headers']) : null; @@ -341,7 +339,7 @@ public function testParseDevice(array $fixtureData): void $this->assertEquals($fixtureData['device'], $uaInfo['device']); } - public function getFixturesDevice(): array + public function getFixturesDevice() { $fixtures = []; $fixtureFiles = \glob(\realpath(__DIR__) . '/Parser/Device/fixtures/*.yml'); @@ -357,7 +355,7 @@ public function getFixturesDevice(): array return $fixtures; } - public function testInstanceReusage(): void + public function testInstanceReusage() { $userAgents = [ 'Mozilla/5.0 (Linux; Android 4.2.2; ARCHOS 101 PLATINUM Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Safari/537.36' => [ @@ -393,7 +391,7 @@ public function testInstanceReusage(): void /** * @dataProvider getVersionTruncationFixtures */ - public function testVersionTruncation(string $useragent, int $truncationType, string $osVersion, string $clientVersion): void + public function testVersionTruncation($useragent, $truncationType, $osVersion, $clientVersion) { AbstractParser::setVersionTruncation($truncationType); $dd = new DeviceDetector($useragent); @@ -403,7 +401,7 @@ public function testVersionTruncation(string $useragent, int $truncationType, st AbstractParser::setVersionTruncation(AbstractParser::VERSION_TRUNCATION_NONE); } - public function getVersionTruncationFixtures(): array + public function getVersionTruncationFixtures() { return [ ['Mozilla/5.0 (Linux; Android 4.2.2; ARCHOS 101 PLATINUM Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Safari/537.36', AbstractParser::VERSION_TRUNCATION_NONE, '4.2.2', '34.0.1847.114'], @@ -414,7 +412,7 @@ public function getVersionTruncationFixtures(): array ]; } - public function testNotSkipDetectDeviceForClientHints(): void + public function testNotSkipDetectDeviceForClientHints() { $dd = $this->createPartialMock(Mobile::class, ['hasDesktopFragment']); @@ -454,7 +452,7 @@ public function testNotSkipDetectDeviceForClientHints(): void ]); } - public function testVersionTruncationForClientHints(): void + public function testVersionTruncationForClientHints() { AbstractParser::setVersionTruncation(AbstractParser::VERSION_TRUNCATION_MINOR); $dd = new DeviceDetector(); @@ -482,7 +480,7 @@ public function testVersionTruncationForClientHints(): void /** * @dataProvider getBotFixtures */ - public function testParseBots(array $fixtureData): void + public function testParseBots(array $fixtureData) { $ua = $fixtureData['user_agent']; $dd = new DeviceDetector($ua); @@ -528,7 +526,7 @@ public function testParseBots(array $fixtureData): void ); } - public function getBotFixtures(): array + public function getBotFixtures() { $fixturesPath = \realpath(__DIR__ . '/fixtures/bots.yml'); $fixtures = \Spyc::YAMLLoad($fixturesPath); @@ -538,7 +536,7 @@ public function getBotFixtures(): array }, $fixtures); } - public function testGetInfoFromUABot(): void + public function testGetInfoFromUABot() { $expected = [ 'user_agent' => 'Googlebot/2.1 (http://www.googlebot.com/bot.html)', @@ -555,7 +553,7 @@ public function testGetInfoFromUABot(): void $this->assertEquals($expected, DeviceDetector::getInfoFromUserAgent($expected['user_agent'])); } - public function testParseNoDetails(): void + public function testParseNoDetails() { $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $dd = new DeviceDetector($userAgent); @@ -564,7 +562,7 @@ public function testParseNoDetails(): void $this->assertEquals([true], $dd->getBot()); } - public function testMagicMMethods(): void + public function testMagicMMethods() { $ua = 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'; $dd = new DeviceDetector($ua); @@ -588,15 +586,15 @@ public function testMagicMMethods(): void $this->assertFalse($dd->isFeedReader()); } - public function testInvalidMagicMethod(): void + public function testInvalidMagicMethod() { - $this->expectException(\BadMethodCallException::class); + $this->setExpectedException('Exception'); $dd = new DeviceDetector('Mozilla/5.0'); $dd->parse(); $dd->inValidMethod(); } - public function testGetOs(): void + public function testGetOs() { $dd = new DeviceDetector('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'); $this->assertNull($dd->getOs()); @@ -611,7 +609,7 @@ public function testGetOs(): void $this->assertEquals($expected, $dd->getOs()); } - public function testGetClient(): void + public function testGetClient() { $dd = new DeviceDetector('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'); $this->assertNull($dd->getClient()); @@ -628,7 +626,7 @@ public function testGetClient(): void $this->assertEquals($expected, $dd->getClient()); } - public function getTypeMethodFixtures(): array + public function getTypeMethodFixtures() { $fixturePath = \realpath(__DIR__ . '/Parser/fixtures/type-methods.yml'); @@ -638,7 +636,7 @@ public function getTypeMethodFixtures(): array /** * @dataProvider getTypeMethodFixtures */ - public function testTypeMethods(string $ua, array $checkTypes): void + public function testTypeMethods($ua, array $checkTypes) { try { $dd = $this->getDeviceDetector(); @@ -663,28 +661,28 @@ public function testTypeMethods(string $ua, array $checkTypes): void )); } - public function testGetBrandName(): void + public function testGetBrandName() { $dd = new DeviceDetector('Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'); $dd->parse(); $this->assertEquals('Google', $dd->getBrandName()); } - public function testGetBrand(): void + public function testGetBrand() { $dd = new DeviceDetector('Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'); $dd->parse(); $this->assertEquals('GO', $dd->getBrand()); } - public function testIsTouchEnabled(): void + public function testIsTouchEnabled() { $dd = new DeviceDetector('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch; ARMBJS)'); $dd->parse(); $this->assertTrue($dd->isTouchEnabled()); } - public function testSkipBotDetection(): void + public function testSkipBotDetection() { $ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'; $dd = new DeviceDetector($ua); @@ -698,15 +696,15 @@ public function testSkipBotDetection(): void $this->assertFalse($dd->isBot()); } - public function testSetYamlParserInvalid(): void + public function testSetYamlParserInvalid() { - $this->expectException(\TypeError::class); + $this->setExpectedException('TypeError'); $dd = new DeviceDetector(); $dd->setYamlParser('Invalid'); } - public function testSetYamlParser(): void + public function testSetYamlParser() { $reader = function & ($object, $property) { $value = & Closure::bind(function & () use ($property) { @@ -739,7 +737,7 @@ public function testSetYamlParser(): void } } - public function testCheckRegexRestrictionEndCondition(): void + public function testCheckRegexRestrictionEndCondition() { $this->assertTrue($this->checkRegexRestrictionEndCondition('([^;/)]+)[;/)]'), 'skip condition'); $this->assertTrue($this->checkRegexRestrictionEndCondition('([^/;)]+)[;/)]'), 'skip condition'); @@ -754,7 +752,7 @@ public function testCheckRegexRestrictionEndCondition(): void /** * Checks the AbstractDeviceParser::$deviceBrands for duplicate brands */ - public function testDuplicateBrands(): void + public function testDuplicateBrands() { $brands = \array_map('strtolower', AbstractDeviceParser::$deviceBrands); $unique = \array_unique($brands); @@ -768,8 +766,9 @@ public function testDuplicateBrands(): void /** * check the Symfony parser for fixtures parsing errors + * @doesNotPerformAssertions */ - public function testSymfonyParser(): void + public function testSymfonyParser() { $files = \array_merge( \glob(__DIR__ . '/../regexes/client/*.yml'), @@ -781,8 +780,6 @@ public function testSymfonyParser(): void foreach ($files as $file) { $yamlSymfony->parseFile($file); } - - $this->expectNotToPerformAssertions(); } /** @@ -791,7 +788,7 @@ public function testSymfonyParser(): void * * @return bool */ - protected function checkRegexVerticalLineClosingGroup(string $regexString): bool + protected function checkRegexVerticalLineClosingGroup($regexString) { if (false !== \strpos($regexString, '|)')) { return !\preg_match('#(? 'Googlebot', @@ -33,7 +31,7 @@ public function testGetInfoFromUABot(): void $this->assertEquals($expected, $botParser->parse()); } - public function testParseNoDetails(): void + public function testParseNoDetails() { $botParser = new Bot(); $botParser->discardDetails(); @@ -41,7 +39,7 @@ public function testParseNoDetails(): void $this->assertEquals([true], $botParser->parse()); } - public function testParseNoBot(): void + public function testParseNoBot() { $botParser = new Bot(); $botParser->setUserAgent('Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; SV1; SE 2.x)'); diff --git a/Tests/Parser/Client/BrowserTest.php b/Tests/Parser/Client/BrowserTest.php index 023c9a92ae..1b44d2373d 100644 --- a/Tests/Parser/Client/BrowserTest.php +++ b/Tests/Parser/Client/BrowserTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Client; use DeviceDetector\ClientHints; @@ -26,7 +24,7 @@ class BrowserTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $client, ?array $headers = null): void + public function testParse($useragent, array $client, $headers = null) { $browserParser = new Browser(); $browserParser->setVersionTruncation(Browser::VERSION_TRUNCATION_NONE); @@ -49,32 +47,32 @@ public function testParse(string $useragent, array $client, ?array $headers = nu self::$browsersTested[] = $client['name']; } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/browser.yml'); return $fixtureData; } - public function testGetAvailableBrowserFamilies(): void + public function testGetAvailableBrowserFamilies() { $this->assertGreaterThan(5, Browser::getAvailableBrowserFamilies()); } - public function testAllBrowsersTested(): void + public function testAllBrowsersTested() { $allBrowsers = \array_values(Browser::getAvailableBrowsers()); $browsersNotTested = \array_diff($allBrowsers, self::$browsersTested); $this->assertEmpty($browsersNotTested, 'This browsers are not tested: ' . \implode(', ', $browsersNotTested)); } - public function testGetAvailableClients(): void + public function testGetAvailableClients() { $available = Browser::getAvailableClients(); $this->assertGreaterThanOrEqual(\count($available), \count(Browser::getAvailableBrowsers())); } - public function testStructureBrowsersYml(): void + public function testStructureBrowsersYml() { $ymlDataItems = Spyc::YAMLLoad(__DIR__ . '/../../../regexes/client/browsers.yml'); @@ -82,13 +80,13 @@ public function testStructureBrowsersYml(): void $this->assertTrue(\array_key_exists('regex', $item), 'key "regex" not exist'); $this->assertTrue(\array_key_exists('name', $item), 'key "name" not exist'); $this->assertTrue(\array_key_exists('version', $item), 'key "version" not exist'); - $this->assertIsString($item['regex']); - $this->assertIsString($item['name']); - $this->assertIsString($item['version']); + $this->assertNotNull($item['regex']); + $this->assertNotNull($item['name']); + $this->assertNotNull($item['version']); } } - public function testBrowserFamiliesNoDuplicates(): void + public function testBrowserFamiliesNoDuplicates() { $browsers = Browser::getAvailableBrowserFamilies(); @@ -108,7 +106,7 @@ public function testBrowserFamiliesNoDuplicates(): void /** * @return array */ - public function getFixturesBrowserHints(): array + public function getFixturesBrowserHints() { $method = new \ReflectionMethod(BrowserHints::class, 'getRegexes'); $method->setAccessible(true); @@ -125,7 +123,7 @@ public function getFixturesBrowserHints(): array /** * @dataProvider getFixturesBrowserHints */ - public function testBrowserHintsForAvailableBrowsers(string $name): void + public function testBrowserHintsForAvailableBrowsers($name) { $browserShort = Browser::getBrowserShortName($name); $this->assertNotEquals( @@ -135,7 +133,7 @@ public function testBrowserHintsForAvailableBrowsers(string $name): void ); } - protected function checkBrowserEngine(string $engine): bool + protected function checkBrowserEngine($engine) { if ('' === $engine) { return true; @@ -143,8 +141,8 @@ protected function checkBrowserEngine(string $engine): bool $engines = Engine::getAvailableEngines(); $enginePos = \array_search($engine, $engines, false); - $engineReference = $engines[$enginePos] ?? null; + $engineReference = $engines[$enginePos] || null; - return $engineReference === $engine; + return $engineReference == $engine; } } diff --git a/Tests/Parser/Client/FeedReaderTest.php b/Tests/Parser/Client/FeedReaderTest.php index c8fd3ca74a..6f7f96d900 100644 --- a/Tests/Parser/Client/FeedReaderTest.php +++ b/Tests/Parser/Client/FeedReaderTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Client; use DeviceDetector\Parser\Client\FeedReader; @@ -21,7 +19,7 @@ class FeedReaderTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $client): void + public function testParse($useragent, array $client) { $feedReaderParser = new FeedReader(); $feedReaderParser->setVersionTruncation(FeedReader::VERSION_TRUNCATION_NONE); @@ -29,14 +27,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $feedReaderParser->parse(), "UserAgent: {$useragent}"); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/feed_reader.yml'); return $fixtureData; } - public function testStructureFeedReaderYml(): void + public function testStructureFeedReaderYml() { $ymlDataItems = Spyc::YAMLLoad(__DIR__ . '/../../../regexes/client/feed_readers.yml'); @@ -45,10 +43,10 @@ public function testStructureFeedReaderYml(): void $this->assertTrue(\array_key_exists('name', $item), 'key "name" not exist'); $this->assertTrue(\array_key_exists('version', $item), 'key "version" not exist'); $this->assertTrue(\array_key_exists('url', $item), 'key "url" not exist'); - $this->assertIsString($item['regex']); - $this->assertIsString($item['name']); - $this->assertIsString($item['version']); - $this->assertIsString($item['url']); + $this->assertNotNull($item['regex']); + $this->assertNotNull($item['name']); + $this->assertNotNull($item['version']); + $this->assertNotNull($item['url']); } } } diff --git a/Tests/Parser/Client/LibraryTest.php b/Tests/Parser/Client/LibraryTest.php index a9baa68ee3..017a4f47ce 100644 --- a/Tests/Parser/Client/LibraryTest.php +++ b/Tests/Parser/Client/LibraryTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Client; use DeviceDetector\Parser\Client\Library; @@ -21,7 +19,7 @@ class LibraryTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $client): void + public function testParse($useragent, array $client) { $libraryParser = new Library(); $libraryParser->setVersionTruncation(Library::VERSION_TRUNCATION_NONE); @@ -29,14 +27,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $libraryParser->parse()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/library.yml'); return $fixtureData; } - public function testStructureLibraryYml(): void + public function testStructureLibraryYml() { $ymlDataItems = Spyc::YAMLLoad(__DIR__ . '/../../../regexes/client/libraries.yml'); @@ -44,9 +42,9 @@ public function testStructureLibraryYml(): void $this->assertTrue(\array_key_exists('regex', $item), 'key "regex" not exist'); $this->assertTrue(\array_key_exists('name', $item), 'key "name" not exist'); $this->assertTrue(\array_key_exists('version', $item), 'key "version" not exist'); - $this->assertIsString($item['regex']); - $this->assertIsString($item['name']); - $this->assertIsString($item['version']); + $this->assertNotNull($item['regex']); + $this->assertNotNull($item['name']); + $this->assertNotNull($item['version']); } } } diff --git a/Tests/Parser/Client/MediaPlayerTest.php b/Tests/Parser/Client/MediaPlayerTest.php index b8ca8482ea..578ac030a7 100644 --- a/Tests/Parser/Client/MediaPlayerTest.php +++ b/Tests/Parser/Client/MediaPlayerTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Client; use DeviceDetector\Parser\Client\MediaPlayer; @@ -21,7 +19,7 @@ class MediaPlayerTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $client): void + public function testParse($useragent, array $client) { $mediaPlayerParser = new MediaPlayer(); $mediaPlayerParser->setVersionTruncation(MediaPlayer::VERSION_TRUNCATION_NONE); @@ -29,14 +27,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $mediaPlayerParser->parse()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/mediaplayer.yml'); return $fixtureData; } - public function testStructureMediaPlayerYml(): void + public function testStructureMediaPlayerYml() { $ymlDataItems = Spyc::YAMLLoad(__DIR__ . '/../../../regexes/client/mediaplayers.yml'); @@ -44,9 +42,9 @@ public function testStructureMediaPlayerYml(): void $this->assertTrue(\array_key_exists('regex', $item), 'key "regex" not exist'); $this->assertTrue(\array_key_exists('name', $item), 'key "name" not exist'); $this->assertTrue(\array_key_exists('version', $item), 'key "version" not exist'); - $this->assertIsString($item['regex']); - $this->assertIsString($item['name']); - $this->assertIsString($item['version']); + $this->assertNotNull($item['regex']); + $this->assertNotNull($item['name']); + $this->assertNotNull($item['version']); } } } diff --git a/Tests/Parser/Client/MobileAppTest.php b/Tests/Parser/Client/MobileAppTest.php index c15da0f6a2..8ac73184cb 100644 --- a/Tests/Parser/Client/MobileAppTest.php +++ b/Tests/Parser/Client/MobileAppTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Client; use DeviceDetector\Parser\Client\MobileApp; @@ -21,7 +19,7 @@ class MobileAppTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $client): void + public function testParse($useragent, array $client) { $mobileAppParser = new MobileApp(); $mobileAppParser->setVersionTruncation(MobileApp::VERSION_TRUNCATION_NONE); @@ -29,14 +27,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $mobileAppParser->parse()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/mobile_app.yml'); return $fixtureData; } - public function testStructureMobileAppYml(): void + public function testStructureMobileAppYml() { $ymlDataItems = Spyc::YAMLLoad(__DIR__ . '/../../../regexes/client/mobile_apps.yml'); diff --git a/Tests/Parser/Client/PIMTest.php b/Tests/Parser/Client/PIMTest.php index 27a389143c..209f5077e7 100644 --- a/Tests/Parser/Client/PIMTest.php +++ b/Tests/Parser/Client/PIMTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Client; use DeviceDetector\Parser\Client\PIM; @@ -21,7 +19,7 @@ class PIMTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $client): void + public function testParse($useragent, array $client) { $PIMParser = new PIM(); $PIMParser->setVersionTruncation(PIM::VERSION_TRUNCATION_NONE); @@ -29,14 +27,14 @@ public function testParse(string $useragent, array $client): void $this->assertEquals($client, $PIMParser->parse()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/pim.yml'); return $fixtureData; } - public function testStructurePimYml(): void + public function testStructurePimYml() { $ymlDataItems = Spyc::YAMLLoad(__DIR__ . '/../../../regexes/client/pim.yml'); @@ -44,9 +42,9 @@ public function testStructurePimYml(): void $this->assertTrue(\array_key_exists('regex', $item), 'key "regex" not exist'); $this->assertTrue(\array_key_exists('name', $item), 'key "name" not exist'); $this->assertTrue(\array_key_exists('version', $item), 'key "version" not exist'); - $this->assertIsString($item['regex']); - $this->assertIsString($item['name']); - $this->assertIsString($item['version']); + $this->assertNotNull($item['regex']); + $this->assertNotNull($item['name']); + $this->assertNotNull($item['version']); } } } diff --git a/Tests/Parser/Device/CameraTest.php b/Tests/Parser/Device/CameraTest.php index c429fe2bb6..d6dfe48265 100644 --- a/Tests/Parser/Device/CameraTest.php +++ b/Tests/Parser/Device/CameraTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\Camera; @@ -21,7 +19,7 @@ class CameraTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $device): void + public function testParse($useragent, array $device) { $consoleParser = new Camera(); $consoleParser->setUserAgent($useragent); @@ -31,7 +29,7 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $consoleParser->getModel()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/camera.yml'); diff --git a/Tests/Parser/Device/CarBrowserTest.php b/Tests/Parser/Device/CarBrowserTest.php index 2758e07dd1..fa02486906 100644 --- a/Tests/Parser/Device/CarBrowserTest.php +++ b/Tests/Parser/Device/CarBrowserTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\CarBrowser; @@ -21,7 +19,7 @@ class CarBrowserTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $device): void + public function testParse($useragent, array $device) { $consoleParser = new CarBrowser(); $consoleParser->setUserAgent($useragent); @@ -31,7 +29,7 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $consoleParser->getModel()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/car_browser.yml'); diff --git a/Tests/Parser/Device/ConsoleTest.php b/Tests/Parser/Device/ConsoleTest.php index 83c4593978..6858c2a4f1 100644 --- a/Tests/Parser/Device/ConsoleTest.php +++ b/Tests/Parser/Device/ConsoleTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\Console; @@ -21,7 +19,7 @@ class ConsoleTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $device): void + public function testParse($useragent, array $device) { $consoleParser = new Console(); $consoleParser->setUserAgent($useragent); @@ -31,7 +29,7 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $consoleParser->getModel()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/console.yml'); diff --git a/Tests/Parser/Device/DeviceParserAbstractTest.php b/Tests/Parser/Device/DeviceParserAbstractTest.php index a244182043..681fed1ba8 100644 --- a/Tests/Parser/Device/DeviceParserAbstractTest.php +++ b/Tests/Parser/Device/DeviceParserAbstractTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\AbstractDeviceParser; @@ -17,21 +15,21 @@ class DeviceParserAbstractTest extends TestCase { - public function testGetAvailableDeviceTypes(): void + public function testGetAvailableDeviceTypes() { $available = AbstractDeviceParser::getAvailableDeviceTypes(); $this->assertGreaterThan(5, \count($available)); $this->assertContains('desktop', \array_keys($available)); } - public function testGetAvailableDeviceTypeNames(): void + public function testGetAvailableDeviceTypeNames() { $available = AbstractDeviceParser::getAvailableDeviceTypeNames(); $this->assertGreaterThan(5, \count($available)); $this->assertContains('desktop', $available); } - public function testGetFullName(): void + public function testGetFullName() { $this->assertEquals('', AbstractDeviceParser::getFullName('Invalid')); $this->assertEquals('Asus', AbstractDeviceParser::getFullName('AU')); diff --git a/Tests/Parser/Device/HbbTvTest.php b/Tests/Parser/Device/HbbTvTest.php index 0d640ce669..460a2e2217 100644 --- a/Tests/Parser/Device/HbbTvTest.php +++ b/Tests/Parser/Device/HbbTvTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\HbbTv; @@ -17,7 +15,7 @@ class HbbTvTest extends TestCase { - public function testIsHbbTv(): void + public function testIsHbbTv() { $hbbTvParser = new HbbTv(); $hbbTvParser->setUserAgent('Opera/9.80 (Linux mips ; U; HbbTV/1.1.1 (; Philips; ; ; ; ) CE-HTML/1.0 NETTV/3.2.1; en) Presto/2.6.33 Version/10.70'); diff --git a/Tests/Parser/Device/NotebookTest.php b/Tests/Parser/Device/NotebookTest.php index 9801229341..e121fa9044 100644 --- a/Tests/Parser/Device/NotebookTest.php +++ b/Tests/Parser/Device/NotebookTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\Notebook; @@ -21,7 +19,7 @@ class NotebookTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $device): void + public function testParse($useragent, array $device) { $notebookParser = new Notebook(); $notebookParser->setUserAgent($useragent); @@ -31,7 +29,7 @@ public function testParse(string $useragent, array $device): void $this->assertEquals($device['model'], $notebookParser->getModel()); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/notebook.yml'); diff --git a/Tests/Parser/Device/ShellTvTest.php b/Tests/Parser/Device/ShellTvTest.php index db71ea0b10..012b5bb58e 100644 --- a/Tests/Parser/Device/ShellTvTest.php +++ b/Tests/Parser/Device/ShellTvTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser\Device; use DeviceDetector\Parser\Device\ShellTv; @@ -17,7 +15,7 @@ class ShellTvTest extends TestCase { - public function testIsShellTv(): void + public function testIsShellTv() { $dd = new ShellTv(); $dd->setUserAgent('Leff Shell LC390TA2A'); diff --git a/Tests/Parser/OperatingSystemTest.php b/Tests/Parser/OperatingSystemTest.php index e68a2609a4..c30299ed63 100644 --- a/Tests/Parser/OperatingSystemTest.php +++ b/Tests/Parser/OperatingSystemTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser; use DeviceDetector\ClientHints; @@ -24,7 +22,7 @@ class OperatingSystemTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, array $os, ?array $headers = null): void + public function testParse($useragent, array $os, $headers = null) { $osParser = new OperatingSystem(); $osParser->setUserAgent($useragent); @@ -37,7 +35,7 @@ public function testParse(string $useragent, array $os, ?array $headers = null): self::$osTested[] = $os['name']; } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/oss.yml'); @@ -47,13 +45,13 @@ public function getFixtures(): array /** * @dataProvider getAllOs */ - public function testOSInGroup(string $os): void + public function testOSInGroup($os) { $familyOs = \call_user_func_array('array_merge', \array_values(OperatingSystem::getAvailableOperatingSystemFamilies())); $this->assertContains($os, $familyOs); } - public function getAllOs(): array + public function getAllOs() { $allOs = \array_keys(OperatingSystem::getAvailableOperatingSystems()); $allOs = \array_map(static function ($os) { @@ -66,13 +64,13 @@ public function getAllOs(): array /** * @dataProvider getAllFamilyOs */ - public function testFamilyOSExists(string $os): void + public function testFamilyOSExists($os) { $allOs = \array_keys(OperatingSystem::getAvailableOperatingSystems()); $this->assertContains($os, $allOs); } - public function getAllFamilyOs(): array + public function getAllFamilyOs() { $allFamilyOs = \call_user_func_array('array_merge', \array_values(OperatingSystem::getAvailableOperatingSystemFamilies())); $allFamilyOs = \array_map(static function ($os) { @@ -82,7 +80,7 @@ public function getAllFamilyOs(): array return $allFamilyOs; } - public function testGetAvailableOperatingSystems(): void + public function testGetAvailableOperatingSystems() { $this->assertGreaterThan(70, OperatingSystem::getAvailableOperatingSystems()); } @@ -90,12 +88,12 @@ public function testGetAvailableOperatingSystems(): void /** * @dataProvider getNameFromIds */ - public function testGetNameFromId(string $os, string $version, ?string $expected): void + public function testGetNameFromId($os, $version, $expected) { $this->assertEquals($expected, OperatingSystem::getNameFromId($os, $version)); } - public function getNameFromIds(): array + public function getNameFromIds() { return [ ['DEB', '4.5', 'Debian 4.5'], @@ -105,7 +103,7 @@ public function getNameFromIds(): array ]; } - public function testAllOperatingSystemsTested(): void + public function testAllOperatingSystemsTested() { $allBrowsers = OperatingSystem::getAvailableOperatingSystems(); $osNotTested = \array_diff($allBrowsers, self::$osTested); diff --git a/Tests/Parser/VendorFragmentTest.php b/Tests/Parser/VendorFragmentTest.php index fbeb7af4c4..0e95063753 100644 --- a/Tests/Parser/VendorFragmentTest.php +++ b/Tests/Parser/VendorFragmentTest.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Tests\Parser; use DeviceDetector\Parser\VendorFragment; @@ -23,7 +21,7 @@ class VendorFragmentTest extends TestCase /** * @dataProvider getFixtures */ - public function testParse(string $useragent, string $vendor): void + public function testParse($useragent, $vendor) { $vfParser = new VendorFragment(); $vfParser->setUserAgent($useragent); @@ -31,14 +29,14 @@ public function testParse(string $useragent, string $vendor): void self::$regexesTested[] = $vfParser->getMatchedRegex(); } - public function getFixtures(): array + public function getFixtures() { $fixtureData = Spyc::YAMLLoad(\realpath(__DIR__) . '/fixtures/vendorfragments.yml'); return $fixtureData; } - public function testAllRegexesTested(): void + public function testAllRegexesTested() { $regexesNotTested = []; diff --git a/Yaml/ParserInterface.php b/Yaml/ParserInterface.php index e3aa2f017a..4581e99d6b 100644 --- a/Yaml/ParserInterface.php +++ b/Yaml/ParserInterface.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Yaml; interface ParserInterface @@ -21,5 +19,5 @@ interface ParserInterface * * @return mixed */ - public function parseFile(string $file); + public function parseFile($file); } diff --git a/Yaml/Pecl.php b/Yaml/Pecl.php index ba30efb11b..5acaad96dd 100644 --- a/Yaml/Pecl.php +++ b/Yaml/Pecl.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Yaml; use Exception; @@ -31,7 +29,7 @@ class Pecl implements ParserInterface * * @throws Exception If the YAML extension is not installed */ - public function parseFile(string $file) + public function parseFile($file) { if (false === \function_exists('yaml_parse_file')) { throw new Exception('Pecl YAML extension is not installed'); diff --git a/Yaml/Spyc.php b/Yaml/Spyc.php index 24d0110b0a..eb3c1ba3b9 100644 --- a/Yaml/Spyc.php +++ b/Yaml/Spyc.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Yaml; use Spyc as SpycParser; @@ -23,7 +21,7 @@ class Spyc implements ParserInterface * * @return mixed */ - public function parseFile(string $file) + public function parseFile($file) { return SpycParser::YAMLLoad($file); } diff --git a/Yaml/Symfony.php b/Yaml/Symfony.php index 00bd6917d4..1592ec97f8 100644 --- a/Yaml/Symfony.php +++ b/Yaml/Symfony.php @@ -8,8 +8,6 @@ * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later */ -declare(strict_types=1); - namespace DeviceDetector\Yaml; use Symfony\Component\Yaml\Yaml; @@ -23,7 +21,7 @@ class Symfony implements ParserInterface * * @return mixed */ - public function parseFile(string $file) + public function parseFile($file) { return Yaml::parseFile($file); } diff --git a/autoload.php b/autoload.php index 34acb171d3..44fd205041 100644 --- a/autoload.php +++ b/autoload.php @@ -1,7 +1,5 @@ =5.6.0", "mustangostang/spyc": "*" }, "require-dev": { - "phpunit/phpunit": "^8.5.8", + "phpunit/phpunit": "^5.7.0", "psr/cache": "^1.0.1", "psr/simple-cache": "^1.0.1", "matthiasmullie/scrapbook": "^1.4.7", - "phpstan/phpstan": "^1.10.44", - "mayflower/mo4-coding-standard": "^v9.0.0", - "symfony/yaml": "^5.1.7" + "mayflower/mo4-coding-standard": "^v2.0.0", + "symfony/yaml": "^3.0.0" }, "suggest": { "doctrine/cache": "Can directly be used for caching purpose", diff --git a/misc/fileTest.php b/misc/fileTest.php index f1820ba200..3d7d00b334 100644 --- a/misc/fileTest.php +++ b/misc/fileTest.php @@ -25,8 +25,6 @@ * `php file-test.php /tmp/source-useragent.txt "not" "useragent" > /tmp/useragent-not-detected.txt` */ -declare(strict_types=1); - use DeviceDetector\DeviceDetector; use DeviceDetector\Parser\Device\AbstractDeviceParser; @@ -48,11 +46,11 @@ define('REPORT_TYPE_YML', 'yml'); define('REPORT_TYPE_USERAGENT', 'useragent'); -$file = $argv[1] ?? ''; -$showMode = $argv[2] ?? 'not'; -$reportMode = $argv[3] ?? 'yml'; +$file = isset($argv[1]) ? $argv[1] : ''; +$showMode = isset($argv[2]) ? $argv[2] : 'not'; +$reportMode = isset($argv[3]) ? $argv[3] : 'yml'; -function printHelpAndExit(): void +function printHelpAndExit() { echo "Usage command:\n"; echo "php file-test.php > report.txt\n\n"; @@ -75,7 +73,7 @@ function printHelpAndExit(): void * @param array $result * @param string $format */ -function printReport(array $result, string $format): void +function printReport(array $result, $format) { if (REPORT_TYPE_YML === $format) { echo Spyc::YAMLDump($result, 2, 0); diff --git a/misc/generateBrandIdFree.php b/misc/generateBrandIdFree.php index cfdbd92a7a..28025e3cd8 100644 --- a/misc/generateBrandIdFree.php +++ b/misc/generateBrandIdFree.php @@ -1,7 +1,5 @@