Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

CryptKeysTrait::registerCryptKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 1
1
<?php
2
3
namespace ByTIC\Hello\Oauth\ServiceProvider\Traits;
4
5
use ByTIC\Hello\Utility\ConfigHelper;
6
use ByTIC\Hello\Utility\CryptHelper;
7
use League\OAuth2\Server\CryptKey;
8
9
/**
10
 * Trait CryptKeysTrait
11
 * @package ByTIC\Hello\Oauth\ServiceProvider\Traits
12
 */
13
trait CryptKeysTrait
14
{
15 2
    public function registerCryptKeys()
16
    {
17
        $this->getContainer()->share('hello.keys.private', function () {
0 ignored issues
show
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
18 2
            return $this->makeCryptKey('private');
19 2
        });
20
        $this->getContainer()->share('hello.keys.public', function () {
0 ignored issues
show
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
21 2
            return $this->makeCryptKey('public');
22 2
        });
23 2
    }
24
25
    /**
26
     * @param $return
27
     * @return array
28
     */
29
    protected function appendCryptKeysToProvide($return)
30
    {
31
        $return[] = 'hello.keys.private';
32
        $return[] = 'hello.keys.public';
33
        return $return;
34
    }
35
36
    /**
37
     * Create a CryptKey instance without permissions check
38
     *
39
     * @param  $type
40
     * @return \League\OAuth2\Server\CryptKey
41
     */
42 2
    protected function makeCryptKey($type)
43
    {
44 2
        return CryptHelper::makeCryptKey($type);
45
    }
46
}
47