Completed
Push — master ( 43937d...c78172 )
by Jacob
04:00
created

MysqlWatercourseRepository::getWatercourseList()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 38
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Waterfall\Watercourse;
4
5
use Aura\Sql\ConnectionLocator;
6
7
class MysqlWatercourseRepository implements WatercourseRepositoryInterface
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
    // todo wot are you even serious
22
    public function getWatercourseList()
23
    {
24
        $query = "
25
            SELECT `sum_table`.`name`, `sum_table`.`alias`, SUM(`count`) AS `count`
26
            FROM ((
27
                SELECT `watercourse`.`name`, `watercourse`.`alias`, `parent_count`.`count`
28
                FROM (
29
                    SELECT COUNT(1) AS `count`, `parent` AS `id`
30
                    FROM `jpemeric_waterfall`.`watercourse`
31
                    INNER JOIN `jpemeric_waterfall`.`waterfall` ON `waterfall`.`watercourse` = `watercourse`.`id` AND
32
                                                                   `waterfall`.`is_public` = :public
33
                    WHERE `watercourse`.`parent` <> :no_parent
34
                    GROUP BY `watercourse`.`id`
35
                ) AS `parent_count`
36
                INNER JOIN `jpemeric_waterfall`.`watercourse` ON `watercourse`.`id` = `parent_count`.`id` AND
37
                                                                 `watercourse`.`has_page` = :has_page
38
            ) UNION ALL (
39
                SELECT `watercourse`.`name`, `watercourse`.`alias`, COUNT(1) AS `count`
40
                FROM `jpemeric_waterfall`.`watercourse`
41
                INNER JOIN `jpemeric_waterfall`.`waterfall` ON `waterfall`.`watercourse` = `watercourse`.`id` AND
42
                                                               `waterfall`.`is_public` = :public
43
                WHERE `watercourse`.`parent` = :no_parent AND `watercourse`.`has_page` = :has_page
44
                GROUP BY `watercourse`.`id`
45
            )) AS `sum_table`
46
            GROUP BY `alias`
47
            ORDER BY `name`";
48
49
        $bindings = [
50
            'public' => 1,
51
            'no_parent' => 0,
52
            'has_page' => 1,
53
        ];
54
55
        return $this
56
            ->connections
57
            ->getRead()
58
            ->fetchAll($query, $bindings);
59
    }
60
}
61