Passed
Pull Request — master (#1228)
by Richard
04:38
created

Key::getAlgorithm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Firebase\JWT;
4
5
use InvalidArgumentException;
6
use OpenSSLAsymmetricKey;
7
8
class Key
9
{
10
    /** @var string $algorithm */
11
    private $algorithm;
12
13
    /** @var string|resource|OpenSSLAsymmetricKey $keyMaterial */
14
    private $keyMaterial;
15
16
    /**
17
     * @param string|resource|OpenSSLAsymmetricKey $keyMaterial
18
     * @param string $algorithm
19
     */
20
    public function __construct($keyMaterial, $algorithm)
21
    {
22
        if (
23
            !is_string($keyMaterial)
24
            && !is_resource($keyMaterial)
25
            && !$keyMaterial instanceof OpenSSLAsymmetricKey
0 ignored issues
show
introduced by
$keyMaterial is always a sub-type of OpenSSLAsymmetricKey.
Loading history...
26
        ) {
27
            throw new InvalidArgumentException('Type error: $keyMaterial must be a string, resource, or OpenSSLAsymmetricKey');
28
        }
29
30
        if (empty($keyMaterial)) {
31
            throw new InvalidArgumentException('Type error: $keyMaterial must not be empty');
32
        }
33
34
        if (!is_string($algorithm)|| empty($keyMaterial)) {
0 ignored issues
show
introduced by
The condition is_string($algorithm) is always true.
Loading history...
35
            throw new InvalidArgumentException('Type error: $algorithm must be a string');
36
        }
37
38
        $this->keyMaterial = $keyMaterial;
39
        $this->algorithm = $algorithm;
40
    }
41
42
    /**
43
     * Return the algorithm valid for this key
44
     *
45
     * @return string
46
     */
47
    public function getAlgorithm()
48
    {
49
        return $this->algorithm;
50
    }
51
52
    /**
53
     * @return string|resource|OpenSSLAsymmetricKey
54
     */
55
    public function getKeyMaterial()
56
    {
57
        return $this->keyMaterial;
58
    }
59
}
60