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

MysqlTwitterRepository::getTwitterById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 16
loc 16
rs 9.4286
c 1
b 0
f 1
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Stream\Twitter;
4
5
use Aura\Sql\ConnectionLocator;
6
use DateTimeInterface;
7
8 View Code Duplication
class MysqlTwitterRepository implements TwitterRepositoryInterface
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...
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 $id
24
     *
25
     * @return array|false
26
     */
27
    public function getTwitterById($id)
28
    {
29
        $query = "
30
            SELECT *
31
            FROM `jpemeric_stream`.`twitter`
32
            WHERE `id` = :id
33
            LIMIT 1";
34
        $bindings = [
35
            'id' => $id,
36
        ];
37
38
        return $this
39
            ->connections
40
            ->getRead()
41
            ->fetchOne($query, $bindings);
42
    }
43
44
    /**
45
     * @param DateTimeInterface $date
46
     * @param string            $text
47
     *
48
     * @return array|false
49
     */
50
    public function getTwitterByFields(DateTimeInterface $date, $text)
51
    {
52
        $query = "
53
            SELECT *
54
            FROM `jpemeric_stream`.`twitter`
55
            WHERE `date` = :date AND `text` = :text
56
            LIMIT 1";
57
        $bindings = [
58
            'date' => $date->format('Y-m-d H:i:s'),
59
            'text' => $text,
60
        ];
61
62
        return $this
63
            ->connections
64
            ->getRead()
65
            ->fetchOne($query, $bindings);
66
    }
67
68
    /**
69
     * @return array|false
70
     */
71
    public function getUnmappedTwitters()
72
    {
73
        $query = "
74
            SELECT `id`, `date`
75
            FROM `jpemeric_stream`.`twitter`
76
            LEFT JOIN `jpemeric_stream`.`post`
77
            ON `post`.`type_id` = `twitter`.`id` AND `post`.`id` IS NULL";
78
79
        return $this
80
            ->connections
81
            ->getRead()
82
            ->fetchAll($query);
83
    }
84
}
85