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

RotatableJWKSet   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A rotate() 0 15 2
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
/**
15
 * Class RotatableJWKSet.
16
 */
17
final class RotatableJWKSet extends StorableJWKSet implements RotatableJWKSetInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function rotate()
23
    {
24
        $jwkset = $this->getObject();
25
26
        $keys = $jwkset->getKeys();
27
        unset($keys[count($keys) - 1]);
28
        $jwkset = new JWKSet();
29
        $jwkset->addKey($this->createJWK());
0 ignored issues
show
Bug introduced by
It seems like $this->createJWK() targeting Jose\Object\StorableJWKSet::createJWK() can also be of type object<Jose\Object\JWKSet>; however, Jose\Object\JWKSet::addKey() does only seem to accept object<Jose\Object\JWKInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
30
        foreach ($keys as $key) {
31
            $jwkset->addKey($key);
32
        }
33
        $this->jwkset = $jwkset;
0 ignored issues
show
Bug introduced by
The property jwkset does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
        $this->setObject($jwkset);
35
        $this->saveObject($jwkset);
36
    }
37
}
38