Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
93.33% covered (success)
93.33%
14 / 15
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Ascii
93.33% covered (success)
93.33%
14 / 15
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
5.01
0.00% covered (danger)
0.00%
0 / 1
 fetch
93.33% covered (success)
93.33%
14 / 15
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
5.01
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 ASCII 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 Ascii extends HWE_Intensity {
17    protected const fileExtension = 'txt';
18    private const dataStartsAtLine = 4;
19    
20    /**
21     * fetch data from url  (remote or local - if $localFileFullPath is set in __construct)
22     * 
23     * @return int number of data found
24     */
25    public function fetch():int{
26        $asciiString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath();
27        $data = preg_split("/\n/", $asciiString);
28
29        if( count($data) <= self::dataStartsAtLine )
30            return 0;
31
32        for($i = self::dataStartsAtLine; $i < count($data); $i++ ){
33            //skip empty lines
34            if( preg_match('/^$/', $data[$i] ) )
35                continue;
36
37            list($lon, $lat, $intensity, $reports, $place) = preg_split('/,/', trim($data[$i]) );
38            $this->places[] = array(
39                'point' => new DS_LatLon($lat, $lon),
40                'intensity' => $intensity,
41                'reports' => $reports,
42                'place' => $place
43
44            );
45        }
46
47        return count($this->places);
48    }
49}
50?>