diff --git a/Command/Storage/LookupKeyCommand.php b/Command/Storage/LookupKeyCommand.php index ff18763..ef17104 100644 --- a/Command/Storage/LookupKeyCommand.php +++ b/Command/Storage/LookupKeyCommand.php @@ -4,7 +4,7 @@ namespace Damax\Bundle\ApiAuthBundle\Command\Storage; -use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFoundException; +use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound; use Damax\Bundle\ApiAuthBundle\Key\Storage\Reader as Storage; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $key = $this->storage->get($input->getArgument('key')); - } catch (KeyNotFoundException $e) { + } catch (KeyNotFound $e) { $io->error('Key not found.'); return 1; diff --git a/Key/Storage/ChainStorage.php b/Key/Storage/ChainStorage.php index f6b5cbf..c2656a7 100644 --- a/Key/Storage/ChainStorage.php +++ b/Key/Storage/ChainStorage.php @@ -36,9 +36,6 @@ public function has(string $key): bool return false; } - /** - * @throws KeyNotFoundException - */ public function get(string $key): Key { foreach ($this->items as $storage) { @@ -47,6 +44,6 @@ public function get(string $key): Key } } - throw new KeyNotFoundException(); + throw new KeyNotFound(); } } diff --git a/Key/Storage/DoctrineStorage.php b/Key/Storage/DoctrineStorage.php index ef4fbfd..12c8683 100644 --- a/Key/Storage/DoctrineStorage.php +++ b/Key/Storage/DoctrineStorage.php @@ -59,7 +59,7 @@ public function get(string $key): Key $sql = sprintf('SELECT %s FROM %s WHERE %s = ?', $fields, $this->tableName, $this->fields[self::FIELD_KEY]); if (false === $row = $this->db->executeQuery($sql, [$key])->fetch(FetchMode::ASSOCIATIVE)) { - throw new KeyNotFoundException(); + throw new KeyNotFound(); } return new Key($key, $row[$this->fields[self::FIELD_IDENTITY]], $row[$this->fields[self::FIELD_TTL]] - time()); diff --git a/Key/Storage/FixedStorage.php b/Key/Storage/FixedStorage.php index 98ad631..d9f1869 100644 --- a/Key/Storage/FixedStorage.php +++ b/Key/Storage/FixedStorage.php @@ -22,13 +22,10 @@ public function has(string $key): bool return (bool) array_search($key, $this->data); } - /** - * @throws KeyNotFoundException - */ public function get(string $key): Key { if (false === $identity = array_search($key, $this->data)) { - throw new KeyNotFoundException(); + throw new KeyNotFound(); } return new Key($key, $identity, $this->ttl); diff --git a/Key/Storage/KeyNotFoundException.php b/Key/Storage/KeyNotFound.php similarity index 59% rename from Key/Storage/KeyNotFoundException.php rename to Key/Storage/KeyNotFound.php index 43e83b3..022a58d 100644 --- a/Key/Storage/KeyNotFoundException.php +++ b/Key/Storage/KeyNotFound.php @@ -4,6 +4,6 @@ namespace Damax\Bundle\ApiAuthBundle\Key\Storage; -final class KeyNotFoundException extends \RuntimeException +final class KeyNotFound extends \RuntimeException { } diff --git a/Key/Storage/Reader.php b/Key/Storage/Reader.php index f842a40..15fcd69 100644 --- a/Key/Storage/Reader.php +++ b/Key/Storage/Reader.php @@ -11,7 +11,7 @@ interface Reader public function has(string $key): bool; /** - * @throws KeyNotFoundException + * @throws KeyNotFound */ public function get(string $key): Key; } diff --git a/Key/Storage/RedisStorage.php b/Key/Storage/RedisStorage.php index ba53104..5b667ea 100644 --- a/Key/Storage/RedisStorage.php +++ b/Key/Storage/RedisStorage.php @@ -21,13 +21,10 @@ public function has(string $key): bool return (bool) $this->client->exists($key); } - /** - * @throws KeyNotFoundException - */ public function get(string $key): Key { if (null === $identity = $this->client->get($key)) { - throw new KeyNotFoundException(); + throw new KeyNotFound(); } return new Key($key, $identity, $this->client->ttl($key)); diff --git a/Security/ApiKey/ApiKeyUserProvider.php b/Security/ApiKey/ApiKeyUserProvider.php index fc635eb..b70bcb7 100644 --- a/Security/ApiKey/ApiKeyUserProvider.php +++ b/Security/ApiKey/ApiKeyUserProvider.php @@ -10,7 +10,7 @@ interface ApiKeyUserProvider extends UserProviderInterface { /** - * @throws InvalidApiKeyException + * @throws InvalidApiKey */ public function loadUserByApiKey(string $apiKey): UserInterface; } diff --git a/Security/ApiKey/InvalidApiKeyException.php b/Security/ApiKey/InvalidApiKey.php similarity index 80% rename from Security/ApiKey/InvalidApiKeyException.php rename to Security/ApiKey/InvalidApiKey.php index e8c3c53..bcc5184 100644 --- a/Security/ApiKey/InvalidApiKeyException.php +++ b/Security/ApiKey/InvalidApiKey.php @@ -6,7 +6,7 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException; -class InvalidApiKeyException extends AuthenticationException +class InvalidApiKey extends AuthenticationException { public function getMessageKey(): string { diff --git a/Security/ApiKey/StorageUserProvider.php b/Security/ApiKey/StorageUserProvider.php index 77d82df..8604201 100644 --- a/Security/ApiKey/StorageUserProvider.php +++ b/Security/ApiKey/StorageUserProvider.php @@ -4,7 +4,7 @@ namespace Damax\Bundle\ApiAuthBundle\Security\ApiKey; -use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFoundException; +use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound; use Damax\Bundle\ApiAuthBundle\Key\Storage\Reader as Storage; use Damax\Bundle\ApiAuthBundle\Security\ApiUser; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; @@ -33,12 +33,12 @@ public function loadUserByApiKey(string $apiKey): UserInterface { try { $key = $this->storage->get($apiKey); - } catch (KeyNotFoundException $e) { - throw new InvalidApiKeyException(); + } catch (KeyNotFound $e) { + throw new InvalidApiKey(); } if ($key->expired()) { - throw new InvalidApiKeyException(); + throw new InvalidApiKey(); } return $this->loadUserByUsername($key->identity()); diff --git a/Tests/Command/Storage/LookupKeyStorageCommandTest.php b/Tests/Command/Storage/LookupKeyStorageCommandTest.php index 5e2013f..1eea053 100644 --- a/Tests/Command/Storage/LookupKeyStorageCommandTest.php +++ b/Tests/Command/Storage/LookupKeyStorageCommandTest.php @@ -6,7 +6,7 @@ use Damax\Bundle\ApiAuthBundle\Command\Storage\LookupKeyCommand; use Damax\Bundle\ApiAuthBundle\Key\Key; -use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFoundException; +use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound; use Damax\Bundle\ApiAuthBundle\Key\Storage\Storage; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Command\Command; @@ -67,7 +67,7 @@ public function it_fails_to_find_key() ->expects($this->once()) ->method('get') ->with('XYZ') - ->willThrowException(new KeyNotFoundException()) + ->willThrowException(new KeyNotFound()) ; $code = $this->tester->execute(['command' => 'damax:api-auth:storage:lookup-key', 'key' => 'XYZ']); diff --git a/Tests/Key/Storage/ChainStorageTest.php b/Tests/Key/Storage/ChainStorageTest.php index 055fb0c..261441b 100644 --- a/Tests/Key/Storage/ChainStorageTest.php +++ b/Tests/Key/Storage/ChainStorageTest.php @@ -6,7 +6,7 @@ use Damax\Bundle\ApiAuthBundle\Key\Storage\ChainStorage; use Damax\Bundle\ApiAuthBundle\Key\Storage\FixedStorage; -use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFoundException; +use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound; use PHPUnit\Framework\TestCase; class ChainStorageTest extends TestCase @@ -57,7 +57,7 @@ public function it_retrieves_key() */ public function it_throws_exception_when_retrieving_missing_key() { - $this->expectException(KeyNotFoundException::class); + $this->expectException(KeyNotFound::class); $this->storage->get('123'); } diff --git a/Tests/Key/Storage/FixedStorageTest.php b/Tests/Key/Storage/FixedStorageTest.php index e9497ca..57b467b 100644 --- a/Tests/Key/Storage/FixedStorageTest.php +++ b/Tests/Key/Storage/FixedStorageTest.php @@ -5,7 +5,7 @@ namespace Damax\Bundle\ApiAuthBundle\Tests\Key\Storage; use Damax\Bundle\ApiAuthBundle\Key\Storage\FixedStorage; -use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFoundException; +use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound; use PHPUnit\Framework\TestCase; class FixedStorageTest extends TestCase @@ -51,7 +51,7 @@ public function it_retrieves_key(FixedStorage $storage) */ public function it_throws_exception_when_retrieving_missing_key(FixedStorage $storage) { - $this->expectException(KeyNotFoundException::class); + $this->expectException(KeyNotFound::class); $storage->get('123'); } diff --git a/Tests/Key/Storage/RedisStorageTest.php b/Tests/Key/Storage/RedisStorageTest.php index 5a5103d..e0e750b 100644 --- a/Tests/Key/Storage/RedisStorageTest.php +++ b/Tests/Key/Storage/RedisStorageTest.php @@ -5,7 +5,7 @@ namespace Damax\Bundle\ApiAuthBundle\Tests\Key\Storage; use Damax\Bundle\ApiAuthBundle\Key\Key; -use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFoundException; +use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound; use Damax\Bundle\ApiAuthBundle\Key\Storage\RedisStorage; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -107,7 +107,7 @@ public function it_fails_retrieving_missing_key() ->with('get', ['XYZ']) ; - $this->expectException(KeyNotFoundException::class); + $this->expectException(KeyNotFound::class); $this->storage->get('XYZ'); } diff --git a/Tests/Security/ApiKey/InvalidApiKeyExceptionTest.php b/Tests/Security/ApiKey/InvalidApiKeyExceptionTest.php index 69a3e90..2cf1c7c 100644 --- a/Tests/Security/ApiKey/InvalidApiKeyExceptionTest.php +++ b/Tests/Security/ApiKey/InvalidApiKeyExceptionTest.php @@ -4,7 +4,7 @@ namespace Damax\Bundle\ApiAuthBundle\Tests\Security\ApiKey; -use Damax\Bundle\ApiAuthBundle\Security\ApiKey\InvalidApiKeyException; +use Damax\Bundle\ApiAuthBundle\Security\ApiKey\InvalidApiKey; use PHPUnit\Framework\TestCase; class InvalidApiKeyExceptionTest extends TestCase @@ -14,6 +14,6 @@ class InvalidApiKeyExceptionTest extends TestCase */ public function it_verifies_message_key() { - $this->assertEquals('Invalid api key.', (new InvalidApiKeyException())->getMessageKey()); + $this->assertEquals('Invalid api key.', (new InvalidApiKey())->getMessageKey()); } } diff --git a/Tests/Security/ApiKey/StorageUserProviderTest.php b/Tests/Security/ApiKey/StorageUserProviderTest.php index b6ff714..7557e29 100644 --- a/Tests/Security/ApiKey/StorageUserProviderTest.php +++ b/Tests/Security/ApiKey/StorageUserProviderTest.php @@ -5,7 +5,7 @@ namespace Damax\Bundle\ApiAuthBundle\Tests\Security\ApiKey; use Damax\Bundle\ApiAuthBundle\Key\Storage\FixedStorage; -use Damax\Bundle\ApiAuthBundle\Security\ApiKey\InvalidApiKeyException; +use Damax\Bundle\ApiAuthBundle\Security\ApiKey\InvalidApiKey; use Damax\Bundle\ApiAuthBundle\Security\ApiKey\StorageUserProvider; use Damax\Bundle\ApiAuthBundle\Security\ApiUser; use PHPUnit\Framework\TestCase; @@ -70,7 +70,7 @@ public function it_loads_user_by_api_key() */ public function it_throws_exception_when_loading_user_with_unregistered_api_key() { - $this->expectException(InvalidApiKeyException::class); + $this->expectException(InvalidApiKey::class); $this->userProvider->loadUserByApiKey('123'); } @@ -80,7 +80,7 @@ public function it_throws_exception_when_loading_user_with_unregistered_api_key( */ public function it_throws_exception_when_loading_user_with_expired_key() { - $this->expectException(InvalidApiKeyException::class); + $this->expectException(InvalidApiKey::class); $storage = new FixedStorage(['foo' => 'ABC', 'bar' => 'XYZ'], 0);