Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
80.95% covered (warning)
80.95%
17 / 21
73.33% covered (warning)
73.33%
11 / 15
14.29% covered (danger)
14.29%
2 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Json
80.95% covered (warning)
80.95%
17 / 21
73.33% covered (warning)
73.33%
11 / 15
14.29% covered (danger)
14.29%
2 / 14
0.00% covered (danger)
0.00%
0 / 1
37.86
0.00% covered (danger)
0.00%
0 / 1
 fetch
80.95% covered (warning)
80.95%
17 / 21
73.33% covered (warning)
73.33%
11 / 15
14.29% covered (danger)
14.29%
2 / 14
0.00% covered (danger)
0.00%
0 / 1
37.86
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 Json 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 Json extends HWE_Intensity {
17    protected const fileExtension = 'json';
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        $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath();
26        $data = json_decode($jsonString, true);
27
28        if( ! array_key_exists('Quakes', $data) )
29            return -1;
30
31        if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) )
32            return -2;
33
34        if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) )
35            return -3;
36
37        if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) )
38            return -4;
39
40        $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs'];
41
42        foreach($mdpsArray as $mdp){
43            $this->places[] = array(
44                'point' => new DS_LatLon($mdp['TerritorialUnit']['Coordinates']['Latitude'], $mdp['TerritorialUnit']['Coordinates']['Longitude']),
45                'intensity' => $mdp['Value'],
46                'reports' =>  $mdp['QuestNumber']['Total'],
47                'felt' =>  $mdp['QuestNumber']['Felt'],
48                'notFelt' =>  $mdp['QuestNumber']['NotFelt'],
49                'place' => $mdp['TerritorialUnit']['Name']
50
51            );
52        }
53
54        return count($this->places);
55    }
56}
57?>