Completed
Push — v2.0.x ( 7a58b6 )
by Florent
24:58
created

Recipient   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 80
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 4 1
A withHeaders() 0 7 1
A withHeader() 0 7 1
A getHeader() 0 7 2
A hasHeader() 0 4 1
A getEncryptedKey() 0 4 1
A withEncryptedKey() 0 7 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Object;
13
14
/**
15
 * Class EncryptionInstruction.
16
 */
17
final class Recipient implements RecipientInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    private $headers = [];
23
24
    /**
25
     * @var null|string
26
     */
27
    private $encrypted_key = null;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getHeaders()
33
    {
34
        return $this->headers;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function withHeaders(array $headers)
41
    {
42
        $signature = clone $this;
43
        $signature->headers = $headers;
44
45
        return $signature;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function withHeader($key, $value)
52
    {
53
        $signature = clone $this;
54
        $signature->headers[$key] = $value;
55
56
        return $signature;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getHeader($key)
63
    {
64
        if ($this->hasHeader($key)) {
65
            return $this->headers[$key];
66
        }
67
        throw new \InvalidArgumentException(sprintf('The header "%s" does not exist', $key));
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function hasHeader($key)
74
    {
75
        return array_key_exists($key, $this->headers);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getEncryptedKey()
82
    {
83
        return $this->encrypted_key;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function withEncryptedKey($encrypted_key)
90
    {
91
        $recipient = clone $this;
92
        $recipient->encrypted_key = $encrypted_key;
93
94
        return $recipient;
95
    }
96
}
97