Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
7 / 7
50.00% covered (danger)
50.00%
2 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Xml
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
7 / 7
50.00% covered (danger)
50.00%
2 / 4
100.00% covered (success)
100.00%
1 / 1
4.12
100.00% covered (success)
100.00%
1 / 1
 fetch
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
7 / 7
50.00% covered (danger)
50.00%
2 / 4
100.00% covered (success)
100.00%
1 / 1
4.12
1<?php
2namespace Hsit\Webservice\Event\Intensity;
3
4use Hsit\Webservice\Event\Intensity as HWE_Intensity;
5use Fdsn\DataStructure\Id as DS_Id;
6use Fdsn\DataStructure\LatLon as DS_LatLon;
7
8/**
9 * Fetch XML intensity data from HSIT portal
10 * 
11 * @param Fdsn\DataStructure\Id $fdsnQuakeId Id quake to scan for data
12 * @param string $macroseismicStudyName macroseismic scale study (now only mcs|ems are supported)
13 * @param bool $fetchMunicipality TRUE fetch municipality data, FALSE fetch locality data. Default is TRUE
14 * @param string $localFileFullPath base url to fetch local file (filepath will be: baseUrl/<hsit_filename>.txt) 
15 */
16class Xml extends HWE_Intensity {
17    protected const fileExtension = 'xml';
18
19    /**
20     * fetch data from url  (remote or local - if $localFileFullPath is set in __construct)
21     * 
22     * @return int number of data found
23     */
24    public function fetch():int{
25        $xmlString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath();
26        $xmlData = new \DomDocument();
27        $xmlData->loadXML($xmlString);
28
29        $mdpsNode = $xmlData->getElementsByTagName('MDPs')->item(0);
30        $numRows = count($mdpsNode->getElementsByTagName('MDP'));
31        $mdpNodes = $xmlData->getElementsByTagName('MDP');
32
33        for($i = 0; $i < $numRows; $i++){
34            $mdp = $mdpNodes->item($i);
35            $this->places[] = array(
36                'point' => new DS_LatLon($mdp->getElementsByTagName('Latitude')->item(0)->nodeValue, $mdp->getElementsByTagName('Longitude')->item(0)->nodeValue),
37                'intensity' => $mdp->getElementsByTagName('Value')->item(0)->nodeValue,
38                'reports' =>  $mdp->getElementsByTagName('Total')->item(0)->nodeValue,
39                'felt' =>  $mdp->getElementsByTagName('Felt')->item(0)->nodeValue,
40                'notFelt' => $mdp->getElementsByTagName('NotFelt')->item(0)->nodeValue,  
41                'place' => $mdp->getElementsByTagName('Name')->item(0)->nodeValue
42            );
43        }
44
45        return count($this->places);
46    }
47}
48?>