Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
66.67% covered (warning)
66.67%
10 / 15
50.00% covered (danger)
50.00%
5 / 10
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
EventCollection
100.00% covered (success)
100.00%
28 / 28
66.67% covered (warning)
66.67%
10 / 15
50.00% covered (danger)
50.00%
5 / 10
100.00% covered (success)
100.00%
5 / 5
22.50
100.00% covered (success)
100.00%
1 / 1
 addFilterByDateTimeRange
100.00% covered (success)
100.00%
5 / 5
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
 addFilterByBoundingBox
100.00% covered (success)
100.00%
7 / 7
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
 addFilterByMagnitudeRange
100.00% covered (success)
100.00%
5 / 5
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
 addFilterByDepthRange
100.00% covered (success)
100.00%
5 / 5
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
 addFilterByRadiusRange
100.00% covered (success)
100.00%
6 / 6
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
1<?php
2namespace Fdsn\Webservices\Event;
3
4use ArrayIterator;
5use IteratorAggregate;
6use Traversable;
7
8use Fdsn\Webservices\Event\EventService;
9
10use Fdsn\Webservices\Event\Data\Author;
11use Fdsn\Webservices\Event\Data\Depth;
12use Fdsn\Webservices\Event\Data\Epicenter;
13use Fdsn\Webservices\Event\Data\Id;
14use Fdsn\Webservices\Event\Data\LatLon;
15use Fdsn\Webservices\Event\Data\Location;
16use Fdsn\Webservices\Event\Data\Magnitude;
17use Fdsn\Webservices\Event\Data\Radius;
18
19use Fdsn\Webservices\Event\Range\DateTimeRange;
20use Fdsn\Webservices\Event\Range\DepthRange;
21use Fdsn\Webservices\Event\Range\LatLonRange;
22use Fdsn\Webservices\Event\Range\MagnitudeRange;
23use Fdsn\Webservices\Event\Range\RadiusRange;
24
25/**
26 * PHP library to access FDSN Webservices and request Event (earthquake) information in text format
27 * @see    https://www.fdsn.org/webservices/fdsnws-event-1.2.pdf FDSN official documentation
28 *
29 * @param string     $format     Accepted output kind format
30 * @param string     $user        Set your app name
31 * @param string     $fdns_server    Fdns webservice domain name (default: webservices.ms.ingv.it)
32 */
33class EventCollection extends EventService implements IteratorAggregate {
34
35    /* Search by bounding box */    
36    private LatLonRange     $square;
37
38    /* Search by magnitude */    
39    private MagnitudeRange     $magnitudeRange;
40
41    /* Search by datetime */    
42    private DateTimeRange    $dateTimeRange;
43
44    /* Search by depth */    
45    private DepthRange     $depthRange;
46
47    /* Search by radius */    
48    private LatLon    $latlon;
49    private RadiusRange $radiusRange;
50    
51    protected string $eventList;
52
53    protected EventData $event;
54    
55    /**
56     * Add filter based on datetime range
57     * @param \Fdsn\DataStructure\DateTimeRange $dateTimeRange     Datetime min -> Datetime max (default value is TODAY)
58     */
59    public function addFilterByDateTimeRange(DateTimeRange  $dateTimeRange):void { 
60        if( self::debug ) printf("[%s] %d \n", __METHOD__, time());
61        $this->dateTimeRange = $dateTimeRange; 
62        $this->parameters['datatimerange'] = sprintf("starttime=%s&endtime=%s", 
63                    $this->dateTimeRange->startDateTime(),
64                    $this->dateTimeRange->endDateTime());
65    }
66
67    /**
68     * Add filter based on geographical selection
69     * @param \Fdsn\DataStructure\LatLonRange $square     Lat/Lon min -> Lat/Lon max
70     */
71    public function addFilterByBoundingBox(LatLonRange $square):void { 
72        if( self::debug ) printf("[%s] %d \n", __METHOD__, time()); 
73
74        $this->square = $square; 
75
76        $this->parameters['boundingbox'] = sprintf("minlat=%.2f&maxlat=%.2f&minlon=%.2f&maxlon=%.2f",
77            $this->square->min()->lat(),
78            $this->square->max()->lat(),
79            $this->square->min()->lon(),
80            $this->square->max()->lon());
81    }
82
83    /**
84     * Add filter based on magnitude range
85     * @param \Fdsn\DataStructure\MagnitudeRange     $magnitudeRange     Magnitude min -> Magnitude max
86     */
87    public function addFilterByMagnitudeRange(MagnitudeRange $magnitudeRange):void { 
88        if( self::debug ) printf("[%s] %d \n", __METHOD__, time()); 
89
90        $this->magnitudeRange = $magnitudeRange; 
91        $this->parameters['magnituderange'] = sprintf("minmag=%.2f&maxmag=%.2f",
92            $this->magnitudeRange->min()->value(),
93            $this->magnitudeRange->max()->value());
94    }
95
96    /**
97     * Add filter based on depth range
98     * @param \Fdsn\DataStructure\DepthRange $depthRange     Depth min -> Depth max
99     */
100    public function addFilterByDepthRange(DepthRange  $depthRange):void { 
101        if( self::debug ) printf("[%s] %d \n", __METHOD__, time()); 
102
103        $this->depthRange  = $depthRange; 
104        $this->parameters['depthrange'] = sprintf("mindepth=%.2f&maxdepth=%.2f",
105            $this->depthRange->min()->value(),
106            $this->depthRange->max()->value());
107    }
108
109    /**
110     * Add filter based on latlon->radius
111     * @param \Fdsn\DataStructure\LatLon        $latlon        lat/lon as coordinate to start search
112     * @param \Fdsn\DataStructure\RadiusRange     $radiusRange    radius min->max to search ( valid range [0:180] for both radius )
113     */
114    public function addFilterByRadiusRange(LatLon $latlon, RadiusRange $radiusRange ):void { 
115        if( self::debug ) printf("[%s] %d \n", __METHOD__, time()); 
116
117        $this->latlon = $latlon;  
118        $this->radiusRange = $radiusRange; 
119
120        $this->parameters['radiusrange'] = sprintf("latitude=%.3f&longitude=%.3f&minradius=%.2f&maxradius=%.2f",
121            $this->latlon->lat(), $this->latlon->lon(),
122            $this->radiusRange->min()->value(), $this->radiusRange->max()->value());
123    }
124
125}