Passed
Push — master ( c91e7e...936ada )
by Pierre
08:38
created

Metro::lines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Controllers\Api\V1;
4
5
use Nymfonya\Component\Container;
6
use Nymfonya\Component\Http\Response;
7
use App\Interfaces\Controllers\IApi;
8
use App\Reuse\Controllers\AbstractApi;
9
use App\Model\Repository\Metro\Lines;
10
use App\Model\Repository\Metro\Stations;
11
use App\Component\Db\Core;
12
use App\Component\Model\Orm\Orm;
13
14
final class Metro extends AbstractApi implements IApi
15
{
16
    /**
17
     * Lines model
18
     *
19
     * @var Lines
20
     */
21
    protected $modelLines;
22
23
24
    /**
25
     * Stations model
26
     *
27
     * @var Stations
28
     */
29
    protected $modelStations;
30
31
    /**
32
     * db core
33
     *
34
     * @var Core
35
     */
36
    protected $dbCore;
37
38
    /**
39
     * instanciate
40
     *
41
     * @param Container $container
42
     */
43 3
    public function __construct(Container $container)
44
    {
45 3
        parent::__construct($container);
46 3
        $this->modelLines = new Lines($container);
47 3
        $this->modelStations = new Stations($container);
48 3
        $this->dbCore = new Core($container);
49
    }
50
51
    /**
52
     * search lines
53
     *
54
     * @return Metro
55
     */
56 1
    final public function lines(): Metro
57
    {
58 1
        $this->response->setCode(Response::HTTP_OK)->setContent([
59 1
            Response::_ERROR => false,
60 1
            Response::_ERROR_MSG => '',
61 1
            'datas' => $this->getQueryResults(
62 1
                $this->modelLines->find(['*'], [])
63
            )
64
        ]);
65 1
        return $this;
66
    }
67
68
    /**
69
     * search stations
70
     *
71
     * @return Metro
72
     */
73 1
    final public function stations(): Metro
74
    {
75 1
        $this->response->setCode(Response::HTTP_OK)->setContent([
76 1
            Response::_ERROR => false,
77 1
            Response::_ERROR_MSG => '',
78 1
            'datas' => $this->getQueryResults(
79 1
                $this->modelStations->find(['*'], [])
80
            )
81
        ]);
82 1
        return $this;
83
    }
84
85
    /**
86
     * get query results
87
     *
88
     * @param Orm $query
89
     * @return array
90
     */
91
    protected function getQueryResults(Orm $query)
92
    {
93
        return $this->dbCore->fromOrm($query)->run(
94
            $query->getSql(),
95
            $query->getBuilderValues()
96
        )->hydrate()
97
            ->getRowset();
98
    }
99
}
100