Recipient::getHeaderParameter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Encryption;
15
16
use InvalidArgumentException;
17
18
/**
19
 * @internal
20
 */
21
class Recipient
22
{
23
    /**
24
     * @var array
25
     */
26
    private $header = [];
27
28
    /**
29
     * @var null|string
30
     */
31
    private $encryptedKey;
32
33
    public function __construct(array $header, ?string $encryptedKey)
34
    {
35
        $this->header = $header;
36
        $this->encryptedKey = $encryptedKey;
37
    }
38
39
    /**
40
     * Returns the recipient header.
41
     */
42
    public function getHeader(): array
43
    {
44
        return $this->header;
45
    }
46
47
    /**
48
     * Returns the value of the recipient header parameter with the specified key.
49
     *
50
     * @param string $key The key
51
     *
52
     * @throws InvalidArgumentException if the header parameter does not exist
53
     *
54
     * @return null|mixed
55
     */
56
    public function getHeaderParameter(string $key)
57
    {
58
        if (!$this->hasHeaderParameter($key)) {
59
            throw new InvalidArgumentException(sprintf('The header "%s" does not exist.', $key));
60
        }
61
62
        return $this->header[$key];
63
    }
64
65
    /**
66
     * Returns true if the recipient header contains the parameter with the specified key.
67
     *
68
     * @param string $key The key
69
     */
70
    public function hasHeaderParameter(string $key): bool
71
    {
72
        return \array_key_exists($key, $this->header);
73
    }
74
75
    /**
76
     * Returns the encrypted key.
77
     */
78
    public function getEncryptedKey(): ?string
79
    {
80
        return $this->encryptedKey;
81
    }
82
}
83