Skip to content

Commit

Permalink
chore: Update composer-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexejLeinweber committed Jan 17, 2025
1 parent 50f726d commit 4c571b0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
matrix:
dependencies: ["lowest", "highest"]
php-version:
- "8.2"
- "8.3"
- "8.4"
operating-system: ["ubuntu-latest"]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
matrix:
dependencies: ["lowest", "highest"]
php-version:
- "8.2"
- "8.3"
- "8.4"
operating-system: ["ubuntu-latest"]

steps:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
}
],
"require": {
"php": "^8.2",
"php": "^8.3",
"psr/clock": "^1.0"
},
"require-dev": {
"brainbits/phpcs-standard": "^7.0.1",
"brainbits/phpstan-rules": "^3.1",
"brainbits/phpstan-rules": "^4.0",
"matthiasnoback/symfony-config-test": "^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^6.0",
"mikey179/vfsstream": "^1.6.11",
"phpstan/phpstan": "^1.10.67",
"phpunit/phpunit": "^11.3.6",
"phpstan/phpstan": "^2.1.1",
"phpunit/phpunit": "^11.5",
"predis/predis": "^2.2",
"symfony/clock": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
Expand All @@ -30,8 +30,8 @@
"symfony/http-kernel": "^6.4|^7.0",
"symfony/routing": "^6.4|^7.0",
"symfony/security-core": "^6.4|^7.0",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3"
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-symfony": "^2.0"
},
"suggest": {
"predis/predis": "If you want to use the PredisStorage",
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ parameters:
- src
bootstrapFiles:
- vendor/autoload.php
excludePaths:
# Declaring types for static function parameters is not possible
- src/Bundle/DependencyInjection/Configuration.php
includes:
- vendor/brainbits/phpstan-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
8 changes: 5 additions & 3 deletions src/Bundle/DependencyInjection/BrainbitsBlockingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

use function assert;
use function sprintf;

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

assert($configuration instanceof Configuration);

/** @var array{
* storage: non-empty-array<string>,
* clock?: class-string,
* block_interval: int,
* owner_factory: array{value?: string, driver: string, service: string}} $config */
$config = $this->processConfiguration($configuration, $configs);

if (isset($config['storage']['predis'])) {
Expand Down
4 changes: 0 additions & 4 deletions src/Owner/SymfonySessionOwnerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Brainbits\Blocking\Exception\NoSessionException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

final readonly class SymfonySessionOwnerFactory implements OwnerFactoryInterface
{
Expand All @@ -32,9 +31,6 @@ public function createOwner(): Owner
}

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

return new Owner($session->getId());
}
Expand Down
30 changes: 18 additions & 12 deletions src/Storage/FilesystemStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
use Brainbits\Blocking\Owner\Owner;
use DateTimeImmutable;
use Psr\Clock\ClockInterface;
use Throwable;

use function assert;
use function dirname;
use function file_exists;
use function file_get_contents;
use function file_put_contents;
use function is_array;
use function is_string;
use function is_writable;
use function json_decode;
Expand Down Expand Up @@ -137,13 +137,16 @@ public function exists(BlockIdentity $identity): bool
$metaContent = file_get_contents($metaFilename);
assert(is_string($metaContent));
assert($metaContent !== '');
/** @var array{ttl: int, updatedAt: string} $metaData */
$metaData = json_decode($metaContent, true);
assert(is_array($metaData));

$now = $this->clock->now();

$expiresAt = (new DateTimeImmutable((string) $metaData['updatedAt'], $now->getTimezone()))
->modify('+' . $metaData['ttl'] . ' seconds');
try {
$expiresAt = (new DateTimeImmutable((string) $metaData['updatedAt'], $now->getTimezone()))
->modify('+' . $metaData['ttl'] . ' seconds');
} catch (Throwable) {
throw UnserializeFailedException::createFromInput($metaContent);
}

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

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

assert(is_array($data));
assert($data['identity'] ?? false);
assert($data['owner'] ?? false);
try {
$block = new Block(
new BlockIdentity($data['identity']),
new Owner($data['owner']),
);
} catch (Throwable) {
throw UnserializeFailedException::createFromInput($content);
}

return new Block(
new BlockIdentity($data['identity']),
new Owner($data['owner']),
);
return $block;
}

private function getFilename(BlockIdentity $identifier): string
Expand Down
21 changes: 12 additions & 9 deletions src/Storage/PredisStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

use Brainbits\Blocking\Block;
use Brainbits\Blocking\Exception\IOException;
use Brainbits\Blocking\Exception\UnserializeFailedException;
use Brainbits\Blocking\Identity\BlockIdentity;
use Brainbits\Blocking\Owner\Owner;
use Predis\ClientInterface;
use Predis\PredisException;
use Throwable;

use function assert;
use function is_array;
use function json_decode;
use function json_encode;

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

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

assert(is_array($data));
assert($data['identity'] ?? false);
assert($data['owner'] ?? false);
try {
$block = new Block(
new BlockIdentity($data['identity']),
new Owner($data['owner']),
);
} catch (Throwable) {
throw UnserializeFailedException::createFromInput($content);
}

return new Block(
new BlockIdentity($data['identity']),
new Owner($data['owner']),
);
return $block;
}

private function createKey(BlockIdentity $identity): string
Expand Down

0 comments on commit 4c571b0

Please sign in to comment.