Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
Total | |
80.95% |
17 / 21 |
|
73.33% |
11 / 15 |
|
14.29% |
2 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Json | |
80.95% |
17 / 21 |
|
73.33% |
11 / 15 |
|
14.29% |
2 / 14 |
|
0.00% |
0 / 1 |
37.86 | |
0.00% |
0 / 1 |
fetch | |
80.95% |
17 / 21 |
|
73.33% |
11 / 15 |
|
14.29% |
2 / 14 |
|
0.00% |
0 / 1 |
37.86 |
1 | <?php |
2 | namespace Hsit\Webservice\Event\Intensity; |
3 | |
4 | use Hsit\Webservice\Event\Intensity as HWE_Intensity; |
5 | use Fdsn\DataStructure\Id as DS_Id; |
6 | use 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 | */ |
16 | class 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 | ?> |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if
statement
always has an else
as part of its logical flow even if you didn't write one.
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
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; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
32 | return -2; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
35 | return -3; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
38 | return -4; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
40 | $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs']; |
41 | |
42 | foreach($mdpsArray as $mdp){ |
42 | foreach($mdpsArray as $mdp){ |
42 | foreach($mdpsArray as $mdp){ |
43 | $this->places[] = array( |
44 | 'point' => new DS_LatLon($mdp['TerritorialUnit']['Coordinates']['Latitude'], $mdp['TerritorialUnit']['Coordinates']['Longitude']), |
42 | foreach($mdpsArray as $mdp){ |
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 | } |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
40 | $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs']; |
41 | |
42 | foreach($mdpsArray as $mdp){ |
42 | foreach($mdpsArray as $mdp){ |
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 | } |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
40 | $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs']; |
41 | |
42 | foreach($mdpsArray as $mdp){ |
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 | } |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
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; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
32 | return -2; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
35 | return -3; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
38 | return -4; |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
40 | $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs']; |
41 | |
42 | foreach($mdpsArray as $mdp){ |
42 | foreach($mdpsArray as $mdp){ |
42 | foreach($mdpsArray as $mdp){ |
43 | $this->places[] = array( |
44 | 'point' => new DS_LatLon($mdp['TerritorialUnit']['Coordinates']['Latitude'], $mdp['TerritorialUnit']['Coordinates']['Longitude']), |
42 | foreach($mdpsArray as $mdp){ |
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 | } |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
40 | $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs']; |
41 | |
42 | foreach($mdpsArray as $mdp){ |
42 | foreach($mdpsArray as $mdp){ |
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 | } |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
25 | $jsonString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
26 | $data = json_decode($jsonString, true); |
27 | |
28 | if( ! array_key_exists('Quakes', $data) ) |
31 | if( ! array_key_exists($this->idQuake->value(), $data['Quakes']) ) |
34 | if( ! array_key_exists('MacroseismicData', $data['Quakes'][$this->idQuake->value()]) ) |
37 | if( ! array_key_exists('MDPs', $data['Quakes'][$this->idQuake->value()]['MacroseismicData']) ) |
40 | $mdpsArray = $data['Quakes'][$this->idQuake->value()]['MacroseismicData']['MDPs']; |
41 | |
42 | foreach($mdpsArray as $mdp){ |
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 | } |