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

MysqlDistanceRepository::getDistanceById()   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\Distance;
4
5
use Aura\Sql\ConnectionLocator;
6
use DateTimeInterface;
7
8 View Code Duplication
class MysqlDistanceRepository implements DistanceRepositoryInterface
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 getDistanceById($id)
28
    {
29
        $query = "
30
            SELECT *
31
            FROM `jpemeric_stream`.`distance`
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            $type
47
     * @param double            $mileage
48
     *
49
     * @return array|false
50
     */
51
    public function getDistanceByFields(DateTimeInterface $date, $type, $mileage)
52
    {
53
        $query = "
54
            SELECT *
55
            FROM `jpemeric_stream`.`distance`
56
            WHERE `date` = :date AND `type` = :type AND `mileage` = :mileage
57
            LIMIT 1";
58
        $bindings = [
59
            'date' => $date->format('Y-m-d H:i:s'),
60
            'type' => $type,
61
            'mileage' => $mileage,
62
        ];
63
64
        return $this
65
            ->connections
66
            ->getRead()
67
            ->fetchOne($query, $bindings);
68
    }
69
70
    /**
71
     * @return array|false
72
     */
73
    public function getUnmappedDistances()
74
    {
75
        $query = "
76
            SELECT `id`, `date`
77
            FROM `jpemeric_stream`.`distance`
78
            LEFT JOIN `jpemeric_stream`.`post`
79
            ON `post`.`type_id` = `distance`.`id` AND `post`.`id` IS NULL";
80
81
        return $this
82
            ->connections
83
            ->getRead()
84
            ->fetchAll($query);
85
    }
86
}
87