Skip to content

Commit c4ece31

Browse files
committed
fix(deprecation warning): str_replace(): Passing null to parameter #3 ($subject)
Remaining self deprecation notices (1) 1x: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated 1x in RateLimitAnnotationListenerTest::testDispatchIsCalledIfThePathLimitProcessorReturnsARateLimit from Noxlogic\RateLimitBundle\Tests\EventListener
1 parent 44cf127 commit c4ece31

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

DependencyInjection/Configuration.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getConfigTreeBuilder(): TreeBuilder
2626
->canBeDisabled()
2727
->children()
2828
->enumNode('storage_engine')
29-
->values(array('redis','memcache','doctrine', 'php_redis', 'php_redis_cluster', 'simple_cache', 'cache'))
29+
->values(['redis','memcache','doctrine', 'php_redis', 'php_redis_cluster', 'simple_cache', 'cache'])
3030
->defaultValue('redis')
3131
->info('The storage engine where all the rates will be stored')
3232
->end()
@@ -109,19 +109,20 @@ public function getConfigTreeBuilder(): TreeBuilder
109109
->end()
110110
->end()
111111
->arrayNode('path_limits')
112-
->defaultValue(array())
112+
->defaultValue([])
113113
->info('Rate limits for paths')
114114
->prototype('array')
115115
->children()
116116
->scalarNode('path')
117117
->isRequired()
118+
->cannotBeEmpty()
118119
->end()
119120
->arrayNode('methods')
120121
->prototype('enum')
121-
->values(array('*', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH'))
122+
->values(['*', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
122123
->end()
123124
->requiresAtLeastOneElement()
124-
->defaultValue(array('*'))
125+
->defaultValue(['*'])
125126
->end()
126127
->integerNode('limit')
127128
->isRequired()

Util/PathLimitProcessor.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88

99
class PathLimitProcessor
1010
{
11-
private array $pathLimits;
12-
13-
public function __construct(array $pathLimits)
11+
/**
12+
* @param array<array{path: string, methods: array<string>, limit: int<-1, max>, period: positive-int}> $pathLimits
13+
*/
14+
public function __construct(private array $pathLimits)
1415
{
15-
$this->pathLimits = $pathLimits;
16-
1716
// Clean up any extra slashes from the config
1817
foreach ($this->pathLimits as &$pathLimit) {
1918
$pathLimit['path'] = trim($pathLimit['path'], '/');
2019
}
2120

2221
// Order the configs so that the most specific paths
2322
// are matched first
24-
usort($this->pathLimits, static function($a, $b) {
23+
usort($this->pathLimits, static function($a, $b): int {
2524
return substr_count($b['path'], '/') - substr_count($a['path'], '/');
2625
});
2726
}
@@ -44,7 +43,7 @@ public function getRateLimit(Request $request): ?RateLimit
4443
return null;
4544
}
4645

47-
public function getMatchedPath(Request $request)
46+
public function getMatchedPath(Request $request): string
4847
{
4948
$path = trim($request->getPathInfo(), '/');
5049
$method = $request->getMethod();

phpstan-baseline.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -384,18 +384,6 @@ parameters:
384384
count: 1
385385
path: Service/Storage/StorageInterface.php
386386

387-
-
388-
message: '#^Method Noxlogic\\RateLimitBundle\\Util\\PathLimitProcessor\:\:__construct\(\) has parameter \$pathLimits with no value type specified in iterable type array\.$#'
389-
identifier: missingType.iterableValue
390-
count: 1
391-
path: Util/PathLimitProcessor.php
392-
393-
-
394-
message: '#^Method Noxlogic\\RateLimitBundle\\Util\\PathLimitProcessor\:\:getMatchedPath\(\) has no return type specified\.$#'
395-
identifier: missingType.return
396-
count: 1
397-
path: Util/PathLimitProcessor.php
398-
399387
-
400388
message: '#^Method Noxlogic\\RateLimitBundle\\Util\\PathLimitProcessor\:\:methodMatched\(\) has parameter \$expectedMethods with no value type specified in iterable type array\.$#'
401389
identifier: missingType.iterableValue
@@ -437,9 +425,3 @@ parameters:
437425
identifier: missingType.parameter
438426
count: 1
439427
path: Util/PathLimitProcessor.php
440-
441-
-
442-
message: '#^Property Noxlogic\\RateLimitBundle\\Util\\PathLimitProcessor\:\:\$pathLimits type has no value type specified in iterable type array\.$#'
443-
identifier: missingType.iterableValue
444-
count: 1
445-
path: Util/PathLimitProcessor.php

0 commit comments

Comments
 (0)