Completed
Push — master ( 8817c3...c1b66d )
by Jacob
03:14
created

MysqlActivityRepository::insertActivity()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 28
rs 8.8571
cc 1
eloc 19
nc 1
nop 6
c 1
b 0
f 1
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Stream\Activity;
4
5
use Aura\Sql\ConnectionLocator;
6
7
class MysqlActivityRepository implements ActivityRepositoryInterface
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 View Code Duplication
    public function getActivityById($id)
0 ignored issues
show
Duplication introduced by
This method 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...
27
    {
28
        $query = "
29
            SELECT *
30
            FROM `jpemeric_stream`.`activity`
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 integer $limit
45
     * @param integer $offset
46
     *
47
     * @return array|false
48
     */
49
    public function getActivities($limit = null, $offset = 0)
50
    {
51
        $query = "
52
            SELECT *
53
            FROM `jpemeric_stream`.`activity`
54
            ORDER BY `datetime` DESC";
55
        if (!is_null($limit)) {
56
            $query .= "
57
            LIMIT {$offset}, {$limit}";
58
        }
59
60
        return $this
61
            ->connections
62
            ->getRead()
63
            ->fetchAll($query);
64
    }
65
66
    public function getActivitiesCount()
67
    {
68
        $query = "
69
            SELECT COUNT(1) AS `count`
70
            FROM `jpemeric_stream`.`activity`";
71
72
        return $this
73
            ->connections
74
            ->getRead()
75
            ->fetchValue($query);
76
    }
77
78
    public function getActivitiesByType($type, $limit = null, $offset = 0)
79
    {
80
        $query = "
81
            SELECT *
82
            FROM `jpemeric_stream`.`activity`
83
            WHERE `type` = :type
84
            ORDER BY `datetime` DESC";
85
        if (!is_null($limit)) {
86
            $query .= "
87
            LIMIT {$offset}, {$limit}";
88
        }
89
        $bindings = [
90
            'type' => $type,
91
        ];
92
93
        return $this
94
            ->connections
95
            ->getRead()
96
            ->fetchAll($query, $bindings);
97
    }
98
99
    public function getActivitiesByTypeCount($type)
100
    {
101
        $query = "
102
            SELECT COUNT(1) AS `count`
103
            FROM `jpemeric_stream`.`activity`
104
            WHERE `type` = :type";
105
        $bindings = [
106
            'type' => $type,
107
        ];
108
109
        return $this
110
            ->connections
111
            ->getRead()
112
            ->fetchValue($query, $bindings);
113
    }
114
}
115