PlayerTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 136
Duplicated Lines 19.12 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 26
loc 136
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A it_gets_the_steam_level_by_user_id() 0 6 1
A it_gets_the_player_details_by_user_id() 0 12 1
A it_gets_the_badges_by_user_id() 0 10 1
A it_gets_the_badge_progress_by_user_id() 0 9 1
A it_gets_the_owned_games_by_user_id_without_app_details() 0 17 1
A it_filters_the_owned_games_by_user_id() 0 14 1
A it_gets_a_single_recently_played_game_by_user_id() 0 14 1
A it_checks_if_playing_a_shared_game_by_user_and_app_id() 0 6 1
A it_gets_the_owned_games_by_user_id() 13 13 1
A it_gets_recently_played_games_by_user_id() 13 13 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
require_once('BaseTester.php');
4
5
/** @group Player */
6
class PlayerTest 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...
7
8
    /** @test */
9
    public function it_gets_the_steam_level_by_user_id()
10
    {
11
        $steamLevel = $this->steamClient->player($this->id64)->GetSteamLevel();
12
13
        $this->assertIsInt($steamLevel);
14
    }
15
16
    /** @test */
17
    public function it_gets_the_player_details_by_user_id()
18
    {
19
        $details = $this->steamClient->player($this->id64)->GetPlayerLevelDetails();
20
21
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Player\Level', $details);
22
23
        $attributes = [
24
            'playerXp', 'playerLevel', 'xpToLevelUp', 'xpForCurrentLevel', 'currentLevelFloor',
25
            'currentLevelCeiling', 'percentThroughLevel'
26
        ];
27
        $this->assertObjectHasAttributes($attributes, $details);
28
    }
29
30
    /** @test */
31
    public function it_gets_the_badges_by_user_id()
32
    {
33
        $badges = $this->steamClient->player($this->id64)->GetBadges();
34
35
        $attributes = ['badges', 'player_xp', 'player_level', 'player_xp_needed_to_level_up', 'player_xp_needed_current_level'];
36
        $this->assertObjectHasAttributes($attributes, $badges);
37
38
        $attributes = ['badgeid', 'level', 'completion_time', 'xp', 'scarcity'];
39
        $this->assertObjectHasAttributes($attributes, $badges->badges[0]);
40
    }
41
42
    /** @test */
43
    public function it_gets_the_badge_progress_by_user_id()
44
    {
45
        $progress = $this->steamClient->player($this->id64)->GetCommunityBadgeProgress();
46
47
        $this->assertObjectHasAttribute('quests', $progress);
48
49
        $attributes = ['questid', 'completed'];
50
        $this->assertObjectHasAttributes($attributes, $progress->quests[0]);
51
    }
52
53
    /** @test */
54 View Code Duplication
    public function it_gets_the_owned_games_by_user_id()
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...
55
    {
56
        $games = $this->steamClient->player($this->id64)->GetOwnedGames();
57
58
        $this->assertInstanceOf('Illuminate\Support\Collection', $games);
59
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Game', $games->first());
60
61
        $attributes = [
62
            'appId', 'name', 'playtimeTwoWeeks', 'playtimeTwoWeeksReadable', 'playtimeForever', 'playtimeForeverReadable',
63
            'icon', 'logo', 'header', 'hasCommunityVisibleStats'
64
        ];
65
        $this->assertObjectHasAttributes($attributes, $games->first());
66
    }
67
68
    /** @test */
69
    public function it_gets_the_owned_games_by_user_id_without_app_details()
70
    {
71
        $games = $this->steamClient->player($this->id64)->GetOwnedGames(false);
72
73
        $this->assertInstanceOf('Illuminate\Support\Collection', $games);
74
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Game', $games->first());
75
76
        $attributes = [
77
            'appId', 'name', 'playtimeTwoWeeks', 'playtimeTwoWeeksReadable', 'playtimeForever', 'playtimeForeverReadable',
78
            'icon', 'logo', 'header', 'hasCommunityVisibleStats'
79
        ];
80
        $this->assertObjectHasAttributes($attributes, $games->first());
81
82
        $this->assertNull($games->first()->name);
83
        $this->assertNull($games->first()->icon);
84
        $this->assertNull($games->first()->logo);
85
    }
86
87
    /** @test */
88
    public function it_filters_the_owned_games_by_user_id()
89
    {
90
        $games = $this->steamClient->player($this->id64)->GetOwnedGames(true, false, $this->appId);
0 ignored issues
show
Documentation introduced by
$this->appId is of type integer, but the function expects a array.

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...
91
92
        $this->assertInstanceOf('Illuminate\Support\Collection', $games);
93
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Game', $games->first());
94
        $this->assertEquals(1, $games->count());
95
96
        $attributes = [
97
            'appId', 'name', 'playtimeTwoWeeks', 'playtimeTwoWeeksReadable', 'playtimeForever', 'playtimeForeverReadable',
98
            'icon', 'logo', 'header', 'hasCommunityVisibleStats'
99
        ];
100
        $this->assertObjectHasAttributes($attributes, $games->first());
101
    }
102
103
    /** @test */
104 View Code Duplication
    public function it_gets_recently_played_games_by_user_id()
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...
105
    {
106
        $games = $this->steamClient->player($this->id64)->GetRecentlyPlayedGames();
107
108
        $this->assertInstanceOf('Illuminate\Support\Collection', $games);
109
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Game', $games->first());
110
111
        $attributes = [
112
            'appId', 'name', 'playtimeTwoWeeks', 'playtimeTwoWeeksReadable', 'playtimeForever', 'playtimeForeverReadable',
113
            'icon', 'logo', 'header', 'hasCommunityVisibleStats'
114
        ];
115
        $this->assertObjectHasAttributes($attributes, $games->first());
116
    }
117
118
    /** @test */
119
    public function it_gets_a_single_recently_played_game_by_user_id()
120
    {
121
        $games = $this->steamClient->player($this->id64)->GetRecentlyPlayedGames(1);
122
123
        $this->assertInstanceOf('Illuminate\Support\Collection', $games);
124
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Game', $games->first());
125
        $this->assertEquals(1, $games->count());
126
127
        $attributes = [
128
            'appId', 'name', 'playtimeTwoWeeks', 'playtimeTwoWeeksReadable', 'playtimeForever', 'playtimeForeverReadable',
129
            'icon', 'logo', 'header', 'hasCommunityVisibleStats'
130
        ];
131
        $this->assertObjectHasAttributes($attributes, $games->first());
132
    }
133
134
    /** @test */
135
    public function it_checks_if_playing_a_shared_game_by_user_and_app_id()
136
    {
137
        $playingSharedGame = $this->steamClient->player($this->id64)->IsPlayingSharedGame($this->appId);
138
139
        $this->assertNotNull($playingSharedGame);
140
    }
141
}
142