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";
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.