1 | <?php |
||
15 | class HttpGetDepartures { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $schema; |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $host; |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $path; |
||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $parameter; |
||
32 | |||
33 | /** |
||
34 | * @param $schema |
||
35 | * @param $host |
||
36 | * @param $path |
||
37 | */ |
||
38 | public function __construct($schema, $host, $path) { |
||
39 | $this->setHost($host); |
||
40 | $this->setSchema($schema); |
||
41 | $this->setPath($path); |
||
42 | |||
43 | $this->setParameter( |
||
44 | [ |
||
45 | 'ubahn' => 'checked' |
||
46 | , 'bus' => 'checked' |
||
47 | , 'tram' => 'checked' |
||
48 | , 'sbahn' => 'checked' |
||
49 | ] |
||
50 | ); |
||
51 | |||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | * @throws \Exception |
||
57 | */ |
||
58 | protected function doGetRequest() { |
||
59 | |||
60 | $url = sprintf('%s://%s/%s?%s' |
||
|
|||
61 | , $this->getSchema() |
||
62 | , $this->getHost() |
||
63 | , $this->getPath() |
||
64 | , http_build_query($this->getParameter(), PHP_QUERY_RFC3986) |
||
65 | ); |
||
66 | $client = new Client(); |
||
67 | $client->setUri($url) |
||
68 | ->setMethod(\Zend\Http\Request::METHOD_GET); |
||
69 | $response = $client->send(); |
||
70 | if ($response->getStatusCode() !== 200) { |
||
71 | throw new \Exception(sprintf('Request Response: Status Code %d', $response->getStatusCode())); |
||
72 | } |
||
73 | return utf8_encode($response->getBody()); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getStations() { |
||
82 | |||
83 | /** |
||
84 | * @param $station |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getDeparturesForStation($station) { |
||
88 | $this->addParameter('haltestelle', $station); |
||
89 | $htmlResponse = $this->doGetRequest(); |
||
90 | return $htmlResponse; |
||
91 | } |
||
92 | |||
93 | public function getNewsTicker() { |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function getSchema() { |
||
103 | |||
104 | /** |
||
105 | * @param string $schema |
||
106 | */ |
||
107 | protected function setSchema($schema) { |
||
110 | |||
111 | /** |
||
112 | * @return string |
||
113 | */ |
||
114 | protected function getHost() { |
||
117 | |||
118 | /** |
||
119 | * @param string $host |
||
120 | */ |
||
121 | protected function setHost($host) { |
||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function getPath() { |
||
131 | |||
132 | /** |
||
133 | * @param string $path |
||
134 | */ |
||
135 | protected function setPath($path) { |
||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getParameter() { |
||
145 | |||
146 | /** |
||
147 | * @param string $key |
||
148 | * @param string $value |
||
149 | */ |
||
150 | protected function addParameter($key, $value) { |
||
153 | |||
154 | /** |
||
155 | * @param array $parameter |
||
156 | */ |
||
157 | protected function setParameter($parameter) { |
||
160 | |||
161 | |||
162 | } |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.