Completed
Branch zenstruck-fork (6c313f)
by Kevin
03:51
created

Key::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 9
cp 0.7778
rs 9.2
cc 4
eloc 8
nc 3
nop 1
crap 4.1755
1
<?php
2
3
namespace Zenstruck\JWT\Signer\OpenSSL;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
8
abstract class Key
9
{
10
    private $value;
11
    private $type;
12
13
    /**
14
     * @param resource $value
15
     */
16 15
    public function __construct($value)
17
    {
18 15
        if (!is_resource($value)) {
19
            throw new \InvalidArgumentException('Invalid key.');
20
        }
21
22 15
        $keyDetails = openssl_pkey_get_details($value);
23
24 15
        if (!is_array($keyDetails) || !isset($keyDetails['type'])) {
25
            throw new \InvalidArgumentException('Invalid key.');
26
        }
27
28 15
        $this->value = $value;
29 15
        $this->type = $keyDetails['type'];
30 15
    }
31
32
    /**
33
     * @return resource
34
     */
35 12
    final public function get()
36
    {
37 12
        return $this->value;
38
    }
39
40 12
    final public function type()
41
    {
42 12
        return $this->type;
43
    }
44
}
45