Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
12 / 12 |
|
90.91% |
10 / 11 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| EventType | |
100.00% |
10 / 10 |
|
100.00% |
12 / 12 |
|
90.91% |
10 / 11 |
|
100.00% |
8 / 8 |
10.08 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
5 / 5 |
|
75.00% |
3 / 4 |
|
100.00% |
1 / 1 |
3.14 | |||
| __destruct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isValid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| equals | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEarthquake | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isDeleted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Fdsn\Webservices\Event\Structs; |
| 3 | |
| 4 | /** |
| 5 | * Data structure to handle Event Type |
| 6 | * @link https://quake.ethz.ch/quakeml/docs/REC?action=AttachFile&do=get&target=QuakeML-BED-20130214b.pdf QuakeML Documentation |
| 7 | * |
| 8 | * @param string $name Name of event type |
| 9 | * |
| 10 | * @return true, if every check is passed, false otherwise |
| 11 | */ |
| 12 | |
| 13 | class EventType { |
| 14 | |
| 15 | /** @var name of event type */ |
| 16 | private string $name; |
| 17 | |
| 18 | /** @var valid event type get from QuakeML documentation */ |
| 19 | private array $validTypes = array( |
| 20 | 'not existing', |
| 21 | 'not reported', |
| 22 | 'earthquake', |
| 23 | 'anthropogenic event', |
| 24 | 'collapse', |
| 25 | 'cavity collapse', |
| 26 | 'mine collapse', |
| 27 | 'building collapse', |
| 28 | 'explosion', |
| 29 | 'accidental explosion', |
| 30 | 'chemical explosion', |
| 31 | 'controlled explosion', |
| 32 | 'experimental explosion', |
| 33 | 'industrial explosion', |
| 34 | 'mining explosion', |
| 35 | 'quarry blast', |
| 36 | 'road cut', |
| 37 | 'blasting levee', |
| 38 | 'nuclear explosion', |
| 39 | 'induced or triggered event', |
| 40 | 'rock burst', |
| 41 | 'reservoir loading', |
| 42 | 'fluid injection', |
| 43 | 'fluid extraction', |
| 44 | 'crash', |
| 45 | 'plane crash', |
| 46 | 'train crash', |
| 47 | 'boat crash', |
| 48 | 'other event', |
| 49 | 'atmospheric event', |
| 50 | 'sonic boom', |
| 51 | 'sonic blast', |
| 52 | 'acoustic noise', |
| 53 | 'thunder', |
| 54 | 'avalanche', |
| 55 | 'snow avalanche', |
| 56 | 'debris avalanche', |
| 57 | 'hydroacoustic event', |
| 58 | 'ice quake', |
| 59 | 'slide', |
| 60 | 'landslide', |
| 61 | 'rockslide', |
| 62 | 'meteorite', |
| 63 | 'volcanic eruption' |
| 64 | ); |
| 65 | |
| 66 | function __construct(string $name) { |
| 67 | |
| 68 | if( '' !== $name && ! $this->isValid($name) ) |
| 69 | throw new \InvalidArgumentException("Invalid EventType"); |
| 70 | |
| 71 | $this->name = $name; |
| 72 | } |
| 73 | |
| 74 | function __destruct(){ } |
| 75 | |
| 76 | /** |
| 77 | * Returns location |
| 78 | * |
| 79 | * @return string Location name |
| 80 | */ |
| 81 | function __toString(){ return sprintf("%s", $this->name); } |
| 82 | |
| 83 | /** |
| 84 | * Fetch event type name |
| 85 | * |
| 86 | * @return string name of event type |
| 87 | */ |
| 88 | public function name():string{ return $this->name; } |
| 89 | |
| 90 | /** |
| 91 | * Check if is an entry no more exists (is deleted) |
| 92 | * @return bool true if an entry is deleted , false otherwise |
| 93 | */ |
| 94 | private function isValid(string $name):bool{ return in_array($name, $this->validTypes); } |
| 95 | |
| 96 | /** |
| 97 | * Compare two objects |
| 98 | * @return bool true are equals, false otherwise |
| 99 | */ |
| 100 | public function equals(self $other):bool{ return $this->name == $other->name; } |
| 101 | |
| 102 | /** |
| 103 | * Check if is an earthquake (or not set, because same FDSN service dont set event type) |
| 104 | * @return bool true is an earthquake, false otherwise |
| 105 | */ |
| 106 | public function isEarthquake():bool{ return preg_match('/^(earthquake|)$/', $this->name); } |
| 107 | |
| 108 | /** |
| 109 | * Check if is an entry no more exists (is deleted) |
| 110 | * @return bool true if an entry is deleted , false otherwise |
| 111 | */ |
| 112 | public function isDeleted():bool{ return preg_match('/not existing/', $this->name); } |
| 113 | } |