Skip to content

Commit 07bdfaa

Browse files
authored
Merge pull request #134 from meQuilibrium/php-8.4-deprecation-fixes
PHP 8.4 deprecation fixes
2 parents 91d4a0b + 277a478 commit 07bdfaa

File tree

13 files changed

+495
-39
lines changed

13 files changed

+495
-39
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ on:
66

77
jobs:
88
run-tests:
9-
runs-on: ubuntu-20.04
9+
runs-on: ubuntu-24.04
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
php: [ "8.0", "8.1", "8.2" ]
13+
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
1414
composer_flags: [ "", "--prefer-lowest" ]
15-
symfony_version: [ "^5.4", "^6.1" ]
15+
symfony_version: [ "^5.4", "^6.4" ]
1616
exclude:
1717
- php: "8.0"
18-
symfony_version: "^6.1"
18+
symfony_version: "^6.4"
1919
name: PHP ${{ matrix.php }} SF ${{ matrix.symfony_version }} ${{ matrix.composer_flags}}
2020
env:
2121
PHP: ${{ matrix.os }}
@@ -38,8 +38,11 @@ jobs:
3838
run: |
3939
composer self-update
4040
if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
41-
if [ "$SYMFONY_VERSION" = "^6.1" ]; then composer remove --dev "friendsofsymfony/oauth-server-bundle" --no-update; fi;
41+
if [ "$SYMFONY_VERSION" = "^6.4" ]; then composer remove --dev "friendsofsymfony/oauth-server-bundle" --no-update; fi;
4242
COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
43+
- name: Static analysis
44+
run: |
45+
./vendor/bin/phpstan --memory-limit=-1
4346
- name: Run tests
4447
run: |
4548
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/simple-phpunit --coverage-text --coverage-clover=coverage.clover

