Completed
Push — master ( f70a65...3f527d )
by Jacob
03:18
created

MysqlBlogCommentRepository::insertBlogComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 19
rs 9.4285
cc 1
eloc 10
nc 1
nop 3
c 1
b 0
f 1
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Stream\BlogComment;
4
5
use Aura\Sql\ConnectionLocator;
6
use DateTime;
7
8
class MysqlBlogCommentRepository implements BlogCommentRepositoryInterface
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
    /**
23
     * @param integer $limit
24
     * @param integer $offset
25
     *
26
     * @return array|false
27
     */
28
    public function getBlogComments($limit = null, $offset = 0)
29
    {
30
        $query = "
31
            SELECT `id`, `permalink`, `datetime`
32
            FROM `jpemeric_stream`.`blog_comment`
33
            ORDER BY `datetime` DESC";
34
        if (!is_null($limit)) {
35
            $query .= "
36
            LIMIT {$offset}, {$limit}";
37
        }
38
39
        return $this
40
            ->connections
41
            ->getRead()
42
            ->fetchAll($query);
43
    }
44
45
    /**
46
     * @param string $permalink
47
     *
48
     * @return array|false
49
     */
50
    public function getBlogCommentByPermalink($permalink)
51
    {
52
        $query = "
53
            SELECT *
54
            FROM `jpemeric_stream`.`blog_comment`
55
            WHERE `permalink` = :permalink
56
            LIMIT 1";
57
58
        $bindings = [
59
            'permalink' => $permalink,
60
        ];
61
62
        return $this
63
            ->connections
64
            ->getRead()
65
            ->fetchOne($query, $bindings);
66
    }
67
}
68