Completed
Pull Request — master (#1)
by Victor DA COSTA
01:47
created
src/WindguruAPI.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.