CryptographyException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 34
ccs 10
cts 10
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A decryptFailure() 0 4 1
A fromThrowable() 0 3 1
A encryptFailure() 0 4 1
A decodeFailure() 0 4 1
A notEncrypted() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\Cryptography\Exception;
6
7
use JetBrains\PhpStorm\Pure;
8
9
class CryptographyException extends \LogicException
10
{
11
    public const DECRYPT_FAILURE_MESSAGE = 'Decrypt of payload is failure';
12
    public const ENCRYPT_FAILURE_MESSAGE = 'Encrypt of payload is failure';
13
    public const DECODE_BASE64_FAILURE_MESSAGE = 'Decode of base64 payload is failure';
14
    public const NOT_ENCRYPTED_PAYLOAD_MESSAGE = 'Payload is not encrypted';
15
16 3
    public static function fromThrowable(\Throwable $previous): self
17
    {
18 3
        return new self($previous->getMessage(), $previous->getCode(), $previous);
19
    }
20
21 1
    #[Pure]
22
    public static function decryptFailure(): self
23
    {
24 1
        return new self(self::DECRYPT_FAILURE_MESSAGE);
25
    }
26
27 1
    #[Pure]
28
    public static function encryptFailure(): self
29
    {
30 1
        return new self(self::ENCRYPT_FAILURE_MESSAGE);
31
    }
32
33 1
    #[Pure]
34
    public static function decodeFailure(): self
35
    {
36 1
        return new self(self::DECODE_BASE64_FAILURE_MESSAGE);
37
    }
38
39 1
    #[Pure]
40
    public static function notEncrypted(): self
41
    {
42 1
        return new self(self::NOT_ENCRYPTED_PAYLOAD_MESSAGE);
43
    }
44
}
45