Completed
Push — master ( 8817c3...c1b66d )
by Jacob
03:14
created

MysqlYouTubeRepository::getYouTubes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
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
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...
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