Completed
Push — master ( f72f24...91217a )
by Jacob
13:23
created

MysqlCommentRepository::getActiveCommentsBySite()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 38
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 38
rs 8.8571
cc 3
eloc 18
nc 3
nop 3
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Comment\Comment;
4
5
use Aura\Sql\ConnectionLocator;
6
7
class MysqlCommentRepository implements CommentRepositoryInterface
8
{
9
10
    /** @var  Aura\Sql\ConnectionLocator */
11
    protected $connections;
12
13
    /**
14
     * @param Aura\Sql\ConnectionLocator $connections
15
     */
16
    public function __construct(ConnectionLocator $connections)
17
    {
18
        $this->connections = $connections;
0 ignored issues
show
Documentation Bug introduced by
It seems like $connections of type object<Aura\Sql\ConnectionLocator> is incompatible with the declared type object<Jacobemerick\Web\...\Sql\ConnectionLocator> of property $connections.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
19
    }
20
21
    public function getActiveCommentsBySite($site, $limit = null, $offset = 0)
22
    {
23
        if ($site == 'blog') {
24
            $site_id = 2;
25
        } else {
26
            throw new Exception('Unrecognized site id in comment repository');
27
        }
28
29
        $query = "
30
            SELECT `comment_meta`.`id`, `comment_meta`.`date`, `comment`.`body`, `commenter`.`name`,
31
                   `post`.`title`, `post`.`category`, `post`.`path`
32
            FROM `jpemeric_comment`.`comment_meta`
33
            INNER JOIN `jpemeric_comment`.`comment` ON `comment`.`id` = `comment_meta`.`comment`
34
            INNER JOIN `jpemeric_comment`.`commenter` ON `commenter`.`id` = `comment_meta`.`commenter` AND
35
                                                         `commenter`.`trusted` = :trusted_commenter
36
            INNER JOIN `jpemeric_comment`.`comment_page` ON `comment_page`.`id` = `comment_meta`.`comment_page` AND
37
                                                            `comment_page`.`site` = :comment_site
38
            INNER JOIN `jpemeric_blog`.`post` ON `post`.`path` = `comment_page`.`path` AND
39
                                                 `post`.`display` = :display_post
40
            WHERE `comment_meta`.`display` = :active_comment
41
            ORDER BY `comment_meta`.`date` DESC";
42
        if ($limit != null) {
43
            $query .= "
44
            LIMIT {$offset}, {$limit}";
45
        }
46
47
        $bindings = [
48
            'trusted_commenter' => 1,
49
            'comment_site' => $site_id,
50
            'display_post' => 1,
51
            'active_comment' => 1,
52
        ];
53
54
        return $this
55
            ->connections
56
            ->getRead()
57
            ->fetchAll($query, $bindings);
58
    }
59
}
60