Completed
Pull Request — master (#20)
by Harry
11:39 queued 03:51
created

AccessTokenTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 32.65 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 16
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testTokenWithNoExpiryIsNeverExpired() 0 7 1
A testTokenWithExpiryIsShown() 8 8 1
A testTokenWithExpiryAsNowIsExpired() 8 8 1
A testProperties() 0 20 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
 * This file is part of graze/gigya-client
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/gigya-client/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/gigya-client
12
 */
13
14
namespace Graze\Gigya\Test\Unit\Auth\OAuth2;
15
16
use DateInterval;
17
use DateTime;
18
use Graze\Gigya\Auth\OAuth2\AccessToken;
19
use Graze\Gigya\Test\TestCase;
20
21
class AccessTokenTest extends TestCase
22
{
23
    public function testTokenWithNoExpiryIsNeverExpired()
24
    {
25
        $token = new AccessToken('token');
26
        static::assertEquals('token', $token->getToken());
27
        static::assertNull($token->getExpires());
28
        static::assertFalse($token->isExpired());
29
    }
30
31 View Code Duplication
    public function testTokenWithExpiryIsShown()
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...
32
    {
33
        $expires = (new DateTime())->add(new DateInterval('PT60S'));
34
        $token = new AccessToken('token', $expires);
35
        static::assertEquals('token', $token->getToken());
36
        static::assertLessThanOrEqual($expires, $token->getExpires());
37
        static::assertFalse($token->isExpired());
38
    }
39
40 View Code Duplication
    public function testTokenWithExpiryAsNowIsExpired()
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...
41
    {
42
        $expires = new DateTime();
43
        $token = new AccessToken('token', $expires);
44
        static::assertEquals('token', $token->getToken());
45
        static::assertLessThanOrEqual($expires, $token->getExpires());
46
        static::assertTrue($token->isExpired());
47
    }
48
49
    public function testProperties()
50
    {
51
        $token = new AccessToken('token');
52
        static::assertEquals('token', $token->getToken());
53
        static::assertNull($token->getExpires());
54
        static::assertFalse($token->isExpired());
55
56
        $token->setToken('new token');
57
        static::assertEquals('new token', $token->getToken());
58
59
        $expires = (new DateTime())->add(new DateInterval('PT60S'));
60
61
        $token->setExpires($expires);
62
        static::assertEquals($expires, $token->getExpires());
63
        static::assertFalse($token->isExpired());
64
65
        $expires = new DateTime();
66
        $token->setExpires($expires);
67
        static::assertTrue($token->isExpired());
68
    }
69
}
70