Skip to content

Commit 00e272c

Browse files
authored
Merge pull request #41 from AlexejLeinweber/chore/update-composer-deps-2
chore: Update composer-deps
2 parents 50f726d + b5c9440 commit 00e272c

File tree

13 files changed

+55
-45
lines changed

13 files changed

+55
-45
lines changed

.github/workflows/test-redis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
matrix:
1515
dependencies: ["lowest", "highest"]
1616
php-version:
17-
- "8.2"
1817
- "8.3"
18+
- "8.4"
1919
operating-system: ["ubuntu-latest"]
2020

2121
steps:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
matrix:
1515
dependencies: ["lowest", "highest"]
1616
php-version:
17-
- "8.2"
1817
- "8.3"
18+
- "8.4"
1919
operating-system: ["ubuntu-latest"]
2020

2121
steps:

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^8.2",
14+
"php": "^8.3",
1515
"psr/clock": "^1.0"
1616
},
1717
"require-dev": {
1818
"brainbits/phpcs-standard": "^7.0.1",
19-
"brainbits/phpstan-rules": "^3.1",
19+
"brainbits/phpstan-rules": "^4.0",
2020
"matthiasnoback/symfony-config-test": "^5.1",
2121
"matthiasnoback/symfony-dependency-injection-test": "^6.0",
2222
"mikey179/vfsstream": "^1.6.11",
23-
"phpstan/phpstan": "^1.10.67",
24-
"phpunit/phpunit": "^11.3.6",
23+
"phpstan/phpstan": "^2.1.1",
24+
"phpunit/phpunit": "^11.5",
2525
"predis/predis": "^2.2",
2626
"symfony/clock": "^6.4|^7.0",
2727
"symfony/config": "^6.4|^7.0",
@@ -30,8 +30,8 @@
3030
"symfony/http-kernel": "^6.4|^7.0",
3131
"symfony/routing": "^6.4|^7.0",
3232
"symfony/security-core": "^6.4|^7.0",
33-
"phpstan/phpstan-phpunit": "^1.3",
34-
"phpstan/phpstan-symfony": "^1.3"
33+
"phpstan/phpstan-phpunit": "^2.0",
34+
"phpstan/phpstan-symfony": "^2.0"
3535
},
3636
"suggest": {
3737
"predis/predis": "If you want to use the PredisStorage",

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ parameters:
44
- src
55
bootstrapFiles:
66
- vendor/autoload.php
7+
excludePaths:
8+
# Declaring types for static function parameters is not possible
9+
- src/Bundle/DependencyInjection/Configuration.php
710
includes:
811
- vendor/brainbits/phpstan-rules/rules.neon
912
- vendor/phpstan/phpstan-phpunit/rules.neon

src/Blocker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Brainbits\Blocking;
1515

16-
use Brainbits\Blocking\Exception\BlockFailedException;
16+
use Brainbits\Blocking\Exception\AlreadyBlockedException;
1717
use Brainbits\Blocking\Identity\BlockIdentity;
1818
use Brainbits\Blocking\Owner\OwnerFactoryInterface;
1919
use Brainbits\Blocking\Storage\StorageInterface;
@@ -32,7 +32,7 @@ public function block(BlockIdentity $identifier, int|null $ttl = null): Block
3232
$block = $this->tryBlock($identifier, $ttl);
3333

3434
if ($block === null) {
35-
throw BlockFailedException::createAlreadyBlocked($identifier);
35+
throw AlreadyBlockedException::createAlreadyBlocked($identifier);
3636
}
3737

3838
return $block;

src/Bundle/DependencyInjection/BrainbitsBlockingExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
2121
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2222

23-
use function assert;
2423
use function sprintf;
2524

2625
class BrainbitsBlockingExtension extends Extension
@@ -32,8 +31,11 @@ public function load(array $configs, ContainerBuilder $container): void
3231
$yamlLoader->load('services.yaml');
3332
$configuration = $this->getConfiguration($configs, $container);
3433

35-
assert($configuration instanceof Configuration);
36-
34+
/** @var array{
35+
* storage: non-empty-array<string>,
36+
* clock?: class-string,
37+
* block_interval: int,
38+
* owner_factory: array{value?: string, driver: string, service: string}} $config */
3739
$config = $this->processConfiguration($configuration, $configs);
3840

3941
if (isset($config['storage']['predis'])) {

src/Exception/BlockFailedException.php renamed to src/Exception/AlreadyBlockedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use function sprintf;
1919

20-
class BlockFailedException extends RuntimeException
20+
class AlreadyBlockedException extends RuntimeException
2121
{
2222
public static function createAlreadyBlocked(BlockIdentity $identity): self
2323
{

src/Owner/SymfonySessionOwnerFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Brainbits\Blocking\Exception\NoSessionException;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\RequestStack;
19-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2019

2120
final readonly class SymfonySessionOwnerFactory implements OwnerFactoryInterface
2221
{
@@ -32,9 +31,6 @@ public function createOwner(): Owner
3231
}
3332

3433
$session = $request->getSession();
35-
if (!$session instanceof SessionInterface) {
36-
throw NoSessionException::create();
37-
}
3834

3935
return new Owner($session->getId());
4036
}

src/Storage/FilesystemStorage.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
use Brainbits\Blocking\Owner\Owner;
2323
use DateTimeImmutable;
2424
use Psr\Clock\ClockInterface;
25+
use Throwable;
2526

2627
use function assert;
2728
use function dirname;
2829
use function file_exists;
2930
use function file_get_contents;
3031
use function file_put_contents;
31-
use function is_array;
3232
use function is_string;
3333
use function is_writable;
3434
use function json_decode;
@@ -137,13 +137,16 @@ public function exists(BlockIdentity $identity): bool
137137
$metaContent = file_get_contents($metaFilename);
138138
assert(is_string($metaContent));
139139
assert($metaContent !== '');
140+
/** @var array{ttl: int, updatedAt: string} $metaData */
140141
$metaData = json_decode($metaContent, true);
141-
assert(is_array($metaData));
142142

143143
$now = $this->clock->now();
144-
145-
$expiresAt = (new DateTimeImmutable((string) $metaData['updatedAt'], $now->getTimezone()))
146-
->modify('+' . $metaData['ttl'] . ' seconds');
144+
try {
145+
$expiresAt = (new DateTimeImmutable((string) $metaData['updatedAt'], $now->getTimezone()))
146+
->modify('+' . $metaData['ttl'] . ' seconds');
147+
} catch (Throwable) {
148+
throw UnserializeFailedException::createFromInput($metaContent);
149+
}
147150

148151
return $expiresAt > $now;
149152
}
@@ -162,16 +165,19 @@ public function get(BlockIdentity $identity): Block|null
162165
throw UnserializeFailedException::createFromInput($content);
163166
}
164167

168+
/** @var array{identity: string, owner: string} $data */
165169
$data = json_decode($content, true);
166170

167-
assert(is_array($data));
168-
assert($data['identity'] ?? false);
169-
assert($data['owner'] ?? false);
171+
try {
172+
$block = new Block(
173+
new BlockIdentity($data['identity']),
174+
new Owner($data['owner']),
175+
);
176+
} catch (Throwable) {
177+
throw UnserializeFailedException::createFromInput($content);
178+
}
170179

171-
return new Block(
172-
new BlockIdentity($data['identity']),
173-
new Owner($data['owner']),
174-
);
180+
return $block;
175181
}
176182

