UserTest   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 139
Duplicated Lines 30.94 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 43
loc 139
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A it_accepts_an_array_of_steam_ids() 0 9 1
A it_returns_no_match_from_an_invalid_display_name() 0 6 1
A it_gets_the_steam_id_from_a_display_name() 0 6 1
A it_gets_the_base_users_player_summary() 0 8 1
A it_gets_the_supplied_users_player_summary() 0 10 1
A it_gets_the_bans_for_the_base_user() 0 9 1
A it_gets_the_bans_for_the_supplied_user() 0 11 1
A checkPlayerClasses() 0 5 1
A it_throws_an_exception_when_no_display_name_is_provided() 12 12 2
A it_gets_all_users_in_friend_list() 9 9 1
A it_gets_friend_users_in_friend_list() 9 9 1
A it_throws_exception_to_invalid_relationship_types() 13 13 2

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
use Syntax\SteamApi\Exceptions\UnrecognizedId;
4
5
require_once('BaseTester.php');
6
7
/** @group User */
8
class UserTest extends BaseTester {
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
9
10
    /** @test */
11
    public function it_accepts_an_array_of_steam_ids()
12
    {
13
        $steamIds = [$this->id32, $this->altId64];
14
15
        $userService = $this->steamClient->user($steamIds);
16
17
        $this->assertCount(2, $userService->getSteamId());
18
        $this->assertEquals($this->id64, $userService->getSteamId()[0]);
19
    }
20
21
    /**
22
     * @test
23
     * @throws UnrecognizedId
24
     */
25 View Code Duplication
    public function it_throws_an_exception_when_no_display_name_is_provided()
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...
26
    {
27
        if (method_exists($this, 'setExpectedException')) {
28
            $this->setExpectedException('Syntax\SteamApi\Exceptions\UnrecognizedId');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<UserTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        } else {
30
            $this->expectException('Syntax\SteamApi\Exceptions\UnrecognizedId');
31
        }
32
        
33
        $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL();
34
35
        $this->assertEquals('No match', $steamObject);
36
    }
37
38
    /** @test
39
     * @throws UnrecognizedId
40
     */
41
    public function it_returns_no_match_from_an_invalid_display_name()
42
    {
43
        $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL('stygiansabyssINVALID');
44
45
        $this->assertEquals('No match', $steamObject);
46
    }
47
48
    /** @test
49
     * @throws UnrecognizedId
50
     */
51
    public function it_gets_the_steam_id_from_a_display_name()
52
    {
53
        $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL('stygiansabyss');
54
55
        $this->assertEquals($this->id64, $steamObject->id64);
56
    }
57
58
    /** @test */
59
    public function it_gets_the_base_users_player_summary()
60
    {
61
        $friendsList = $this->steamClient->user($this->id64)->GetPlayerSummaries();
62
63
        $this->assertCount(1, $friendsList);
0 ignored issues
show
Documentation introduced by
$friendsList is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
64
        $this->checkPlayerProperties($friendsList);
65
        $this->checkPlayerClasses($friendsList);
66
    }
67
68
    /** @test */
69
    public function it_gets_the_supplied_users_player_summary()
70
    {
71
        $friendsList = $this->steamClient->user($this->id64)->GetPlayerSummaries($this->altId64);
72
73
        $this->assertCount(1, $friendsList);
0 ignored issues
show
Documentation introduced by
$friendsList is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
74
        $this->checkPlayerProperties($friendsList);
75
        $this->checkPlayerClasses($friendsList);
76
77
        $this->assertNotEquals($friendsList[0]->steamId, $this->id64);
78
    }
79
80
    /** @test */
81 View Code Duplication
    public function it_gets_all_users_in_friend_list()
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...
82
    {
83
        $friendsList = $this->steamClient->user($this->id64)->GetFriendList('all');
84
85
        $this->assertGreaterThan(0, $friendsList);
86
87
        $this->checkPlayerProperties($friendsList);
88
        $this->checkPlayerClasses($friendsList);
89
    }
90
91
    /** @test */
92 View Code Duplication
    public function it_gets_friend_users_in_friend_list()
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...
93
    {
94
        $friendsList = $this->steamClient->user($this->id64)->GetFriendList('friend');
95
96
        $this->assertGreaterThan(0, $friendsList);
97
98
        $this->checkPlayerProperties($friendsList);
99
        $this->checkPlayerClasses($friendsList);
100
    }
101
102
    /** @test */
103 View Code Duplication
    public function it_throws_exception_to_invalid_relationship_types()
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...
104
    {
105
        $expectedMessage = 'Provided relationship [nonFriend] is not valid.  Please select from: all, friend';
106
        
107
        if (method_exists($this, 'setExpectedException')) {
108
            $this->setExpectedException('InvalidArgumentException', $expectedMessage);
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<UserTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
        } else {
110
            $this->expectException('InvalidArgumentException');
111
            $this->expectExceptionMessage($expectedMessage);
112
        }
113
114
        $this->steamClient->user($this->id64)->GetFriendList('nonFriend');
115
    }
116
117
    /** @test */
118
    public function it_gets_the_bans_for_the_base_user()
119
    {
120
        $bans = $this->steamClient->user($this->id64)->GetPlayerBans();
121
122
        $this->assertCount(1, $bans);
123
124
        $attributes = ['SteamId', 'CommunityBanned', 'VACBanned', 'NumberOfVACBans', 'DaysSinceLastBan', 'EconomyBan'];
125
        $this->assertObjectHasAttributes($attributes, $bans[0]);
126
    }
127
128
    /** @test */
129
    public function it_gets_the_bans_for_the_supplied_user()
130
    {
131
        $bans = $this->steamClient->user($this->id64)->GetPlayerBans($this->altId64);
132
133
        $this->assertCount(1, $bans);
134
135
        $attributes = ['SteamId', 'CommunityBanned', 'VACBanned', 'NumberOfVACBans', 'DaysSinceLastBan', 'EconomyBan'];
136
        $this->assertObjectHasAttributes($attributes, $bans[0]);
137
138
        $this->assertNotEquals($bans[0]->SteamId, $this->id64);
139
    }
140
141
    private function checkPlayerClasses($friendsList)
142
    {
143
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Player', $friendsList[0]);
144
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Id', $friendsList[0]->steamIds);
145
    }
146
}