Completed
Pull Request — master (#46)
by Antonio Oertel
04:53
created

CertificateException::unableToOpen()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
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/nfephp for the canonical source repository
12
 */
13
class CertificateException extends \RuntimeException implements ExceptionInterface
14
{
15
    public static function unableToRead()
16
    {
17
        return new static('Unable to read certificate, get follow error: ' . static::getOpenSSLError());
0 ignored issues
show
Bug introduced by
Since getOpenSSLError() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getOpenSSLError() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
18
    }
19
20
    public static function unableToOpen()
21
    {
22
        return new static('Unable to open certificate, get follow error: ' . static::getOpenSSLError());
0 ignored issues
show
Bug introduced by
Since getOpenSSLError() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getOpenSSLError() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
23
    }
24
25
    public static function signContent()
26
    {
27
        return new static(
28
            'An unexpected error has occurred when sign a content, get follow error: ' . static::getOpenSSLError()
0 ignored issues
show
Bug introduced by
Since getOpenSSLError() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getOpenSSLError() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
29
        );
30
    }
31
32
    public static function getPrivateKey()
33
    {
34
        return new static('An error has occurred when get private key, get follow error: ' . static::getOpenSSLError());
0 ignored issues
show
Bug introduced by
Since getOpenSSLError() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getOpenSSLError() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
35
    }
36
37
    private static function getOpenSSLError()
38
    {
39
        $error = '';
40
        while ($msg = openssl_error_string()) {
41
            $error .= "($msg)";
42
        }
43
        return $error;
44
    }
45
}
46