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

MysqlWaterfallRepository::getWaterfalls()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 11

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 23
loc 23
rs 9.0857
c 1
b 0
f 0
cc 2
eloc 11
nc 2
nop 2
1
<?php
2
3
namespace Jacobemerick\Web\Domain\Waterfall\Waterfall;
4
5
use Aura\Sql\ConnectionLocator;
6
7 View Code Duplication
class MysqlWaterfallRepository implements WaterfallRepositoryInterface
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...
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 getWaterfalls($limit = null, $offset = 0)
22
    {
23
        $query = "
24
            SELECT `waterfall`.`id`, `waterfall`.`name`, `waterfall`.`alias`,
25
                   `watercourse`.`name` AS `watercourse`, `watercourse`.`alias` AS `watercourse_alias`
26
            FROM `jpemeric_waterfall`.`waterfall`
27
            INNER JOIN `jpemeric_waterfall`.`watercourse` ON `waterfall`.`watercourse` = `watercourse`.`id`
28
            WHERE `is_public` = :public
29
            ORDER BY `name`, `watercourse`";
30
        if ($limit != null) {
31
            $query .= "
32
            LIMIT {$offset}, {$limit}";
33
        }
34
35
        $bindings = [
36
            'public' => 1,
37
        ];
38
39
        return $this
40
            ->connections
41
            ->getRead()
42
            ->fetchAll($query, $bindings);
43
    }
44
}
45