Completed
Push — master ( 65e224...f25ceb )
by Florent
03:47
created

RotatableJWK::toPublic()   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-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 Assert\Assertion;
15
use Base64Url\Base64Url;
16
use Jose\Factory\JWKFactory;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * Class RotatableJWK.
21
 */
22
final class RotatableJWK implements JWKInterface
23
{
24
    /**
25
     * @var \Jose\Object\JWKInterface
26
     */
27
    private $jwk;
28
29
    /**
30
     * @var string
31
     */
32
    private $filename;
33
34
    /**
35
     * @var int
36
     */
37
    private $ttl;
38
39
    /**
40
     * @var array
41
     */
42
    private $parameters;
43
44
    /**
45
     * RotatableJWK constructor.
46
     *
47
     * @param string $filename
48
     * @param array  $parameters
49
     * @param int    $ttl
50
     */
51
    public function __construct($filename, array $parameters, $ttl = 0)
52
    {
53
        Assertion::directory(basename($filename), 'The selected directory does not exist.');
54
        $this->filename = $filename;
55
        $this->parameters = $parameters;
56
        $this->ttl = $ttl;
57
    }
58
59
    /**
60
     * @return \Jose\Object\JWKInterface
61
     */
62
    private function getJWK()
63
    {
64
        if (null === $this->jwk) {
65
            $this->createJWK();
66
        }
67
        return $this->jwk;
68
    }
69
    
70
    private function loadJWK()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
71
    {
72
    }
73
74
    private function createJWK()
75
    {
76
        $jwk = JWKFactory::createKey($this->parameters);
0 ignored issues
show
Unused Code introduced by
$jwk is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getAll()
83
    {
84
        return $this->getJWK()->getAll();
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function get($key)
91
    {
92
        return $this->getJWK()->get($key);
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function has($key)
99
    {
100
        return $this->getJWK()->has($key);
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function thumbprint($hash_algorithm)
107
    {
108
        return $this->getJWK()->thumbprint($hash_algorithm);
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function toPublic()
115
    {
116
        return $this->getJWK()->toPublic();
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function jsonSerialize()
123
    {
124
        return $this->getJWK()->jsonSerialize();
125
    }
126
}
127