DependencyInjection/Configuration.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ class Configuration implements ConfigurationInterface
2020
public function getConfigTreeBuilder(): TreeBuilder
2121
{
2222
$treeBuilder = new TreeBuilder('noxlogic_rate_limit');
23-
// Keep compatibility with symfony/config < 4.2
24-
if (\method_exists($treeBuilder, 'getRootNode')) {
25-
$rootNode = $treeBuilder->getRootNode();
26-
} else {
27-
$rootNode = $treeBuilder->root('noxlogic_rate_limit');
28-
}
29-
$rootNode
23+
$rootNode = $treeBuilder->getRootNode();
24+
25+
$rootNode // @phpstan-ignore method.notFound
3026
->canBeDisabled()
3127
->children()
3228
->enumNode('storage_engine')

DependencyInjection/NoxlogicRateLimitExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NoxlogicRateLimitExtension extends Extension
1717
{
1818
/**
1919
* {@inheritDoc}
20+
* @param mixed[][] $configs
2021
*/
2122
public function load(array $configs, ContainerBuilder $container): void
2223
{

EventListener/HeaderModificationListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Noxlogic\RateLimitBundle\EventListener;
44

55
use Noxlogic\RateLimitBundle\Service\RateLimitInfo;
6-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
76
use Symfony\Component\HttpKernel\Event\ResponseEvent;
87

98
class HeaderModificationListener extends BaseListener
@@ -18,7 +17,7 @@ public function __construct($defaultParameters = array())
1817
}
1918

2019
/**
21-
* @param FilterResponseEvent|ResponseEvent $event
20+
* @param ResponseEvent $event
2221
*/
2322
public function onKernelResponse($event)
2423
{
@@ -44,7 +43,7 @@ public function onKernelResponse($event)
4443

4544
$response = $event->getResponse();
4645
$response->headers->set($this->getParameter('header_limit_name'), $rateLimitInfo->getLimit());
47-
$response->headers->set($this->getParameter('header_remaining_name'), $remaining);
46+
$response->headers->set($this->getParameter('header_remaining_name'), (string) $remaining);
4847
$response->headers->set($this->getParameter('header_reset_name'), $rateLimitInfo->getResetTimestamp());
4948
}
5049
}

Events/CheckedRateLimitEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CheckedRateLimitEvent extends Event
1212

1313
protected ?RateLimit $rateLimit;
1414

15-
public function __construct(Request $request, RateLimit $rateLimit = null)
15+
public function __construct(Request $request, ?RateLimit $rateLimit = null)
1616
{
1717
$this->request = $request;
1818
$this->rateLimit = $rateLimit;

Service/RateLimitService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class RateLimitService
88
{
99
/**
10-
* @var Storage\StorageInterface
10+
* @var ?Storage\StorageInterface
1111
*/
1212
protected $storage;
1313

@@ -20,7 +20,7 @@ public function setStorage(StorageInterface $storage)
2020
}
2121

2222
/**
23-
* @return StorageInterface
23+
* @return ?StorageInterface
2424
*/
2525
public function getStorage()
2626
{

Service/Storage/PhpRedis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class PhpRedis implements StorageInterface
1010
{
1111
/**
12-
* @var \Redis
12+
* @var \Redis|\RedisCluster
1313
*/
1414
protected $client;
1515

Service/Storage/Redis.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function createRate($key, $limit, $period)
5555

5656
$reset = time() + $period;
5757

58-
$this->client->hset($key, 'limit', $limit);
59-
$this->client->hset($key, 'calls', 1);
60-
$this->client->hset($key, 'reset', $reset);
58+
$this->client->hset($key, 'limit', (string) $limit);
59+
$this->client->hset($key, 'calls', '1');
60+
$this->client->hset($key, 'reset', (string) $reset);
6161
$this->client->expire($key, $period);
6262

6363
$rateLimitInfo = new RateLimitInfo();

Service/Storage/StorageInterface.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ interface StorageInterface
99
/**
1010
* Get information about the current rate
1111
*
12-
* @param string $key
13-
* @return RateLimitInfo Rate limit information
14-
*/
12+
* @param string $key
13+
* @return RateLimitInfo|bool Rate limit information
14+
* @todo: Replace return type with RateLimitInfo|false when PHP 8.2 is the minimum version
15+
*/
1516
public function getRateInfo($key);
1617

1718
/**
1819
* Limit the rate by one
1920
*
20-
* @param string $key
21-
* @return RateLimitInfo Rate limit info
21+
* @param string $key
22+
* @return RateLimitInfo|bool Rate limit info
23+
* @todo: Replace return type with RateLimitInfo|false when PHP 8.2 is the minimum version
2224
*/
2325
public function limitRate($key);
2426

Tests/EventListener/HeaderModificationListenerTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
namespace Noxlogic\RateLimitBundle\Tests\EventListener;
44

55
use Noxlogic\RateLimitBundle\EventListener\HeaderModificationListener;
6-
use Noxlogic\RateLimitBundle\Events\ProxyFilterResponseEvent;
76
use Noxlogic\RateLimitBundle\Service\RateLimitInfo;
87
use Noxlogic\RateLimitBundle\Tests\TestCase;
98
use Symfony\Component\HttpFoundation\Request;
109
use Symfony\Component\HttpFoundation\Response;
1110
use Symfony\Component\HttpKernel\Event\ControllerEvent;
12-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1311
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1412
use Symfony\Component\HttpKernel\HttpKernelInterface;
1513

@@ -136,19 +134,15 @@ public function testListenerWithoutRateInfo()
136134
}
137135

138136
/**
139-
* @return FilterResponseEvent|ControllerEvent
137+
* @return ResponseEvent
140138
*/
141139
protected function createEvent()
142140
{
143-
$kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->getMock();
141+
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
144142
$request = new Request();
145143
$response = new Response();
146144

147-
if (class_exists('Symfony\\Component\\HttpKernel\\Event\\ControllerEvent')) {
148-
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
149-
} else {
150-
$event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
151-
}
145+
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response);
152146

153147
return $event;
154148
}

0 commit comments

Comments
 (0)