UtilitiesAuthenticatorTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 74.07 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAuthentication() 10 10 1
A testFailedScopeAuthentication() 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
 * Created by PhpStorm.
4
 * User: conrad
5
 * Date: 21/05/18
6
 * Time: 3:59 PM
7
 */
8
9
namespace AdvancedLearning\Oauth2Server\Tests;
10
11
12
use AdvancedLearning\Oauth2Server\Utilities\Authenticator;
13
use SilverStripe\Control\HTTPRequest;
14
use SilverStripe\Dev\SapphireTest;
15
16
class UtilitiesAuthenticatorTest extends SapphireTest
17
{
18
    use Authenticator;
19
20 View Code Duplication
    public function testAuthentication()
0 ignored issues
show
Duplication introduced by Conrad Dobbs
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...
21
    {
22
        $request = new HTTPRequest('GET', '/test');
23
        $request->addHeader('oauth_client_id', 'someclientid');
24
        $request->addHeader('oauth_scopes', 'scope1,scope2');
25
26
        $authenticated = $this->oauthAuthenticate($request, ['scope1', 'scope2']);
27
28
        $this->assertTrue($authenticated, 'Request should have been authenticated');
29
    }
30
31 View Code Duplication
    public function testFailedScopeAuthentication()
0 ignored issues
show
Duplication introduced by Conrad Dobbs
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
        $request = new HTTPRequest('GET', '/test');
34
        $request->addHeader('oauth_client_id', 'someclientid');
35
        $request->addHeader('oauth_scopes', 'scope1');
36
37
        $authenticated = $this->oauthAuthenticate($request, ['scope1', 'scope2']);
38
39
        $this->assertFalse($authenticated, 'Request should have failed due to invalid scopes');
40
    }
41
42
}
43