Skip to content

Commit

Permalink
Fix for mixing simple cache with PSR6 cache implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Serban Ghita committed Dec 9, 2024
1 parent 7d70be1 commit c348bc5
Show file tree
Hide file tree
Showing 3 changed files with 4,859 additions and 4,835 deletions.
19 changes: 18 additions & 1 deletion src/Cache/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Detection\Cache;

use Psr\Cache\CacheItemInterface;

/**
* Simple cache item (key, value, ttl) that is being
* used by all the detection methods of Mobile Detect class.
*/
class CacheItem
class CacheItem implements CacheItemInterface
{
/**
* @var string Unique key for the cache record.
Expand Down Expand Up @@ -45,4 +47,19 @@ public function getTtl(): int|null
{
return $this->ttl;
}

public function isHit()

Check failure on line 51 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8, ubuntu-latest, latest, ^9.6.18)

Return type mixed of method Detection\Cache\CacheItem::isHit() is not covariant with return type bool of method Psr\Cache\CacheItemInterface::isHit().

Check failure on line 51 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8.4, ubuntu-latest, latest, ^9.6.18)

Return type mixed of method Detection\Cache\CacheItem::isHit() is not covariant with return type bool of method Psr\Cache\CacheItemInterface::isHit().
{
// TODO: Implement isHit() method.

Check failure on line 53 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8, ubuntu-latest, latest, ^9.6.18)

Method Detection\Cache\CacheItem::isHit() should return bool but return statement is missing.

Check failure on line 53 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8.4, ubuntu-latest, latest, ^9.6.18)

Method Detection\Cache\CacheItem::isHit() should return bool but return statement is missing.
}

public function expiresAt($expiration)

Check failure on line 56 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8, ubuntu-latest, latest, ^9.6.18)

Return type mixed of method Detection\Cache\CacheItem::expiresAt() is not covariant with return type static(Psr\Cache\CacheItemInterface) of method Psr\Cache\CacheItemInterface::expiresAt().

Check failure on line 56 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8.4, ubuntu-latest, latest, ^9.6.18)

Return type mixed of method Detection\Cache\CacheItem::expiresAt() is not covariant with return type static(Psr\Cache\CacheItemInterface) of method Psr\Cache\CacheItemInterface::expiresAt().
{
// TODO: Implement expiresAt() method.

Check failure on line 58 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8, ubuntu-latest, latest, ^9.6.18)

Method Detection\Cache\CacheItem::expiresAt() should return static(Detection\Cache\CacheItem) but return statement is missing.

Check failure on line 58 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8.4, ubuntu-latest, latest, ^9.6.18)

Method Detection\Cache\CacheItem::expiresAt() should return static(Detection\Cache\CacheItem) but return statement is missing.
}

public function expiresAfter($time)

Check failure on line 61 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8, ubuntu-latest, latest, ^9.6.18)

Return type mixed of method Detection\Cache\CacheItem::expiresAfter() is not covariant with return type static(Psr\Cache\CacheItemInterface) of method Psr\Cache\CacheItemInterface::expiresAfter().

Check failure on line 61 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8.4, ubuntu-latest, latest, ^9.6.18)

Return type mixed of method Detection\Cache\CacheItem::expiresAfter() is not covariant with return type static(Psr\Cache\CacheItemInterface) of method Psr\Cache\CacheItemInterface::expiresAfter().
{
// TODO: Implement expiresAfter() method.

Check failure on line 63 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8, ubuntu-latest, latest, ^9.6.18)

Method Detection\Cache\CacheItem::expiresAfter() should return static(Detection\Cache\CacheItem) but return statement is missing.

Check failure on line 63 in src/Cache/CacheItem.php

View workflow job for this annotation

GitHub Actions / run (8.4, ubuntu-latest, latest, ^9.6.18)

Method Detection\Cache\CacheItem::expiresAfter() should return static(Detection\Cache\CacheItem) but return statement is missing.
}
}
19 changes: 16 additions & 3 deletions src/MobileDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Detection\Cache\Cache;
use Detection\Cache\CacheException;
use Detection\Exception\MobileDetectException;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\InvalidArgumentException;
use Psr\SimpleCache\CacheInterface;

Expand Down Expand Up @@ -1409,7 +1410,11 @@ public function isMobile(): bool
$cacheKey = $this->createCacheKey("mobile");
$cacheItem = $this->cache->get($cacheKey);
if ($cacheItem !== null) {
return $cacheItem->get();
if ($cacheItem instanceof CacheItemInterface) {
return $cacheItem->get();
} else {
return $cacheItem;
}
}

// Special case: Amazon CloudFront mobile viewer
Expand Down Expand Up @@ -1455,7 +1460,11 @@ public function isTablet(): bool
$cacheKey = $this->createCacheKey("tablet");
$cacheItem = $this->cache->get($cacheKey);
if ($cacheItem !== null) {
return $cacheItem->get();
if ($cacheItem instanceof CacheItemInterface) {
return $cacheItem->get();
} else {
return $cacheItem;
}
}

// Special case: Amazon CloudFront mobile viewer
Expand Down Expand Up @@ -1524,7 +1533,11 @@ public function is(string $ruleName): bool
$cacheKey = $this->createCacheKey($ruleName);
$cacheItem = $this->cache->get($cacheKey);
if ($cacheItem !== null) {
return $cacheItem->get();
if ($cacheItem instanceof CacheItemInterface) {
return $cacheItem->get();
} else {
return $cacheItem;
}
}

$result = $this->matchUserAgentWithRule($ruleName);
Expand Down
Loading

0 comments on commit c348bc5

Please sign in to comment.