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 |
||
6 | class PlayerTest extends BaseTester { |
||
|
|||
7 | |||
8 | /** @test */ |
||
9 | public function it_gets_the_steam_level_by_user_id() |
||
15 | |||
16 | /** @test */ |
||
17 | public function it_gets_the_player_details_by_user_id() |
||
29 | |||
30 | /** @test */ |
||
31 | public function it_gets_the_badges_by_user_id() |
||
41 | |||
42 | /** @test */ |
||
43 | public function it_gets_the_badge_progress_by_user_id() |
||
52 | |||
53 | /** @test */ |
||
54 | View Code Duplication | public function it_gets_the_owned_games_by_user_id() |
|
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() |
||
86 | |||
87 | /** @test */ |
||
88 | public function it_filters_the_owned_games_by_user_id() |
||
102 | |||
103 | /** @test */ |
||
104 | View Code Duplication | public function it_gets_recently_played_games_by_user_id() |
|
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() |
||
133 | |||
134 | /** @test */ |
||
135 | public function it_checks_if_playing_a_shared_game_by_user_and_app_id() |
||
141 | } |
||
142 |