Failed Conditions
Push — master ( 5a7fe0...97bdf0 )
by Florent
03:16 queued 01:22
created

Recipient::hasHeaderParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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
/**
17
 * Class Recipient.
18
 */
19
final class Recipient
20
{
21
    /**
22
     * @var array
23
     */
24
    private $header = [];
25
26
    /**
27
     * @var null|string
28
     */
29
    private $encryptedKey = null;
30
31
    /**
32
     * Recipient constructor.
33
     *
34
     * @param array       $header
35
     * @param null|string $encryptedKey
36
     */
37
    private function __construct(array $header, ?string $encryptedKey)
38
    {
39
        $this->header = $header;
40
        $this->encryptedKey = $encryptedKey;
41
    }
42
43
    /**
44
     * @param array       $header
45
     * @param null|string $encryptedKey
46
     *
47
     * @return Recipient
48
     */
49
    public static function create(array $header = [], ?string $encryptedKey): self
50
    {
51
        return new self($header, $encryptedKey);
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getHeader(): array
58
    {
59
        return $this->header;
60
    }
61
62
    /**
63
     * Returns the value of the unprotected header of the specified key.
64
     *
65
     * @param string $key The key
66
     *
67
     * @return mixed|null Header value
68
     */
69
    public function getHeaderParameter(string $key)
70
    {
71
        if ($this->hasHeaderParameter($key)) {
72
            return $this->header[$key];
73
        }
74
75
        throw new \InvalidArgumentException(sprintf('The header "%s" does not exist.', $key));
76
    }
77
78
    /**
79
     * @param string $key The key
80
     *
81
     * @return bool
82
     */
83
    public function hasHeaderParameter(string $key): bool
84
    {
85
        return array_key_exists($key, $this->header);
86
    }
87
88
    /**
89
     * @return null|string
90
     */
91
    public function getEncryptedKey(): ?string
92
    {
93
        return $this->encryptedKey;
94
    }
95
}
96