Skip to content

Commit 07873ea

Browse files
authored
refactor: consistent exception naming (#1308)
1 parent c17719b commit 07873ea

File tree

231 files changed

+633
-645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+633
-645
lines changed

packages/auth/src/CurrentUserNotLoggedIn.php renamed to packages/auth/src/AuthenticatedUserWasMissing.php

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

77
use Exception;
88

9-
final class CurrentUserNotLoggedIn extends Exception
9+
final class AuthenticatedUserWasMissing extends Exception
1010
{
1111
public function __construct()
1212
{

packages/auth/src/CurrentUserInitializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con
2222
$user = $container->get(Authenticator::class)->currentUser();
2323

2424
if (! $user) {
25-
throw new CurrentUserNotLoggedIn();
25+
throw new AuthenticatedUserWasMissing();
2626
}
2727

2828
return $user;

packages/cache/src/CouldNotClearCache.php renamed to packages/cache/src/CacheCouldNotBeCleared.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
use Exception;
88

9-
final class CouldNotClearCache extends Exception implements CacheException
9+
final class CacheCouldNotBeCleared extends Exception implements CacheException
1010
{
1111
}

packages/cache/src/NotNumberException.php renamed to packages/cache/src/CacheKeyCouldNotBeIncremented.php

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

55
use Exception;
66

7-
final class NotNumberException extends Exception implements CacheException
7+
final class CacheKeyCouldNotBeIncremented extends Exception implements CacheException
88
{
99
public function __construct(
1010
public readonly string $key,

packages/cache/src/ForbiddenCacheUsageException.php renamed to packages/cache/src/CacheUsageWasForbidden.php

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

55
use Exception;
66

7-
final class ForbiddenCacheUsageException extends Exception implements CacheException
7+
final class CacheUsageWasForbidden extends Exception implements CacheException
88
{
99
public function __construct(
1010
public readonly ?string $tag = null,

packages/cache/src/GenericCache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function increment(Stringable|string $key, int $by = 1): int
9090
if (! $item->isHit()) {
9191
$item->set($by);
9292
} elseif (! is_numeric($item->get())) {
93-
throw new NotNumberException((string) $key);
93+
throw new CacheKeyCouldNotBeIncremented((string) $key);
9494
} else {
9595
$item->set(((int) $item->get()) + $by);
9696
}
@@ -111,7 +111,7 @@ public function decrement(Stringable|string $key, int $by = 1): int
111111
if (! $item->isHit()) {
112112
$item->set(-$by);
113113
} elseif (! is_numeric($item->get())) {
114-
throw new NotNumberException((string) $key);
114+
throw new CacheKeyCouldNotBeIncremented((string) $key);
115115
} else {
116116
$item->set(((int) $item->get()) - $by);
117117
}
@@ -215,7 +215,7 @@ public function remove(Stringable|string $key): void
215215
public function clear(): void
216216
{
217217
if (! $this->adapter->clear()) {
218-
throw new CouldNotClearCache();
218+
throw new CacheCouldNotBeCleared();
219219
}
220220
}
221221
}

packages/cache/src/GenericLock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function execute(Closure $callback, null|DateTimeInterface|Duration $wait
5050

5151
while (! $this->acquire()) {
5252
if ($waitUntil->beforeOrAtTheSameTime(DateTime::now())) {
53-
throw new LockAcquisitionTimedOutException($this->key);
53+
throw new LockAcquisitionTimedOut($this->key);
5454
}
5555

5656
usleep(250); // TODO: sleep from clock?

packages/cache/src/LockAcquisitionTimedOutException.php renamed to packages/cache/src/LockAcquisitionTimedOut.php

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

55
use Exception;
66

7-
final class LockAcquisitionTimedOutException extends Exception implements CacheException
7+
final class LockAcquisitionTimedOut extends Exception implements CacheException
88
{
99
public function __construct(
1010
public readonly string $key,

packages/cache/src/Testing/RestrictedCache.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Psr\Cache\CacheItemInterface;
77
use Stringable;
88
use Tempest\Cache\Cache;
9-
use Tempest\Cache\ForbiddenCacheUsageException;
9+
use Tempest\Cache\CacheUsageWasForbidden;
1010
use Tempest\Cache\Lock;
1111
use Tempest\DateTime\DateTimeInterface;
1212
use Tempest\DateTime\Duration;
@@ -20,56 +20,56 @@ public function __construct(
2020

2121
public function lock(Stringable|string $key, null|Duration|DateTimeInterface $expiration = null, null|Stringable|string $owner = null): Lock
2222
{
23-
throw new ForbiddenCacheUsageException($this->tag);
23+
throw new CacheUsageWasForbidden($this->tag);
2424
}
2525

2626
public function has(Stringable|string $key): bool
2727
{
28-
throw new ForbiddenCacheUsageException($this->tag);
28+
throw new CacheUsageWasForbidden($this->tag);
2929
}
3030

3131
public function put(Stringable|string $key, mixed $value, null|Duration|DateTimeInterface $expiration = null): CacheItemInterface
3232
{
33-
throw new ForbiddenCacheUsageException($this->tag);
33+
throw new CacheUsageWasForbidden($this->tag);
3434
}
3535

3636
public function putMany(iterable $values, null|Duration|DateTimeInterface $expiration = null): array
3737
{
38-
throw new ForbiddenCacheUsageException($this->tag);
38+
throw new CacheUsageWasForbidden($this->tag);
3939
}
4040

4141
public function increment(Stringable|string $key, int $by = 1): int
4242
{
43-
throw new ForbiddenCacheUsageException($this->tag);
43+
throw new CacheUsageWasForbidden($this->tag);
4444
}
4545

4646
public function decrement(Stringable|string $key, int $by = 1): int
4747
{
48-
throw new ForbiddenCacheUsageException($this->tag);
48+
throw new CacheUsageWasForbidden($this->tag);
4949
}
5050

5151
public function get(Stringable|string $key): mixed
5252
{
53-
throw new ForbiddenCacheUsageException($this->tag);
53+
throw new CacheUsageWasForbidden($this->tag);
5454
}
5555

5656
public function getMany(iterable $key): array
5757
{
58-
throw new ForbiddenCacheUsageException($this->tag);
58+
throw new CacheUsageWasForbidden($this->tag);
5959
}
6060

6161
public function resolve(Stringable|string $key, Closure $callback, null|Duration|DateTimeInterface $expiration = null, ?Duration $stale = null): mixed
6262
{
63-
throw new ForbiddenCacheUsageException($this->tag);
63+
throw new CacheUsageWasForbidden($this->tag);
6464
}
6565

6666
public function remove(Stringable|string $key): void
6767
{
68-
throw new ForbiddenCacheUsageException($this->tag);
68+
throw new CacheUsageWasForbidden($this->tag);
6969
}
7070

7171
public function clear(): void
7272
{
73-
throw new ForbiddenCacheUsageException($this->tag);
73+
throw new CacheUsageWasForbidden($this->tag);
7474
}
7575
}

packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Tempest\CommandBus\AsyncCommandRepositories;
66

77
use Tempest\CommandBus\CommandRepository;
8-
use Tempest\CommandBus\Exceptions\CouldNotResolveCommand;
8+
use Tempest\CommandBus\Exceptions\PendingCommandCouldNotBeResolved;
99

1010
use function Tempest\Support\arr;
1111

@@ -23,7 +23,7 @@ public function findPendingCommand(string $uuid): object
2323
$path = __DIR__ . "/../stored-commands/{$uuid}.pending.txt";
2424

2525
if (! file_exists($path)) {
26-
throw new CouldNotResolveCommand($uuid);
26+
throw new PendingCommandCouldNotBeResolved($uuid);
2727
}
2828

2929
$payload = file_get_contents($path);

0 commit comments

Comments
 (0)