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

CryptKeysTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
ccs 8
cts 12
cp 0.6667
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCryptKeys() 0 9 1
A appendCryptKeysToProvide() 0 6 1
A makeCryptKey() 0 4 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