Skip to content

Commit

Permalink
Remove Exception suffix from exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lakiboy committed Jul 5, 2018
1 parent 750ca9c commit 2207c61
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Command/Storage/LookupKeyCommand.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions Key/Storage/ChainStorage.php
Expand Up @@ -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) {
Expand All @@ -47,6 +44,6 @@ public function get(string $key): Key
}
}

throw new KeyNotFoundException();
throw new KeyNotFound();
}
}
2 changes: 1 addition & 1 deletion Key/Storage/DoctrineStorage.php
Expand Up @@ -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());
Expand Down
5 changes: 1 addition & 4 deletions Key/Storage/FixedStorage.php
Expand Up @@ -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);
Expand Down
Expand Up @@ -4,6 +4,6 @@

namespace Damax\Bundle\ApiAuthBundle\Key\Storage;

final class KeyNotFoundException extends \RuntimeException
final class KeyNotFound extends \RuntimeException
{
}
2 changes: 1 addition & 1 deletion Key/Storage/Reader.php
Expand Up @@ -11,7 +11,7 @@ interface Reader
public function has(string $key): bool;

/**
* @throws KeyNotFoundException
* @throws KeyNotFound
*/
public function get(string $key): Key;
}
5 changes: 1 addition & 4 deletions Key/Storage/RedisStorage.php
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Security/ApiKey/ApiKeyUserProvider.php
Expand Up @@ -10,7 +10,7 @@
interface ApiKeyUserProvider extends UserProviderInterface
{
/**
* @throws InvalidApiKeyException
* @throws InvalidApiKey
*/
public function loadUserByApiKey(string $apiKey): UserInterface;
}
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\Security\Core\Exception\AuthenticationException;

class InvalidApiKeyException extends AuthenticationException
class InvalidApiKey extends AuthenticationException
{
public function getMessageKey(): string
{
Expand Down
8 changes: 4 additions & 4 deletions Security/ApiKey/StorageUserProvider.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Storage/LookupKeyStorageCommandTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Key/Storage/ChainStorageTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Key/Storage/FixedStorageTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Key/Storage/RedisStorageTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Security/ApiKey/InvalidApiKeyExceptionTest.php
Expand Up @@ -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
Expand All @@ -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());
}
}
6 changes: 3 additions & 3 deletions Tests/Security/ApiKey/StorageUserProviderTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand All @@ -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);

Expand Down

0 comments on commit 2207c61

Please sign in to comment.