VideosTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 79
Duplicated Lines 12.66 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldReturnYoutubeArrayAsJson() 10 10 1
A shouldThrowExceptionIfNoItemFound() 0 18 1
A getYoutubeList() 0 42 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
/**
4
 * This file is a part of nekland youtube api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\Tests\Api;
13
14
15
class VideosTest extends TestCase
16
{
17
    /**
18
     * @test
19
     */
20 View Code Duplication
    public function shouldReturnYoutubeArrayAsJson()
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...
21
    {
22
        $youtube = $this->getYoutubeMock(['get' => $this->getYoutubeList()]);
23
        /** @var \Nekland\YoutubeApi\Api\Videos $videos */
24
        $videos  = $youtube->api('videos');
25
26
        $this->assertEquals($videos->listById('PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f')['etag'], '"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY"');
27
        $this->assertEquals($videos->getById('PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f')['id'], 'DR7e0DoHZ2Y');
28
        $this->assertEquals($videos->listBy(['id' => 'PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f'])['etag'], '"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY"');
29
    }
30
31
32
    public function shouldThrowExceptionIfNoItemFound()
33
    {
34
        $youtube = $this->getYoutubeMock(['get' => '{
35
 "kind": "youtube#videoListResponse",
36
 "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/q9wh51deRpP1b7X8Nc3D-bdBxqs\"",
37
 "pageInfo": {
38
  "totalResults": 0,
39
  "resultsPerPage": 0
40
 },
41
 "items": []
42
}
43
'
44
        ]);
45
46
        $this->expectException('Nekland\YoutubeApi\Exception\NotFoundItemException');
47
48
        $youtube->api('videos')->listById('id_that_doesnt_exists');
49
    }
50
51
    private function getYoutubeList()
52
    {
53
        return '
54
{
55
 "kind": "youtube#videoListResponse",
56
 "etag": "\\"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY\\"",
57
 "pageInfo": {
58
  "totalResults": 1,
59
  "resultsPerPage": 1
60
 },
61
 "items": [
62
  {
63
   "kind": "youtube#video",
64
   "etag": "\\"X98aQHqGvPBJLZLOiSGUHCM9jnE/PYBJAtNy79ShJyHHToh-N89kDH4\\"",
65
   "id": "DR7e0DoHZ2Y",
66
   "snippet": {
67
    "publishedAt": "2014-02-19T18:00:04.000Z",
68
    "channelId": "UCvOGElQWhX8tyTxwzv1rKzg",
69
    "title": "Mystery Skulls - Ghost (Solidisco Remix)\u200f",
70
    "description": "ENM ● New Songs every Monday, Wednesday & Friday!\nDownload it from iTunes: http://bit.ly/1e5u2pM\n\nBecome a fan of Solidisco\nFB: https://facebook.com/solidisco\nSoundcloud: http://soundcloud.com/solidisco\n\nBecome a fan of Mystery Skulls\nFB: https://facebook.com/mysteryskulls\nSoundcloud: http://soundcloud.com/mysteryskulls\n\nFollow Warner bros. Records\nFB: http://facebook.com/WarnerBrosRecords\nYouTube: http://youtube.com/warnerbrosrecords\nhttp://warnerbrosrecords.com\n\nOriginal artwork: http://bit.ly/1bK1bge\n------------------------------------------------------------\nStay connected with us\nFB: http://on.fb.me/tWNN6B\n@epicnetwork\nGoogle+ http://google.com/+EpicNetworkMusic\nSoundcloud: http://snd.sc/1hQlDce\n------------------------------------------------------------\nTrack\'s title: Mystery Skulls - Ghost (Solidisco Remix)\u200f",
71
    "thumbnails": {
72
     "default": {
73
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/default.jpg"
74
     },
75
     "medium": {
76
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/mqdefault.jpg"
77
     },
78
     "high": {
79
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/hqdefault.jpg"
80
     },
81
     "standard": {
82
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/sddefault.jpg"
83
     }
84
    },
85
    "channelTitle": "ENM",
86
    "categoryId": "10",
87
    "liveBroadcastContent": "none"
88
   }
89
  }
90
 ]
91
}';
92
    }
93
}
94