PrivateKey   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A __toString() 0 4 1
A __debugInfo() 0 5 1
1
<?php declare(strict_types = 1);
2
3
namespace Link0\Bunq\Domain\Keypair;
4
5
use \InvalidArgumentException;
6
7
final class PrivateKey
8
{
9
    /**
10
     * @var string
11
     */
12
    private $key;
13
14
    /**
15
     * @param string $privateKey
16
     */
17
    public function __construct(string $privateKey)
18
    {
19
        if (!preg_match('/^\-\-\-\-\-BEGIN PRIVATE KEY\-\-\-\-\-[\S\n]+\-\-\-\-\-END PRIVATE KEY\-\-\-\-\-$/', $privateKey)) {
20
            throw new InvalidArgumentException("Invalid PrivateKey format. Please use a shielded format");
21
        }
22
23
        $this->key = $privateKey;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function __toString()
30
    {
31
        return $this->key;
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    public function __debugInfo()
38
    {
39
        // Hide the actual key from backtraces
40
        return ['key' => '***PRIVATE KEY***'];
41
    }
42
}
43