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