Completed
Push — master ( 027ea9...6fcfe6 )
by Florent
05:03
created

JWK::without()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 2
eloc 6
nc 2
nop 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 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
        if (!array_key_exists('kty', $values)) {
32
            throw new \InvalidArgumentException('The parameter "kty" is mandatory.');
33
        }
34
        $this->values = $values;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function jsonSerialize()
41
    {
42
        return $this->getAll();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function get($key)
49
    {
50
        if ($this->has($key)) {
51
            return $this->values[$key];
52
        }
53
        throw new \InvalidArgumentException(sprintf('The value identified by "%s" does not exist.', $key));
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function has($key)
60
    {
61
        return array_key_exists($key, $this->getAll());
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getKeys()
68
    {
69
        return array_keys($this->values);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getAll()
76
    {
77
        return $this->values;
78
    }
79
}
80