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

MysqlBookRepository::getUnmappedBooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 13
loc 13
rs 9.4286
c 1
b 0
f 1
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Stream\Book;
4
5
use Aura\Sql\ConnectionLocator;
6
7 View Code Duplication
class MysqlBookRepository implements BookRepositoryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 getBookById($id)
27
    {
28
        $query = "
29
            SELECT `id`, `title`, `author`, `image`, `date_read` AS `date`
30
            FROM `jpemeric_stream`.`book`
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
     * @param string $author
46
     *
47
     * @return array|false
48
     */
49
    public function getBookByFields($title, $author)
50
    {
51
        $query = "
52
            SELECT *
53
            FROM `jpemeric_stream`.`book`
54
            WHERE `title` = :title AND `author` = :author
55
            LIMIT 1";
56
        $bindings = [
57
            'title' => $title,
58
            'author' => $author,
59
        ];
60
61
        return $this
62
            ->connections
63
            ->getRead()
64
            ->fetchOne($query, $bindings);
65
    }
66
67
    /**
68
     * @return array|false
69
     */
70
    public function getUnmappedBooks()
71
    {
72
        $query = "
73
            SELECT `id`, `date`
74
            FROM `jpemeric_stream`.`book`
75
            LEFT JOIN `jpemeric_stream`.`post`
76
            ON `post`.`type_id` = `book`.`id` AND `post`.`id` IS NULL";
77
78
        return $this
79
            ->connections
80
            ->getRead()
81
            ->fetchAll($query);
82
    }
83
}
84