Skip to content

Commit

Permalink
Update phpstan action (#7522)
Browse files Browse the repository at this point in the history
* Update phpstan action

* update phpstan dependency

* Fix newly detected PHPStan issues
  • Loading branch information
sgiehl authored Nov 29, 2023
1 parent 1ce0b07 commit 11b8935
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 26 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ jobs:
runs-on: ubuntu-latest

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

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
- uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
args: analyse -c phpstan.neon
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
1 change: 1 addition & 0 deletions ClientHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public function getBrandList(): array
$versions = \array_column($this->fullVersionList, 'version');

if (\count($brands) === \count($versions)) {
// @phpstan-ignore-next-line
return \array_combine($brands, $versions);
}
}
Expand Down
4 changes: 2 additions & 2 deletions DeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ class DeviceDetector

/**
* Holds the cache class used for caching the parsed yml-Files
* @var CacheInterface
* @var CacheInterface|null
*/
protected $cache = null;

/**
* Holds the parser class used for parsing yml-Files
* @var YamlParser
* @var YamlParser|null
*/
protected $yamlParser = null;

Expand Down
32 changes: 23 additions & 9 deletions Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ abstract class AbstractParser
public const VERSION_TRUNCATION_NONE = -1;

/**
* @var CacheInterface
* @var CacheInterface|null
*/
protected $cache;
protected $cache = null;

/**
* @var YamlParser
* @var YamlParser|null
*/
protected $yamlParser;
protected $yamlParser = null;

/**
* parses the currently set useragents and returns possible results
Expand Down Expand Up @@ -244,14 +244,24 @@ public function getYamlParser(): YamlParser
protected function getRegexes(): array
{
if (empty($this->regexList)) {
$cacheKey = 'DeviceDetector-' . DeviceDetector::VERSION . 'regexes-' . $this->getName();
$cacheKey = (string) \preg_replace('/([^a-z0-9_-]+)/i', '', $cacheKey);
$this->regexList = $this->getCache()->fetch($cacheKey);
$cacheKey = 'DeviceDetector-' . DeviceDetector::VERSION . 'regexes-' . $this->getName();
$cacheKey = (string) \preg_replace('/([^a-z0-9_-]+)/i', '', $cacheKey);
$cacheContent = $this->getCache()->fetch($cacheKey);

if (\is_array($cacheContent)) {
$this->regexList = $cacheContent;
}

if (empty($this->regexList)) {
$this->regexList = $this->getYamlParser()->parseFile(
$parsedContent = $this->getYamlParser()->parseFile(
$this->getRegexesDirectory() . DIRECTORY_SEPARATOR . $this->fixtureFile
);

if (!\is_array($parsedContent)) {
$parsedContent = [];
}

$this->regexList = $parsedContent;
$this->getCache()->save($cacheKey, $this->regexList);
}
}
Expand Down Expand Up @@ -385,7 +395,11 @@ protected function preMatchOverall(): ?array
$cacheKey = (string) \preg_replace('/([^a-z0-9_-]+)/i', '', $cacheKey);

if (empty($this->overAllMatch)) {
$this->overAllMatch = $this->getCache()->fetch($cacheKey);
$overAllMatch = $this->getCache()->fetch($cacheKey);

if (\is_string($overAllMatch)) {
$this->overAllMatch = $overAllMatch;
}
}

if (empty($this->overAllMatch)) {
Expand Down
2 changes: 1 addition & 1 deletion Parser/Client/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class Browser extends AbstractClientParser
{
/**
* @var BrowserHints|null
* @var BrowserHints
*/
private $browserHints;

Expand Down
2 changes: 1 addition & 1 deletion Parser/Client/MobileApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class MobileApp extends AbstractClientParser
{
/**
* @var AppHints|null
* @var AppHints
*/
private $appHints;

Expand Down
16 changes: 11 additions & 5 deletions Parser/Device/AbstractDeviceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1830,11 +1830,17 @@ public static function getAvailableDeviceTypeNames(): array
*
* @param int $deviceType one of the DEVICE_TYPE_* constants
*
* @return mixed
* @return string
*/
public static function getDeviceName(int $deviceType)
public static function getDeviceName(int $deviceType): string
{
return \array_search($deviceType, self::$deviceTypes);
$deviceName = \array_search($deviceType, self::$deviceTypes);

if (\is_string($deviceName)) {
return $deviceName;
}

return '';
}

/**
Expand Down Expand Up @@ -1908,8 +1914,8 @@ public function parse(): ?array

// 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)) {
$osVersion = $this->clientHints->getOperatingSystemVersion();
$this->setUserAgent(\preg_replace(
$osVersion = $this->clientHints ? $this->clientHints->getOperatingSystemVersion() : '';
$this->setUserAgent((string) \preg_replace(
'(Android 10[.\d]*; K)',
\sprintf('Android %s; %s', '' !== $osVersion ? $osVersion : '10', $deviceModel),
$this->userAgent
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"psr/cache": "^1.0.1",
"psr/simple-cache": "^1.0.1",
"matthiasmullie/scrapbook": "^1.4.7",
"phpstan/phpstan": "^0.12.52",
"phpstan/phpstan": "^1.10.44",
"mayflower/mo4-coding-standard": "^v8.0.0",
"symfony/yaml": "^5.1.7"
},
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ parameters:
- %rootDir%/../../autoload.php
paths:
- %rootDir%/../../../
excludes_analyse:
excludePaths:
- %rootDir%/../../../vendor
- %rootDir%/../../../misc
- %rootDir%/../../../Tests
- %rootDir%/../../../autoload.php
ignoreErrors:
- '#.+Doctrine\\Common\\Cache\\CacheProvider.+#'
- '#.+unknown class Illuminate\\Support\\Facades\\Cache.+#'
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false

0 comments on commit 11b8935

Please sign in to comment.