JwtBearerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 3
dl 10
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMissingConfigException() 0 5 1
A testPrivateKeyNotSplFileObject() 0 8 1
A testValidRequestGetsToken() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace CommerceGuys\Guzzle\Oauth2\Tests\GrantType;
4
5
use CommerceGuys\Guzzle\Oauth2\GrantType\JwtBearer;
6
use CommerceGuys\Guzzle\Oauth2\Tests\TestBase;
7
use SplFileObject;
8
9
class JwtBearerTest extends TestBase
10
{
11
    public function testMissingConfigException()
12
    {
13
        $this->setExpectedException('\\InvalidArgumentException', 'Config is missing the following keys: client_id, private_key');
14
        new JwtBearer($this->getClient());
15
    }
16
17
    public function testPrivateKeyNotSplFileObject()
18
    {
19
        $this->setExpectedException('\\InvalidArgumentException', 'private_key needs to be instance of SplFileObject');
20
        $grantType = new JwtBearer($this->getClient(), [
0 ignored issues
show
Unused Code introduced by
$grantType 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...
21
            'client_id' => 'testClient',
22
            'private_key' => 'INVALID'
23
        ]);
24
    }
25
26 View Code Duplication
    public function testValidRequestGetsToken()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $grantType = new JwtBearer($this->getClient(), [
29
            'client_id' => 'testClient',
30
            'private_key' => new SplFileObject(__DIR__ . '/../private.key')
31
        ]);
32
        $token = $grantType->getToken();
33
        $this->assertNotEmpty($token->getToken());
34
        $this->assertTrue($token->getExpires()->getTimestamp() > time());
35
    }
36
}
37