Completed
Push — master ( 8a9d26...40a3a6 )
by Carlos
02:18
created

BusClient::getGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Afonso\Emt;
4
5
use DateTime;
6
use RuntimeException;
7
8
/**
9
 * The SDK client for the EMT OpenData API BUS service.
10
 *
11
 * @author Carlos Afonso Pérez <[email protected]>
12
 */
13
class BusClient extends Client
14
{
15
    const ENDPOINT = 'https://openbus.emtmadrid.es:9443';
16
17
    /**
18
     * Return the itinerary of one or more lines.
19
     *
20
     * @var int[] $lines
21
     * @var \DateTime $date
22
     * @return \stdClass
23
     * @throws \RuntimeException
24
     */
25
    public function getRouteLines(array $lines, DateTime $date)
26
    {
27
        $params = [
28
            'Lines' => join('|', $lines),
29
            'SelectDate' => $date->format('d/m/Y'),
30
        ];
31
        return $this->callBusService('GetRouteLines.php', $params);
32
    }
33
34
    /**
35
     * Return calendar details for the given date interval.
36
     *
37
     * @var \DateTime $startDate
38
     * @var \DateTime $endDate
39
     * @return \stdClass
40
     * @throws \RuntimeException
41
     */
42
    public function getCalendar(DateTime $startDate, DateTime $endDate)
43
    {
44
        $params = [
45
            'SelectDateBegin' => $startDate->format('d/m/Y'),
46
            'SelectDateEnd' => $endDate->format('d/m/Y'),
47
        ];
48
        return $this->callBusService('GetCalendar.php', $params);
49
    }
50
51
    /**
52
     * Return a list with line details.
53
     *
54
     * @var int[] $lines
55
     * @var \DateTime $date
56
     * @return \stdClass
57
     * @throws \RuntimeException
58
     */
59 View Code Duplication
    public function getListLines(array $lines, DateTime $date)
0 ignored issues
show
Duplication introduced by
This method 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...
60
    {
61
        $params = [
62
            'Lines' => join('|', $lines),
63
            'SelectDate' => $date->format('d/m/Y'),
64
        ];
65
        return $this->callBusService('GetListLines.php', $params);
66
    }
67
68
    /**
69
     * Return details about all line groups.
70
     *
71
     * @return \stdClass
72
     * @throws \RuntimeException
73
     */
74
    public function getGroups()
75
    {
76
        return $this->callBusService('GetGroups.php');
77
    }
78
79
    /**
80
     * Return start and end operation times of one or more lines.
81
     *
82
     * @var int[] $lines
83
     * @var \DateTime $date
84
     * @return \stdClass
85
     * @throws \RuntimeException
86
     */
87 View Code Duplication
    public function getTimesLines(array $lines, DateTime $date)
0 ignored issues
show
Duplication introduced by
This method 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...
88
    {
89
        $params = [
90
            'Lines' => join('|', $lines),
91
            'SelectDate' => $date->format('d/m/Y'),
92
        ];
93
        return $this->callBusService('GetTimesLines.php', $params);
94
    }
95
96
    /**
97
     * Return timetable details of one or more lines.
98
     *
99
     * @var int[] $lines
100
     * @var \DateTime $date
101
     * @return \stdClass
102
     * @throws \RuntimeException
103
     */
104 View Code Duplication
    public function getTimeTableLines(array $lines, DateTime $date)
0 ignored issues
show
Duplication introduced by
This method 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...
105
    {
106
        $params = [
107
            'Lines' => join('|', $lines),
108
            'SelectDate' => $date->format('d/m/Y'),
109
        ];
110
        return $this->callBusService('GetTimeTableLines.php', $params);
111
    }
112
113
    /**
114
     * Return details of one or more bus stops including name, served lines
115
     * and geographic coordinates.
116
     *
117
     * @var int[] $stopIds
118
     * @return \stdClass
119
     * @throws \RuntimeException
120
     */
121
    public function getNodesLines(array $stopIds)
122
    {
123
        $params = [
124
            'Nodes' => join('|', $stopIds),
125
        ];
126
        return $this->callBusService('GetNodesLines.php', $params);
127
    }
128
129
    /**
130
     * Set the RequestLauncher instance to be used by this client.
131
     *
132
     * @param \Afonso\Emt\RequestLauncher $launcher
133
     */
134
    public function setRequestLauncher(RequestLauncher $launcher)
135
    {
136
        $this->launcher = $launcher;
137
    }
138
139
    /**
140
     * Make an arbitrary call to the Bus service.
141
     *
142
     * @param string $endpoint
143
     * @param array $params
144
     * @return \stdClass
145
     */
146
    protected function callBusService($endpoint, array $params = [])
147
    {
148
        $url = self::ENDPOINT . '/emt-proxy-server/last/bus/' . $endpoint;
149
        return $this->launcher->launchRequest($url, $params)->resultValues;
150
    }
151
}
152