Failed Conditions
Push — master ( 1a5cd4...b0e5e0 )
by Florent
10:14
created

StorableJWK::loadJWK()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 5
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A StorableJWK::createObjectFromFileContent() 0 4 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 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
use Base64Url\Base64Url;
15
use Jose\Factory\JWKFactory;
16
17
/**
18
 * Class StorableJWK.
19
 */
20
class StorableJWK implements StorableJWKInterface
21
{
22
    use Storable;
23
24
    /**
25
     * @var array
26
     */
27
    protected $parameters;
28
29
    /**
30
     * RotatableJWK constructor.
31
     *
32
     * @param string $filename
33
     * @param array  $parameters
34
     */
35
    public function __construct($filename, array $parameters)
36
    {
37
        $this->setFilename($filename);
38
        $this->parameters = $parameters;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getFilename()
45
    {
46
        return $this->filename;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getAll()
53
    {
54
        return $this->getJWK()->getAll();
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function get($key)
61
    {
62
        return $this->getJWK()->get($key);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function has($key)
69
    {
70
        return $this->getJWK()->has($key);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function thumbprint($hash_algorithm)
77
    {
78
        return $this->getJWK()->thumbprint($hash_algorithm);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function toPublic()
85
    {
86
        return $this->getJWK()->toPublic();
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function jsonSerialize()
93
    {
94
        return $this->getJWK()->jsonSerialize();
95
    }
96
97
    /**
98
     * @return \Jose\Object\JWKInterface
99
     */
100
    protected function getJWK()
101
    {
102
        $this->loadObjectIfNeeded();
103
104
        return $this->getObject();
105
    }
106
107
    protected function createNewObject()
108
    {
109
        $data = JWKFactory::createKey($this->parameters)->getAll();
110
        $data['kid'] = Base64Url::encode(random_bytes(64));
111
112
        return JWKFactory::createFromValues($data);
113
    }
114
115
    /**
116
     * @param array $file_content
117
     *
118
     * @return \JsonSerializable
119
     */
120
    protected function createObjectFromFileContent(array $file_content)
121
    {
122
        return new JWK($file_content);
123
    }
124
125
126
}
127