Completed
Push — master ( 58dd05...6b6b52 )
by Carlos
01:57
created

BusClient::callBusService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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
    /**
16
     * Return the itinerary of one or more lines.
17
     *
18
     * @var int[] $lines
19
     * @var \DateTime $date
20
     * @return \stdClass
21
     * @throws \RuntimeException
22
     */
23 3
    public function getRouteLines(array $lines, DateTime $date)
24
    {
25
        $params = [
26 3
            'Lines' => join('|', $lines),
27 3
            'SelectDate' => $date->format('d/m/Y'),
28 1
        ];
29 3
        return $this->callBusService('GetRouteLines.php', $params);
30
    }
31
32
    /**
33
     * Return calendar details for the given date interval.
34
     *
35
     * @var \DateTime $startDate
36
     * @var \DateTime $endDate
37
     * @return \stdClass
38
     * @throws \RuntimeException
39
     */
40 3
    public function getCalendar(DateTime $startDate, DateTime $endDate)
41
    {
42
        $params = [
43 3
            'SelectDateBegin' => $startDate->format('d/m/Y'),
44 3
            'SelectDateEnd' => $endDate->format('d/m/Y'),
45 1
        ];
46 3
        return $this->callBusService('GetCalendar.php', $params);
47
    }
48
49
    /**
50
     * Return a list with line details.
51
     *
52
     * @var int[] $lines
53
     * @var \DateTime $date
54
     * @return \stdClass
55
     * @throws \RuntimeException
56
     */
57 3 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...
58
    {
59
        $params = [
60 3
            'Lines' => join('|', $lines),
61 3
            'SelectDate' => $date->format('d/m/Y'),
62 1
        ];
63 3
        return $this->callBusService('GetListLines.php', $params);
64
    }
65
66
    /**
67
     * Return details about all line groups.
68
     *
69
     * @return \stdClass
70
     * @throws \RuntimeException
71
     */
72 3
    public function getGroups()
73
    {
74 3
        return $this->callBusService('GetGroups.php');
75
    }
76
77
    /**
78
     * Return start and end operation times of one or more lines.
79
     *
80
     * @var int[] $lines
81
     * @var \DateTime $date
82
     * @return \stdClass
83
     * @throws \RuntimeException
84
     */
85 3 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...
86
    {
87
        $params = [
88 3
            'Lines' => join('|', $lines),
89 3
            'SelectDate' => $date->format('d/m/Y'),
90 1
        ];
91 3
        return $this->callBusService('GetTimesLines.php', $params);
92
    }
93
94
    /**
95
     * Return timetable details of one or more lines.
96
     *
97
     * @var int[] $lines
98
     * @var \DateTime $date
99
     * @return \stdClass
100
     * @throws \RuntimeException
101
     */
102 3 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...
103
    {
104
        $params = [
105 3
            'Lines' => join('|', $lines),
106 3
            'SelectDate' => $date->format('d/m/Y'),
107 1
        ];
108 3
        return $this->callBusService('GetTimeTableLines.php', $params);
109
    }
110
111
    /**
112
     * Return details of one or more bus stops including name, served lines
113
     * and geographic coordinates.
114
     *
115
     * @var int[] $stopIds
116
     * @return \stdClass
117
     * @throws \RuntimeException
118
     */
119 3
    public function getNodesLines(array $stopIds)
120
    {
121
        $params = [
122 3
            'Nodes' => join('|', $stopIds),
123 1
        ];
124 3
        return $this->callBusService('GetNodesLines.php', $params);
125
    }
126
    /**
127
     * Make an arbitrary call to the BUS service.
128
     *
129
     * @param string $endpoint
130
     * @param array $params
131
     * @return \stdClass
132
     */
133 21
    protected function callBusService($endpoint, array $params = [])
134
    {
135 21
        $url = self::ENDPOINT . '/emt-proxy-server/last/bus/' . $endpoint;
136 21
        return $this->launcher->launchRequest($url, $params)->resultValues;
137
    }
138
}
139