Passed
Push — master ( 463105...84cd59 )
by Roberto
04:47
created

CertificateException::getPrivateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace NFePHP\Common\Exception;
4
5
/**
6
 * @category   NFePHP
7
 * @package    NFePHP\Common\Exception
8
 * @copyright  Copyright (c) 2008-2014
9
 * @license    http://www.gnu.org/licenses/lesser.html LGPL v3
10
 * @author     Roberto L. Machado <linux.rlm at gmail dot com>
11
 * @link       http://github.com/nfephp-org/sped-common for the canonical source repository
12
 */
13
class CertificateException extends \RuntimeException implements ExceptionInterface
14
{
15 1
    public static function unableToRead()
16
    {
17 1
        return new static('Unable to read certificate, ' . static::getOpenSSLError());
18
    }
19
20
    public static function unableToOpen()
21
    {
22
        return new static('Unable to open certificate, ' . static::getOpenSSLError());
23
    }
24
25
    public static function signContent()
26
    {
27
        return new static(
28
            'An unexpected error has occurred when sign a content, ' . static::getOpenSSLError()
29
        );
30
    }
31
32
    public static function getPrivateKey()
33
    {
34
        return new static('An error has occurred when get private key, ' . static::getOpenSSLError());
35
    }
36
37
    public static function signatureFailed()
38
    {
39
        return new static(
40
            'An error has occurred when verify signature, ' . static::getOpenSSLError()
41
        );
42
    }
43
44 1
    protected static function getOpenSSLError()
45
    {
46 1
        $error = 'get follow error: ';
47 1
        while ($msg = openssl_error_string()) {
48 1
            $error .= "($msg)";
49
        }
50 1
        return $error;
51
    }
52
}
53