Lines 70.00% 7 / 10
Functions and Methods 40.00% 2 / 5
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
RegistryEditException 70.00% 7 / 10 40.00% 2 / 5 6.97 0.00% 0 / 1
 notFound 100.00% 1 / 1 100.00% 1 / 1 1
 nothingToUpdate 0.00% 0 / 1 0.00% 0 / 1 2
 rejected 100.00% 6 / 6 100.00% 1 / 1 2
 unreachable 0.00% 0 / 1 0.00% 0 / 1 2
 timedOut 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Exception;
6
7use Stewart\Contracts\Entity\EntityId;
8use Throwable;
9
10/** @extends StewartException<RegistryEditError> */
11final class RegistryEditException extends StewartException
12{
13    public static function notFound(EntityId $entityId): self
14    {
15        return self::createForReason(RegistryEditError::NotFound, entityId: $entityId->value);
16    }
17
18    public static function nothingToUpdate(EntityId $entityId): self
19    {
20        return self::createForReason(RegistryEditError::NothingToUpdate, entityId: $entityId->value);
21    }
22
23    public static function rejected(EntityId $entityId, string $detail, ?string $errorCode = null, ?Throwable $previous = null): self
24    {
25        return self::createForReasonWithAppendedText(
26            RegistryEditError::Rejected,
27            ['entityId' => $entityId->value, 'detail' => $detail, 'errorCode' => $errorCode],
28            $errorCode === null ? null : '(' . $errorCode . ')',
29            $previous,
30        );
31    }
32
33    public static function unreachable(EntityId $entityId, string $detail, ?Throwable $previous = null): self
34    {
35        return self::createForReason(RegistryEditError::Unreachable, $previous, entityId: $entityId->value, detail: $detail);
36    }
37
38    public static function timedOut(EntityId $entityId, string $detail, ?Throwable $previous = null): self
39    {
40        return self::createForReason(RegistryEditError::TimedOut, $previous, entityId: $entityId->value, detail: $detail);
41    }
42}