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

Key   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
wmc 6
lcom 0
cbo 0
ccs 11
cts 13
cp 0.8462
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
A get() 0 4 1
A type() 0 4 1
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