Completed
Push — master ( 58d5b4...7e5a50 )
by Carlos
02:03
created

Client::setRequestLauncher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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