mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 08:52:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -59,11 +59,9 @@ class Agent extends MobileDetect
|
||||
*/
|
||||
public function platform()
|
||||
{
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.platform', function () {
|
||||
return $this->findDetectionRulesAgainstUserAgent(
|
||||
$this->mergeRules(MobileDetect::getOperatingSystems(), static::$additionalOperatingSystems)
|
||||
);
|
||||
});
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.platform', fn () => $this->findDetectionRulesAgainstUserAgent(
|
||||
$this->mergeRules(MobileDetect::getOperatingSystems(), static::$additionalOperatingSystems)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,11 +71,9 @@ public function platform()
|
||||
*/
|
||||
public function browser()
|
||||
{
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.browser', function () {
|
||||
return $this->findDetectionRulesAgainstUserAgent(
|
||||
$this->mergeRules(static::$additionalBrowsers, MobileDetect::getBrowsers())
|
||||
);
|
||||
});
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.browser', fn () => $this->findDetectionRulesAgainstUserAgent(
|
||||
$this->mergeRules(static::$additionalBrowsers, MobileDetect::getBrowsers())
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +83,7 @@ public function browser()
|
||||
*/
|
||||
public function isDesktop()
|
||||
{
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.desktop', function () {
|
||||
return $this->retrieveUsingCacheOrResolve('paymently.desktop', function (): bool {
|
||||
// Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront'
|
||||
if (
|
||||
$this->getUserAgent() === static::$cloudFrontUA
|
||||
@ -103,19 +99,24 @@ public function isDesktop()
|
||||
/**
|
||||
* Match a detection rule and return the matched key.
|
||||
*
|
||||
* @param array<mixed, string> $rules
|
||||
* @return string|null
|
||||
*/
|
||||
protected function findDetectionRulesAgainstUserAgent(array $rules)
|
||||
{
|
||||
$userAgent = $this->getUserAgent();
|
||||
|
||||
if ($userAgent === null || $userAgent === '' || $userAgent === '0') {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($rules as $key => $regex) {
|
||||
if (empty($regex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->match($regex, $userAgent)) {
|
||||
return $key ?: reset($this->matchesArray);
|
||||
return $key !== 0 && ($key !== '' && $key !== '0') ? $key : reset($this->matchesArray);
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ protected function retrieveUsingCacheOrResolve(string $key, Closure $callback)
|
||||
return $cacheItem;
|
||||
}
|
||||
|
||||
return tap(call_user_func($callback), function ($result) use ($cacheKey) {
|
||||
return tap(call_user_func($callback), function ($result) use ($cacheKey): void {
|
||||
$this->store[$cacheKey] = $result;
|
||||
});
|
||||
}
|
||||
@ -144,10 +145,10 @@ protected function retrieveUsingCacheOrResolve(string $key, Closure $callback)
|
||||
/**
|
||||
* Merge multiple rules into one array.
|
||||
*
|
||||
* @param array $all
|
||||
* @param array<mixed> $all
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function mergeRules(...$all)
|
||||
protected function mergeRules(...$all): array
|
||||
{
|
||||
$merged = [];
|
||||
|
||||
|
Reference in New Issue
Block a user