1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jacobemerick\Web\Domain\Stream\YouTube; |
4
|
|
|
|
5
|
|
|
use Aura\Sql\ConnectionLocator; |
6
|
|
|
use DateTime; |
7
|
|
|
|
8
|
|
|
class MysqlYouTubeRepository implements YouTubeRepositoryInterface |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** @var ConnectionLocator */ |
12
|
|
|
protected $connections; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param ConnectonLocator $connections |
16
|
|
|
*/ |
17
|
|
|
public function __construct(ConnectionLocator $connections) |
18
|
|
|
{ |
19
|
|
|
$this->connections = $connections; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getYouTubes($limit = null, $offset = 0) |
23
|
|
|
{ |
24
|
|
|
$query = " |
25
|
|
|
SELECT `id`, `video_id`, `datetime` |
26
|
|
|
FROM `jpemeric_stream`.`youtube` |
27
|
|
|
ORDER BY `datetime` DESC"; |
28
|
|
|
if (!is_null($limit)) { |
29
|
|
|
$query .= " |
30
|
|
|
LIMIT {$offset}, {$limit}"; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $this |
34
|
|
|
->connections |
35
|
|
|
->getRead() |
36
|
|
|
->fetchAll($query); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $title |
|
|
|
|
41
|
|
|
* |
42
|
|
|
* @return array|false |
43
|
|
|
*/ |
44
|
|
|
public function getYouTubeByVideoId($videoId) |
45
|
|
|
{ |
46
|
|
|
$query = " |
47
|
|
|
SELECT * |
48
|
|
|
FROM `jpemeric_stream`.`youtube` |
49
|
|
|
WHERE `video_id` = :video_id |
50
|
|
|
LIMIT 1"; |
51
|
|
|
$bindings = [ |
52
|
|
|
'video_id' => $videoId, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
return $this |
56
|
|
|
->connections |
57
|
|
|
->getRead() |
58
|
|
|
->fetchOne($query, $bindings); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function insertVideo($videoId, DateTime $datetime, array $metadata) |
62
|
|
|
{ |
63
|
|
|
$query = " |
64
|
|
|
INSERT INTO `jpemeric_stream`.`youtube` |
65
|
|
|
(`video_id`, `datetime`, `metadata`) |
66
|
|
|
VALUES |
67
|
|
|
(:video_id, :datetime, :metadata)"; |
68
|
|
|
|
69
|
|
|
$bindings = [ |
70
|
|
|
'video_id' => $videoId, |
71
|
|
|
'datetime' => $datetime->format('Y-m-d H:i:s'), |
72
|
|
|
'metadata' => json_encode($metadata), |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
return $this |
76
|
|
|
->connections |
77
|
|
|
->getWrite() |
78
|
|
|
->perform($query, $bindings); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.