From 3e7afb4e4364fee1851f9992a8477ae67dcfc19a Mon Sep 17 00:00:00 2001 From: Jost Voelker Date: Wed, 7 Dec 2022 16:10:19 +0100 Subject: [PATCH] chore: update brainbits codestyle and fix style --- .phpunit.result.cache | 1 + composer.json | 2 +- src/Block.php | 13 +++++-------- src/Blocker.php | 14 +++++--------- src/Exception/UnserializeFailedException.php | 6 +----- src/Identity/Identity.php | 5 +---- src/Owner/Owner.php | 5 +---- src/Owner/SymfonySessionOwnerFactory.php | 5 +---- src/Owner/SymfonyTokenOwnerFactory.php | 5 +---- src/Owner/ValueOwnerFactory.php | 5 +---- src/Storage/FilesystemStorage.php | 2 +- src/Storage/InMemoryStorage.php | 2 +- src/Storage/StorageInterface.php | 2 +- src/Validator/ExpiredValidator.php | 5 +---- 14 files changed, 22 insertions(+), 50 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..7383b18 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":[],"times":{"Brainbits\\Blocking\\Tests\\BlockTest::testConstruct":0.03,"Brainbits\\Blocking\\Tests\\BlockTest::testGetIdentifierReturnsCorrectValue":0.001,"Brainbits\\Blocking\\Tests\\BlockTest::testGetOwnerReturnsCorrectValue":0,"Brainbits\\Blocking\\Tests\\BlockTest::testIsOwnedByReturnsTrue":0.001,"Brainbits\\Blocking\\Tests\\BlockTest::testIsOwnedByReturnsFalse":0.001,"Brainbits\\Blocking\\Tests\\BlockTest::testGetCreatedAtReturnsCorrectValue":0,"Brainbits\\Blocking\\Tests\\BlockTest::testGetUpdatedAtReturnsCreatedAtValueAfterInstanciation":0,"Brainbits\\Blocking\\Tests\\BlockTest::testTouchUpdatesValue":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testBlockReturnsBlockOnNonexistingBlock":0.005,"Brainbits\\Blocking\\Tests\\BlockerTest::testBlockReturnsBlockOnExistingAndInvalidBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testBlockThrowsExceptionOnExistingAndValidAndNonOwnerBlock":0.002,"Brainbits\\Blocking\\Tests\\BlockerTest::testBlockUpdatesBlockOnExistingAndValidAndOwnedBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testUnblockReturnsNullOnExistingAndInvalidBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testUnblockReturnsBlockOnExistingAndValidBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testUnblockReturnsNullOnNonexistingBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testIsBlockedReturnsFalseOnExistingAndInvalidBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testIsBlockedReturnsTrueOnExistingAndValidBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testIsBlockedReturnsFalseOnNonexistingBlock":0.001,"Brainbits\\Blocking\\Tests\\BlockerTest::testGetBlockReturnsBlockOnExistingBlock":0.001,"Brainbits\\Blocking\\Tests\\Identifier\\IdentifierTest::testConstruct":0,"Brainbits\\Blocking\\Tests\\Identifier\\IdentifierTest::testEquals":0,"Brainbits\\Blocking\\Tests\\Identifier\\IdentifierTest::testToString":0,"Brainbits\\Blocking\\Tests\\Owner\\OwnerTest::testConstruct":0,"Brainbits\\Blocking\\Tests\\Owner\\OwnerTest::testEquals":0,"Brainbits\\Blocking\\Tests\\Owner\\OwnerTest::testToString":0,"Brainbits\\Blocking\\Tests\\Owner\\SymfonySessionOwnerFactoryTest::testToString":0.012,"Brainbits\\Blocking\\Tests\\Owner\\SymfonyTokenOwnerFactoryTest::testCreateOwner":0.005,"Brainbits\\Blocking\\Tests\\Owner\\SymfonyTokenOwnerFactoryTest::testE":0,"Brainbits\\Blocking\\Tests\\Owner\\SymfonyTokenOwnerFactoryTest::testE2":0.001,"Brainbits\\Blocking\\Tests\\Owner\\ValueOwnerFactoryTest::testCreate":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testWriteSucceedesOnNewFile":0.007,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testWriteFailsOnNonExistantDirectoryInNonWritableDirectory":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testWriteFailsOnNonWritableDirectory":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testTouchSucceedesOnExistingFile":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testRemoveReturnsFalseOnNonexistingFile":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testUnblockReturnsTrueOnExistingFile":0.001,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testExistsReturnsFalseOnNonexistingFile":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testIsBlockedReturnsTrueOnExistingBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testGetReturnsNullOnNonexistingFile":0,"Brainbits\\Blocking\\Tests\\Storage\\FilesystemStorageTest::testGetReturnsBlockOnExistingFile":0.001,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testConstructWithBlock":0.001,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testWriteSucceedesOnNewBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testTouchSucceedesOnExistingBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testRemoveReturnsFalseOnNonexistingBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testUnblockReturnsTrueOnExistingBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testExistsReturnsFalseOnNonexistingBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testIsBlockedReturnsTrueOnExistingBlock":0,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testGetReturnsNullOnNonexistingFile":0.001,"Brainbits\\Blocking\\Tests\\Storage\\InMemoryStorageTest::testGetReturnsBlockOnExistingFile":0,"Brainbits\\Blocking\\Tests\\Validator\\AlwaysInvalidateValidatorTest::testValidateBlockLastUpdatedThirtySecondsAgo":0.001,"Brainbits\\Blocking\\Tests\\Validator\\AlwaysInvalidateValidatorTest::testValidateBlockLastUpdatedOneMinuteAgo":0,"Brainbits\\Blocking\\Tests\\Validator\\AlwaysInvalidateValidatorTest::testValidateBlockLastUpdatedOneHourAo":0,"Brainbits\\Blocking\\Tests\\Validator\\ExpiredValidatorTest::testValidateBlockLastUpdatedThirtySecondsAgo":0.001,"Brainbits\\Blocking\\Tests\\Validator\\ExpiredValidatorTest::testValidateBlockLastUpdatedOneMinuteAgo":0,"Brainbits\\Blocking\\Tests\\Validator\\ExpiredValidatorTest::testValidateBlockLastUpdatedOneHourAo":0}} \ No newline at end of file diff --git a/composer.json b/composer.json index f54a0a8..95cd140 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "symfony/security-core": "^5.4|^6.0", "phpspec/prophecy-phpunit": "^2.0.1", "squizlabs/php_codesniffer": "^3.6", - "brainbits/phpcs-standard": "^5.0", + "brainbits/phpcs-standard": "^6.0", "phpstan/phpstan": "^1.0", "brainbits/phpstan-rules": "^3.0" }, diff --git a/src/Block.php b/src/Block.php index b50f987..81d631f 100644 --- a/src/Block.php +++ b/src/Block.php @@ -22,16 +22,13 @@ */ class Block implements BlockInterface { - private IdentityInterface $identifier; - private OwnerInterface $owner; - private DateTimeImmutable $createdAt; private DateTimeImmutable $updatedAt; - public function __construct(IdentityInterface $identifier, OwnerInterface $owner, DateTimeImmutable $createdAt) - { - $this->identifier = $identifier; - $this->owner = $owner; - $this->createdAt = $createdAt; + public function __construct( + private IdentityInterface $identifier, + private OwnerInterface $owner, + private DateTimeImmutable $createdAt, + ) { $this->updatedAt = $createdAt; } diff --git a/src/Blocker.php b/src/Blocker.php index eb6e84a..bd134a1 100644 --- a/src/Blocker.php +++ b/src/Blocker.php @@ -26,17 +26,13 @@ class Blocker { private StorageInterface $storage; - private OwnerFactoryInterface $ownerFactory; - private ValidatorInterface $validator; public function __construct( StorageInterface $adapter, - OwnerFactoryInterface $ownerFactory, - ValidatorInterface $validator + private OwnerFactoryInterface $ownerFactory, + private ValidatorInterface $validator, ) { $this->storage = $adapter; - $this->ownerFactory = $ownerFactory; - $this->validator = $validator; } public function block(IdentityInterface $identifier): BlockInterface @@ -50,7 +46,7 @@ public function block(IdentityInterface $identifier): BlockInterface return $block; } - public function tryBlock(IdentityInterface $identifier): ?BlockInterface + public function tryBlock(IdentityInterface $identifier): BlockInterface|null { $owner = $this->ownerFactory->createOwner(); @@ -73,7 +69,7 @@ public function tryBlock(IdentityInterface $identifier): ?BlockInterface return $block; } - public function unblock(IdentityInterface $identifier): ?BlockInterface + public function unblock(IdentityInterface $identifier): BlockInterface|null { $block = $this->getBlock($identifier); if ($block === null) { @@ -104,7 +100,7 @@ public function isBlocked(IdentityInterface $identifier): bool return false; } - public function getBlock(IdentityInterface $identifier): ?BlockInterface + public function getBlock(IdentityInterface $identifier): BlockInterface|null { if (!$this->isBlocked($identifier)) { return null; diff --git a/src/Exception/UnserializeFailedException.php b/src/Exception/UnserializeFailedException.php index b4b7981..c6740ba 100644 --- a/src/Exception/UnserializeFailedException.php +++ b/src/Exception/UnserializeFailedException.php @@ -21,13 +21,9 @@ */ final class UnserializeFailedException extends RuntimeException { - private string $input; - - private function __construct(string $message, string $input) + private function __construct(string $message, private string $input) { parent::__construct($message); - - $this->input = $input; } public static function createFromInput(mixed $input): self diff --git a/src/Identity/Identity.php b/src/Identity/Identity.php index d34e8bf..116d9da 100644 --- a/src/Identity/Identity.php +++ b/src/Identity/Identity.php @@ -18,11 +18,8 @@ */ class Identity implements IdentityInterface { - private string $identityValue; - - public function __construct(string $identityValue) + public function __construct(private string $identityValue) { - $this->identityValue = $identityValue; } public function equals(IdentityInterface $identifier): bool diff --git a/src/Owner/Owner.php b/src/Owner/Owner.php index 242bb52..5f31e59 100644 --- a/src/Owner/Owner.php +++ b/src/Owner/Owner.php @@ -15,11 +15,8 @@ class Owner implements OwnerInterface { - private string $ownerValue; - - public function __construct(string $ownerValue) + public function __construct(private string $ownerValue) { - $this->ownerValue = $ownerValue; } public function equals(OwnerInterface $owner): bool diff --git a/src/Owner/SymfonySessionOwnerFactory.php b/src/Owner/SymfonySessionOwnerFactory.php index 355b9e0..dee0f58 100644 --- a/src/Owner/SymfonySessionOwnerFactory.php +++ b/src/Owner/SymfonySessionOwnerFactory.php @@ -23,11 +23,8 @@ */ class SymfonySessionOwnerFactory implements OwnerFactoryInterface { - private RequestStack $requestStack; - - public function __construct(RequestStack $requestStack) + public function __construct(private RequestStack $requestStack) { - $this->requestStack = $requestStack; } public function createOwner(): OwnerInterface diff --git a/src/Owner/SymfonyTokenOwnerFactory.php b/src/Owner/SymfonyTokenOwnerFactory.php index 7457732..d16e4de 100644 --- a/src/Owner/SymfonyTokenOwnerFactory.php +++ b/src/Owner/SymfonyTokenOwnerFactory.php @@ -23,11 +23,8 @@ */ class SymfonyTokenOwnerFactory implements OwnerFactoryInterface { - private TokenStorageInterface $tokenStorage; - - public function __construct(TokenStorageInterface $tokenStorage) + public function __construct(private TokenStorageInterface $tokenStorage) { - $this->tokenStorage = $tokenStorage; } public function createOwner(): OwnerInterface diff --git a/src/Owner/ValueOwnerFactory.php b/src/Owner/ValueOwnerFactory.php index 762a387..62215ba 100644 --- a/src/Owner/ValueOwnerFactory.php +++ b/src/Owner/ValueOwnerFactory.php @@ -18,11 +18,8 @@ */ class ValueOwnerFactory implements OwnerFactoryInterface { - private string $value; - - public function __construct(string $value) + public function __construct(private string $value) { - $this->value = $value; } public function createOwner(): OwnerInterface diff --git a/src/Storage/FilesystemStorage.php b/src/Storage/FilesystemStorage.php index f43e38e..a84ef52 100644 --- a/src/Storage/FilesystemStorage.php +++ b/src/Storage/FilesystemStorage.php @@ -100,7 +100,7 @@ public function exists(IdentityInterface $identifier): bool return file_exists($filename); } - public function get(IdentityInterface $identifier): ?BlockInterface + public function get(IdentityInterface $identifier): BlockInterface|null { if (!$this->exists($identifier)) { return null; diff --git a/src/Storage/InMemoryStorage.php b/src/Storage/InMemoryStorage.php index 76f91cd..d5687da 100644 --- a/src/Storage/InMemoryStorage.php +++ b/src/Storage/InMemoryStorage.php @@ -63,7 +63,7 @@ public function exists(IdentityInterface $identifier): bool return isset($this->blocks[(string) $identifier]); } - public function get(IdentityInterface $identifier): ?BlockInterface + public function get(IdentityInterface $identifier): BlockInterface|null { if (!$this->exists($identifier)) { return null; diff --git a/src/Storage/StorageInterface.php b/src/Storage/StorageInterface.php index 19556d7..11c9e66 100644 --- a/src/Storage/StorageInterface.php +++ b/src/Storage/StorageInterface.php @@ -29,5 +29,5 @@ public function remove(BlockInterface $block): bool; public function exists(IdentityInterface $identifier): bool; - public function get(IdentityInterface $identifier): ?BlockInterface; + public function get(IdentityInterface $identifier): BlockInterface|null; } diff --git a/src/Validator/ExpiredValidator.php b/src/Validator/ExpiredValidator.php index dc9c157..b0dacd8 100644 --- a/src/Validator/ExpiredValidator.php +++ b/src/Validator/ExpiredValidator.php @@ -23,11 +23,8 @@ */ class ExpiredValidator implements ValidatorInterface { - private int $expireSeconds; - - public function __construct(int $expireSeconds) + public function __construct(private int $expireSeconds) { - $this->expireSeconds = $expireSeconds; } public function validate(BlockInterface $block): bool