Completed
Push — master ( 7cfad9...ca95cf )
by Jacob
03:19
created

MysqlYouTubeRepository::getYouTubeById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 16
rs 9.4286
c 1
b 0
f 1
cc 1
eloc 8
nc 1
nop 1
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 integer $id
41
     *
42
     * @return array|false
43
     */
44
    public function getYouTubeById($id)
45
    {
46
        $query = "
47
            SELECT *
48
            FROM `jpemeric_stream`.`youtube`
49
            WHERE `id` = :id
50
            LIMIT 1";
51
        $bindings = [
52
            'id' => $id,
53
        ];
54
55
        return $this
56
            ->connections
57
            ->getRead()
58
            ->fetchOne($query, $bindings);
59
    }
60
61
    /**
62
     * @param string $title
0 ignored issues
show
Bug introduced by
There is no parameter named $title. Was it maybe removed?

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 method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
63
     *
64
     * @return array|false
65
     */
66
    public function getYouTubeByVideoId($videoId)
67
    {
68
        $query = "
69
            SELECT *
70
            FROM `jpemeric_stream`.`youtube`
71
            WHERE `video_id` = :video_id
72
            LIMIT 1";
73
        $bindings = [
74
            'video_id' => $videoId,
75
        ];
76
77
        return $this
78
            ->connections
79
            ->getRead()
80
            ->fetchOne($query, $bindings);
81
    }
82
83
    public function getYouTubesUpdatedSince(DateTime $datetime)
84
    {
85
        $query = "
86
            SELECT *
87
            FROM `jpemeric_stream`.`youtube`
88
            WHERE `updated_at` >= :last_update";
89
        $bindings = [
90
            'last_update' => $datetime->format('Y-m-d H:i:s'),
91
        ];
92
        return $this
93
            ->connections
94
            ->getRead()
95
            ->fetchAll($query, $bindings);
96
    }
97
98
    public function insertVideo($videoId, DateTime $datetime, array $metadata)
99
    {
100
        $query = "
101
            INSERT INTO `jpemeric_stream`.`youtube`
102
                (`video_id`, `datetime`, `metadata`)
103
            VALUES
104
                (:video_id, :datetime, :metadata)";
105
106
        $bindings = [
107
            'video_id' => $videoId,
108
            'datetime' => $datetime->format('Y-m-d H:i:s'),
109
            'metadata' => json_encode($metadata),
110
        ];
111
112
        return $this
113
            ->connections
114
            ->getWrite()
115
            ->perform($query, $bindings);
116
    }
117
}
118