KeyGeneratorException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 9
c 1
b 0
f 1
dl 0
loc 31
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A keyCreateError() 0 3 1
A __construct() 0 9 2
A csrExportError() 0 3 1
A keyExportError() 0 3 1
A csrCreateError() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the LetsEncrypt ACME client.
7
 *
8
 * @author    Ivanov Aleksandr <[email protected]>
9
 * @copyright 2019-2020
10
 * @license   https://github.com/misantron/letsencrypt-client/blob/master/LICENSE MIT License
11
 */
12
13
namespace LetsEncrypt\Exception;
14
15
final class KeyGeneratorException extends OpenSSLException
16
{
17
    private function __construct(string $prefix)
18
    {
19
        // collect OpenSSL error messages
20
        $error = $prefix . ':' . PHP_EOL;
21
        while ($message = openssl_error_string()) {
22
            $error .= $message . PHP_EOL;
23
        }
24
25
        parent::__construct($error);
26
    }
27
28
    public static function keyCreateError(string $prefix = 'Unable to generate key pair'): self
29
    {
30
        return new static($prefix);
31
    }
32
33
    public static function keyExportError(string $prefix = 'Key pair export error'): self
34
    {
35
        return new static($prefix);
36
    }
37
38
    public static function csrCreateError(string $prefix = 'Unable to generate CSR'): self
39
    {
40
        return new static($prefix);
41
    }
42
43
    public static function csrExportError(string $prefix = 'CSR export error'): self
44
    {
45
        return new static($prefix);
46
    }
47
}
48