Skip to content

Commit

Permalink
Support PHP 8.4 (#191)
Browse files Browse the repository at this point in the history
* Support PHP 8.4

* Add tests in GitHub Action

* Explicitly declare nullable parameters as nullable

* Supply a default value for defaultTtl

* Adjust dependency versions

Many of the dependencies were outdated and did not support the full
range of PHP versions supported by this project at both extremes,
specifically the lowest optioned versions of the following dependencies
did not support PHP 8.4:

- guzzlehttp/guzzle
- guzzlehttp/promises
- guzzlehttp/psr7
- phpunit/phpunit
- symfony/phpunit-bridge

Meanwhile the highest possible version of each of the above already
supported PHP 8.1 and above, including PHP 8.4.
  • Loading branch information
andrewnicols authored Oct 17, 2024
1 parent 7e4e9ee commit 61305ed
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
php-versions: ['8.1', '8.2', '8.3', '8.4']
dependencies:
- "lowest"
- "highest"
Expand All @@ -29,7 +29,7 @@ jobs:
with:
dependency-versions: "${{ matrix.dependencies }}"
env:
COMPOSER_PROCESS_TIMEOUT: 6000
COMPOSER_PROCESS_TIMEOUT: 6000

- name: Run test suite
run: composer run-script test
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
],
"require": {
"php": ">=8.1",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"guzzlehttp/promises": "^1.4 || ^2.0",
"guzzlehttp/psr7": "^1.7.0 || ^2.0.0"
"guzzlehttp/guzzle": "^7.9.2",
"guzzlehttp/promises": "^2.0.3",
"guzzlehttp/psr7": "^2.7.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5.15 || ^9.5",
"phpunit/phpunit": "^9.6.21",
"doctrine/cache": "^1.10",
"league/flysystem": "^2.5",
"psr/cache": "^1.0",
"cache/array-adapter": "^0.4 || ^0.5 || ^1.0",
"illuminate/cache": "^5.0",
"cache/simple-cache-bridge": "^0.1 || ^1.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0",
"symfony/phpunit-bridge": "^7.1.4",
"symfony/cache": "^4.4 || ^5.0"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions src/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function __construct(
RequestInterface $request,
ResponseInterface $response,
\DateTime $staleAt,
\DateTime $staleIfErrorTo = null,
\DateTime $staleWhileRevalidateTo = null
?\DateTime $staleIfErrorTo = null,
?\DateTime $staleWhileRevalidateTo = null
) {
$this->dateCreated = new \DateTime();

Expand Down
8 changes: 4 additions & 4 deletions src/CacheMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CacheMiddleware
/**
* @param CacheStrategyInterface|null $cacheStrategy
*/
public function __construct(CacheStrategyInterface $cacheStrategy = null)
public function __construct(?CacheStrategyInterface $cacheStrategy = null)
{
$this->cacheStorage = $cacheStrategy !== null ? $cacheStrategy : new PrivateCacheStrategy();

Expand Down Expand Up @@ -335,7 +335,7 @@ protected function addReValidationRequest(
*
* @return null|ResponseInterface
*/
protected static function getStaleResponse(CacheEntry $cacheEntry = null)
protected static function getStaleResponse(?CacheEntry $cacheEntry = null)
{
// Return staled cache entry if we can
if ($cacheEntry instanceof CacheEntry && $cacheEntry->serveStaleIfError()) {
Expand All @@ -352,7 +352,7 @@ protected static function getStaleResponse(CacheEntry $cacheEntry = null)
*
* @return RequestInterface
*/
protected static function getRequestWithReValidationHeader(RequestInterface $request, CacheEntry $cacheEntry)
protected static function getRequestWithReValidationHeader(RequestInterface $request, ?CacheEntry $cacheEntry)
{
if ($cacheEntry->getResponse()->hasHeader('Last-Modified')) {
$request = $request->withHeader(
Expand All @@ -377,7 +377,7 @@ protected static function getRequestWithReValidationHeader(RequestInterface $req
*
* @deprecated Use constructor => `new CacheMiddleware()`
*/
public static function getMiddleware(CacheStrategyInterface $cacheStorage = null)
public static function getMiddleware(?CacheStrategyInterface $cacheStorage = null)
{
return new self($cacheStorage);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/Delegate/DelegatingCacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DelegatingCacheStrategy implements CacheStrategyInterface
/**
* DelegatingCacheStrategy constructor.
*/
public function __construct(CacheStrategyInterface $defaultCacheStrategy = null)
public function __construct(?CacheStrategyInterface $defaultCacheStrategy = null)
{
$this->defaultCacheStrategy = $defaultCacheStrategy ?: new NullCacheStrategy();
}
Expand Down
9 changes: 6 additions & 3 deletions src/Strategy/GreedyCacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ class GreedyCacheStrategy extends PrivateCacheStrategy
*/
private $varyHeaders;

public function __construct(CacheStorageInterface $cache = null, $defaultTtl, KeyValueHttpHeader $varyHeaders = null)
{
public function __construct(
?CacheStorageInterface $cache = null,
$defaultTtl = 60,
?KeyValueHttpHeader $varyHeaders = null,
) {
$this->defaultTtl = $defaultTtl;
$this->varyHeaders = $varyHeaders;
parent::__construct($cache);
}

protected function getCacheKey(RequestInterface $request, KeyValueHttpHeader $varyHeaders = null)
protected function getCacheKey(RequestInterface $request, ?KeyValueHttpHeader $varyHeaders = null)
{
if (null === $varyHeaders || $varyHeaders->isEmpty()) {
return hash(
Expand Down
4 changes: 2 additions & 2 deletions src/Strategy/PrivateCacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PrivateCacheStrategy implements CacheStrategyInterface
'max-age',
];

public function __construct(CacheStorageInterface $cache = null)
public function __construct(?CacheStorageInterface $cache = null)
{
$this->storage = $cache !== null ? $cache : new VolatileRuntimeStorage();
}
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function getCacheObject(RequestInterface $request, ResponseInterface $
*
* @return string
*/
protected function getCacheKey(RequestInterface $request, KeyValueHttpHeader $varyHeaders = null)
protected function getCacheKey(RequestInterface $request, ?KeyValueHttpHeader $varyHeaders = null)
{
if (!$varyHeaders) {
return hash('sha256', $request->getMethod().$request->getUri());
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/PublicCacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class PublicCacheStrategy extends PrivateCacheStrategy
{
public function __construct(CacheStorageInterface $cache = null)
public function __construct(?CacheStorageInterface $cache = null)
{
parent::__construct($cache);

Expand Down

0 comments on commit 61305ed

Please sign in to comment.