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

MysqlBlogRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 0 Features 3
Metric Value
wmc 3
c 6
b 0
f 3
lcom 1
cbo 2
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBlogByPermalink() 0 16 1
A getBlogsUpdatedSince() 0 16 1
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Stream\Blog;
4
5
use Aura\Sql\ConnectionLocator;
6
use DateTime;
7
8
class MysqlBlogRepository implements BlogRepositoryInterface
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 getBlogByPermalink($permalink)
23
    {
24
        $query = "
25
            SELECT *
26
            FROM `jpemeric_stream`.`blog`
27
            WHERE `permalink` = :permalink
28
            LIMIT 1";
29
        $bindings = [
30
            'permalink' => $permalink,
31
        ];
32
33
        return $this
34
            ->connections
35
            ->getRead()
36
            ->fetchOne($query, $bindings);
37
    }
38
39
    public function getBlogsUpdatedSince(DateTime $datetime)
40
    {
41
        $query = "
42
            SELECT *
43
            FROM `jpemeric_stream`.`blog`
44
            WHERE `updated_at` >= :last_update";
45
46
        $bindings = [
47
            'last_update' => $datetime->format('Y-m-d H:i:s'),
48
        ];
49
50
        return $this
51
            ->connections
52
            ->getRead()
53
            ->fetchAll($query, $bindings);
54
    }
55
}
56