177183
private function getFilename(BlockIdentity $identifier): string

src/Storage/PredisStorage.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
use Brainbits\Blocking\Block;
1717
use Brainbits\Blocking\Exception\IOException;
18+
use Brainbits\Blocking\Exception\UnserializeFailedException;
1819
use Brainbits\Blocking\Identity\BlockIdentity;
1920
use Brainbits\Blocking\Owner\Owner;
2021
use Predis\ClientInterface;
2122
use Predis\PredisException;
23+
use Throwable;
2224

23-
use function assert;
24-
use function is_array;
2525
use function json_decode;
2626
use function json_encode;
2727

@@ -110,16 +110,19 @@ public function get(BlockIdentity $identity): Block|null
110110
throw IOException::getFailed((string) $identity);
111111
}
112112

113+
/** @var array{identity: string, owner: string} $data */
113114
$data = json_decode($content, true);
114115

115-
assert(is_array($data));
116-
assert($data['identity'] ?? false);
117-
assert($data['owner'] ?? false);
116+
try {
117+
$block = new Block(
118+
new BlockIdentity($data['identity']),
119+
new Owner($data['owner']),
120+
);
121+
} catch (Throwable) {
122+
throw UnserializeFailedException::createFromInput($content);
123+
}
118124

119-
return new Block(
120-
new BlockIdentity($data['identity']),
121-
new Owner($data['owner']),
122-
);
125+
return $block;
123126
}
124127

125128
private function createKey(BlockIdentity $identity): string

0 commit comments

Comments
 (0)