GroupScopesTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 54.55 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 18
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testServiceScopes() 9 9 1
A testEntityScopes() 9 9 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: 4:10 PM
7
 */
8
9
namespace AdvancedLearning\Oauth2Server\Tests;
10
11
12
use AdvancedLearning\Oauth2Server\Entities\UserEntity;
13
use AdvancedLearning\Oauth2Server\Extensions\GroupExtension;
14
use AdvancedLearning\Oauth2Server\Services\ScopeService;
15
use SilverStripe\Core\Config\Config;
16
use SilverStripe\Dev\SapphireTest;
17
use SilverStripe\Security\Group;
18
use SilverStripe\Security\Member;
19
20
class GroupScopesTest extends SapphireTest
21
{
22
    protected static $fixture_file = 'tests/OAuthFixture.yml';
23
24
    public function setUp()
25
    {
26
        // add GroupExtension for scopes
27
        Config::forClass(Group::class)->merge('extensions', [GroupExtension::class]);
28
29
        return parent::setUp(); // TODO: Change the autogenerated stub
30
    }
31
32 View Code Duplication
    public function testServiceScopes()
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...
33
    {
34
        $obj = $this->objFromFixture(Member::class, 'member1');
35
36
        $service = new ScopeService();
37
38
        $this->assertTrue($service->hasScope('scope1', $obj), 'Member should have the scope via groups');
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$obj is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        $this->assertFalse($service->hasScope('scope2', $obj), 'Member should not have scope2');
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$obj is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
    }
41
42 View Code Duplication
    public function testEntityScopes()
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...
43
    {
44
        $member = $this->objFromFixture(Member::class, 'member1');
45
46
        $entity = new UserEntity($member);
0 ignored issues
show
Documentation introduced by Conrad Dobbs
$member is of type object<SilverStripe\ORM\DataObject>|null, but the function expects a object<SilverStripe\Security\Member>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
48
        $this->assertTrue($entity->hasScope('scope1'), 'Member should have scope1');
49
        $this->assertFalse($entity->hasScope('scope2'), 'Member should not have scope2');
50
    }
51
52
}