Completed
Push — master ( c330e2...cf0c7a )
by Jacob
03:58
created

MysqlBlogRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 75
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBlogById() 0 16 1
A getBlogByTitle() 0 16 1
A getUnmappedBlogs() 0 13 1
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Stream\Blog;
4
5
use Aura\Sql\ConnectionLocator;
6
7
class MysqlBlogRepository implements BlogRepositoryInterface
8
{
9
10
    /** @var  ConnectionLocator */
11
    protected $connections;
12
13
    /**
14
     * @param ConnectonLocator $connections
15
     */
16
    public function __construct(ConnectionLocator $connections)
17
    {
18
        $this->connections = $connections;
19
    }
20
21
    /**
22
     * @param integer $id
23
     *
24
     * @return array|false
25
     */
26
    public function getBlogById($id)
27
    {
28
        $query = "
29
            SELECT *
30
            FROM `jpemeric_stream`.`blog`
31
            WHERE `id` = :id
32
            LIMIT 1";
33
        $bindings = [
34
            'id' => $id,
35
        ];
36
37
        return $this
38
            ->connections
39
            ->getRead()
40
            ->fetchOne($query, $bindings);
41
    }
42
43
    /**
44
     * @param string $title
45
     *
46
     * @return array|false
47
     */
48
    public function getBlogByTitle($title)
49
    {
50
        $query = "
51
            SELECT *
52
            FROM `jpemeric_stream`.`blog`
53
            WHERE `title` = :title
54
            LIMIT 1";
55
        $bindings = [
56
            'title' => $title,
57
        ];
58
59
        return $this
60
            ->connections
61
            ->getRead()
62
            ->fetchOne($query, $bindings);
63
    }
64
65
    /**
66
     * @return array|false
67
     */
68
    public function getUnmappedBlogs()
69
    {
70
        $query = "
71
            SELECT `id`, `date`
72
            FROM `jpemeric_stream`.`blog`
73
            LEFT JOIN `jpemeric_stream`.`post`
74
            ON `post`.`type_id` = `blog`.`id` AND `post`.`id` IS NULL";
75
76
        return $this
77
            ->connections
78
            ->getRead()
79
            ->fetchAll($query);
80
    }
81
}
82