CryptographyException::encryptFailure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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