PrivateKey   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createKey() 0 11 2
A __construct() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the Pixidos package.
5
 *
6
 *  (c) Ondra Votava <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 *
11
 */
12
13
declare(strict_types=1);
14
15
namespace Pixidos\GPWebPay\Signer\Key;
16
17
use OpenSSLAsymmetricKey;
18
use Pixidos\GPWebPay\Exceptions\SignerException;
19
20
final class PrivateKey extends AbstractKey
21
{
22 21
    public function __construct(
23
        string $file,
24
        private readonly string $password
25
    ) {
26 21
        parent::__construct($file);
27
    }
28
29
30
    /**
31
     * @throws SignerException
32
     */
33 11
    protected function createKey(): OpenSSLAsymmetricKey
34
    {
35 11
        $content = $this->getContent();
36 11
        $key = openssl_pkey_get_private($content, $this->password);
37 11
        if (false === $key) {
38 1
            throw new SignerException(
39 1
                sprintf('"%s" is not valid PEM private key (or password is incorrect).', $this->file)
40 1
            );
41
        }
42
43 10
        return $key;
44
    }
45
}
46