Completed
Push — master ( 668fd8...cdc0a6 )
by Florent
12:11
created

JWK::getKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 JWK.
16
 */
17
final class JWK implements JWKInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $values = [];
23
24
    /**
25
     * JWK constructor.
26
     *
27
     * @param array $values
28
     */
29
    public function __construct(array $values = [])
30
    {
31
        $this->values = $values;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function jsonSerialize()
38
    {
39
        return $this->getAll();
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function get($key)
46
    {
47
        if ($this->has($key)) {
48
            return $this->values[$key];
49
        }
50
        throw new \InvalidArgumentException(sprintf('The value identified by "%s" does not exist.', $key));
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function has($key)
57
    {
58
        return array_key_exists($key, $this->getAll());
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getKeys()
65
    {
66
        return array_keys($this->values);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getAll()
73
    {
74
        return $this->values;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function withValue($key, $value)
81
    {
82
        $jwk = clone $this;
83
        $jwk->values[$key] = $value;
84
85
        return $jwk;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function withoutValue($key)
92
    {
93
        if (!array_key_exists($key, $this->values)) {
94
            return $this;
95
        }
96
        $jwk = clone $this;
97
        unset($jwk->values[$key]);
98
99
        return $jwk;
100
    }
101
}
102