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\YoutubeApi\Api\Behavior; |
13
|
|
|
|
14
|
|
|
use Nekland\YoutubeApi\Exception\NotFoundItemException; |
15
|
|
|
|
16
|
|
|
trait ListTrait |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param string $id |
20
|
|
|
* @param array $parts |
21
|
|
|
* @param array $otherParameters |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function listById($id, array $parts = ['snippet'], array $otherParameters = []) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$parameters = array_merge( |
27
|
|
|
['part' => implode(',', $parts), 'id' => $id], |
28
|
|
|
$otherParameters |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
return $this->get(static::URL, $parameters); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get automatically only the video data array |
36
|
|
|
* |
37
|
|
|
* @param string $id |
38
|
|
|
* @param array $parts |
39
|
|
|
* @param array $otherParameters |
40
|
|
|
* @return array |
41
|
|
|
* @throws NotFoundItemException |
42
|
|
|
*/ |
43
|
|
|
public function getById($id, array $parts = ['snippet'], array $otherParameters = []) |
44
|
|
|
{ |
45
|
|
|
$data = $this->listById($id, $parts, $otherParameters); |
46
|
|
|
if (empty($data['items'])) { |
47
|
|
|
throw new NotFoundItemException(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $data['items'][0]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $filters |
55
|
|
|
* @param array $parts |
56
|
|
|
* @param array $otherParameters |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function listBy(array $filters, array $parts = ['snippet'], array $otherParameters = []) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$parameters = array_merge( |
62
|
|
|
['part' => implode(',', $parts)], |
63
|
|
|
$filters, |
64
|
|
|
$otherParameters |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
return $this->get(static::URL, $parameters); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.