@@ -106,7 +106,6 @@ discard block |
||
106 | 106 | /** |
107 | 107 | * Set the Id of the Spot. |
108 | 108 | * |
109 | - * @param string $someArgument The Argument for this call. |
|
110 | 109 | */ |
111 | 110 | public function setSpot($idSpot) |
112 | 111 | { |
@@ -212,7 +211,6 @@ discard block |
||
212 | 211 | /** |
213 | 212 | * Set the data of the Spot on cache. |
214 | 213 | * |
215 | - * @param string $data The Data. |
|
216 | 214 | */ |
217 | 215 | private function setCacheData() |
218 | 216 | { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * Example: 'https://www.windguru.cz/int/iapi.php?q=ads_spot&id_spot%5B%5D=42' |
36 | 36 | * |
37 | 37 | * @var string; |
38 | - */ |
|
38 | + */ |
|
39 | 39 | const ENDPOINT='https://www.windguru.cz'; |
40 | 40 | const LOGFOLDER='logs'; |
41 | 41 | const CACHEFOLDER='cache'; |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | $this->_messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); |
93 | 93 | |
94 | 94 | if(!file_exists(self::CACHEFOLDER)) { |
95 | - mkdir(self::CACHEFOLDER, 0777, true); |
|
95 | + mkdir(self::CACHEFOLDER, 0777, true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | if(!file_exists(self::LOGFOLDER)) { |
99 | - mkdir(self::LOGFOLDER, 0777, true); |
|
99 | + mkdir(self::LOGFOLDER, 0777, true); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | $this->_log = new Logger('WindguruAPI'); |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getData() |
132 | 132 | { |
133 | - if(file_exists(self::CACHEFOLDER.'/'.$this->_idSpot)) { |
|
133 | + if(file_exists(self::CACHEFOLDER.'/'.$this->_idSpot)) { |
|
134 | 134 | $this->getCacheData(); |
135 | - } else { |
|
135 | + } else { |
|
136 | 136 | $this->getOnlineData(); |
137 | - } |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -168,25 +168,25 @@ discard block |
||
168 | 168 | $number = 1; |
169 | 169 | |
170 | 170 | foreach ($nodes as $node) { |
171 | - if($node->nodeName == "script") { |
|
171 | + if($node->nodeName == "script") { |
|
172 | 172 | $nodeData = $xml->addChild('tab'); |
173 | 173 | $nodeData->addChild('number',$number); |
174 | 174 | $nodeData->addChild( |
175 | - 'wg_fcst_tab_data', |
|
176 | - $this->extractVariableIntoScript( |
|
175 | + 'wg_fcst_tab_data', |
|
176 | + $this->extractVariableIntoScript( |
|
177 | 177 | $node->nodeValue, |
178 | 178 | 'wg_fcst_tab_data_'.$number |
179 | - ) |
|
179 | + ) |
|
180 | 180 | ); |
181 | 181 | $nodeData->addChild( |
182 | - 'wgopts', |
|
183 | - $this->extractVariableIntoScript( |
|
182 | + 'wgopts', |
|
183 | + $this->extractVariableIntoScript( |
|
184 | 184 | $node->nodeValue, |
185 | 185 | 'wgopts_'.$number |
186 | - ) |
|
186 | + ) |
|
187 | 187 | ); |
188 | 188 | $number++; |
189 | - } |
|
189 | + } |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $this->_data = $xml; |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | */ |
206 | 206 | private function extractVariableIntoScript($script, $variable) |
207 | 207 | { |
208 | - preg_match('/var ' . $variable . ' = (.*);/', $script, $m ); |
|
209 | - return $m[1]; |
|
208 | + preg_match('/var ' . $variable . ' = (.*);/', $script, $m ); |
|
209 | + return $m[1]; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function setCacheData() |
218 | 218 | { |
219 | - // todo assert notNull $this->_data. |
|
219 | + // todo assert notNull $this->_data. |
|
220 | 220 | |
221 | - file_put_contents(self::CACHEFOLDER.'/'.$this->_idSpot, $this->_data->asXML()); |
|
221 | + file_put_contents(self::CACHEFOLDER.'/'.$this->_idSpot, $this->_data->asXML()); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | */ |
229 | 229 | private function getCacheData() |
230 | 230 | { |
231 | - $current = file_get_contents(self::CACHEFOLDER.'/'.$this->_idSpot); |
|
232 | - $xml = new \SimpleXMLElement($current); |
|
233 | - if(time() - $xml['updated'] <= self::CACHETIME) { |
|
231 | + $current = file_get_contents(self::CACHEFOLDER.'/'.$this->_idSpot); |
|
232 | + $xml = new \SimpleXMLElement($current); |
|
233 | + if(time() - $xml['updated'] <= self::CACHETIME) { |
|
234 | 234 | $this->_data = $xml; |
235 | 235 | $this->_log->warning($this->_idSpot . ": Load cache data."); |
236 | - } else { |
|
236 | + } else { |
|
237 | 237 | $this->getOnlineData(); |
238 | - } |
|
238 | + } |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @var string; |
38 | 38 | */ |
39 | - const ENDPOINT='https://www.windguru.cz'; |
|
40 | - const LOGFOLDER='logs'; |
|
41 | - const CACHEFOLDER='cache'; |
|
42 | - const CACHETIME=10*60; // secondes |
|
39 | + const ENDPOINT = 'https://www.windguru.cz'; |
|
40 | + const LOGFOLDER = 'logs'; |
|
41 | + const CACHEFOLDER = 'cache'; |
|
42 | + const CACHETIME = 10 * 60; // secondes |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Private Id of the Spot |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | $this->_httpClient = $httpClient ?: HttpClientDiscovery::find(); |
92 | 92 | $this->_messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); |
93 | 93 | |
94 | - if(!file_exists(self::CACHEFOLDER)) { |
|
94 | + if (!file_exists(self::CACHEFOLDER)) { |
|
95 | 95 | mkdir(self::CACHEFOLDER, 0777, true); |
96 | 96 | } |
97 | 97 | |
98 | - if(!file_exists(self::LOGFOLDER)) { |
|
98 | + if (!file_exists(self::LOGFOLDER)) { |
|
99 | 99 | mkdir(self::LOGFOLDER, 0777, true); |
100 | 100 | } |
101 | 101 | |
102 | 102 | $this->_log = new Logger('WindguruAPI'); |
103 | - $this->_log->pushHandler(new StreamHandler(self::LOGFOLDER . '/' . date('Ymd') . '.log', Logger::WARNING)); |
|
103 | + $this->_log->pushHandler(new StreamHandler(self::LOGFOLDER.'/'.date('Ymd').'.log', Logger::WARNING)); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getData() |
132 | 132 | { |
133 | - if(file_exists(self::CACHEFOLDER.'/'.$this->_idSpot)) { |
|
133 | + if (file_exists(self::CACHEFOLDER.'/'.$this->_idSpot)) { |
|
134 | 134 | $this->getCacheData(); |
135 | 135 | } else { |
136 | 136 | $this->getOnlineData(); |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | $number = 1; |
169 | 169 | |
170 | 170 | foreach ($nodes as $node) { |
171 | - if($node->nodeName == "script") { |
|
171 | + if ($node->nodeName == "script") { |
|
172 | 172 | $nodeData = $xml->addChild('tab'); |
173 | - $nodeData->addChild('number',$number); |
|
173 | + $nodeData->addChild('number', $number); |
|
174 | 174 | $nodeData->addChild( |
175 | 175 | 'wg_fcst_tab_data', |
176 | 176 | $this->extractVariableIntoScript( |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $this->_data = $xml; |
193 | 193 | $this->setCacheData(); |
194 | 194 | |
195 | - $this->_log->warning($this->_idSpot . ": Load online data."); |
|
195 | + $this->_log->warning($this->_idSpot.": Load online data."); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | */ |
206 | 206 | private function extractVariableIntoScript($script, $variable) |
207 | 207 | { |
208 | - preg_match('/var ' . $variable . ' = (.*);/', $script, $m ); |
|
209 | - return $m[1]; |
|
208 | + preg_match('/var '.$variable.' = (.*);/', $script, $m); |
|
209 | + return $m[ 1 ]; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | { |
231 | 231 | $current = file_get_contents(self::CACHEFOLDER.'/'.$this->_idSpot); |
232 | 232 | $xml = new \SimpleXMLElement($current); |
233 | - if(time() - $xml['updated'] <= self::CACHETIME) { |
|
233 | + if (time() - $xml[ 'updated' ] <= self::CACHETIME) { |
|
234 | 234 | $this->_data = $xml; |
235 | - $this->_log->warning($this->_idSpot . ": Load cache data."); |
|
235 | + $this->_log->warning($this->_idSpot.": Load cache data."); |
|
236 | 236 | } else { |
237 | 237 | $this->getOnlineData(); |
238 | 238 | } |
@@ -11,18 +11,18 @@ |
||
11 | 11 | * @link https://github.com/voidtek/windguru.io |
12 | 12 | */ |
13 | 13 | |
14 | -require_once __DIR__ . "/vendor/autoload.php"; |
|
14 | +require_once __DIR__."/vendor/autoload.php"; |
|
15 | 15 | |
16 | 16 | use voidtek\WindguruIO\WindguruAPI; |
17 | 17 | |
18 | 18 | if (PHP_SAPI === 'cli') { |
19 | - $idspot = $argv[1]; |
|
19 | + $idspot = $argv[ 1 ]; |
|
20 | 20 | } |
21 | 21 | else { |
22 | - $idspot = $_GET['idspot']; |
|
22 | + $idspot = $_GET[ 'idspot' ]; |
|
23 | 23 | } |
24 | 24 | |
25 | -if(empty($idspot)) return; |
|
25 | +if (empty($idspot)) return; |
|
26 | 26 | |
27 | 27 | $windguruAPI = new WindguruAPI(); |
28 | 28 | $windguruAPI->setSpot($idspot); |
@@ -17,12 +17,13 @@ |
||
17 | 17 | |
18 | 18 | if (PHP_SAPI === 'cli') { |
19 | 19 | $idspot = $argv[1]; |
20 | -} |
|
21 | -else { |
|
20 | +} else { |
|
22 | 21 | $idspot = $_GET['idspot']; |
23 | 22 | } |
24 | 23 | |
25 | -if(empty($idspot)) return; |
|
24 | +if(empty($idspot)) { |
|
25 | + return; |
|
26 | +} |
|
26 | 27 | |
27 | 28 | $windguruAPI = new WindguruAPI(); |
28 | 29 | $windguruAPI->setSpot($idspot); |