Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
Total | |
100.00% |
22 / 22 |
|
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Webservice | |
100.00% |
22 / 22 |
|
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
fetch | n/a |
0 / 0 |
n/a |
0 / 0 |
n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||||
numRows | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
version | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIterator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFetch | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
fdsnSupportedVersion | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Fdsn\Webservices; |
3 | |
4 | use ArrayIterator; |
5 | use IteratorAggregate; |
6 | use Traversable; |
7 | |
8 | /** |
9 | * PHP library to access FDSN Webservices and request Catalogs |
10 | * |
11 | * @param string $fdsn_server Fdns webservice domain name (default: webservices.ms.ingv.it) |
12 | */ |
13 | abstract class Webservice implements IteratorAggregate { |
14 | /** |
15 | * @var Base URL to compile with FDSN server url |
16 | */ |
17 | public const basePath = 'https://%s/fdsnws/event/1'; |
18 | |
19 | /** |
20 | * @var Default server url |
21 | */ |
22 | public const defaultFdsnServer = 'webservices.ms.ingv.it'; |
23 | |
24 | /** |
25 | * @var Max supported version |
26 | */ |
27 | public const fdsnSupportedVersion = '^1.'; |
28 | |
29 | protected string $fdsnServer; |
30 | protected string $webserviceFullPath; |
31 | |
32 | protected array $arrayOfResults = array(); |
33 | protected string $version = ''; |
34 | |
35 | function __construct( string $fdsn_server = self::defaultFdsnServer ){ |
36 | |
37 | $this->fdsnServer = $fdsn_server; |
38 | |
39 | $this->webserviceFullPath = sprintf(self::basePath, |
40 | $this->fdsnServer |
41 | ); |
42 | |
43 | if( ! $this->fdsnSupportedVersion() ){ |
44 | // @codeCoverageIgnoreStart |
45 | throw new \ValueError(sprintf("[%s] Error fetching FDSN version from server %s", __METHOD__, $this->fdsnServer)); |
46 | // @codeCoverageIgnoreEnd |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * Fetch data from selected FDSN server |
52 | * |
53 | * @return int number of data found |
54 | */ |
55 | abstract public function fetch():int; |
56 | |
57 | |
58 | /** |
59 | * Return the number of elems found |
60 | * @return int The number of elems found |
61 | */ |
62 | public function numRows():int { return count($this->arrayOfResults); } |
63 | |
64 | /** |
65 | * Get FDSN running version |
66 | * @return string FDSN running version (trimmed by newline) |
67 | */ |
68 | public function version():string{ return $this->version; } |
69 | |
70 | /** |
71 | * Iterate over catalogis found |
72 | * @return array array of \Fdsn\DataStructure\Catalog obj |
73 | */ |
74 | public function getIterator():Traversable { return new ArrayIterator($this->arrayOfResults); } |
75 | |
76 | /** |
77 | * Fetch data from selected FDSN server |
78 | * |
79 | * @return string downloaded string |
80 | */ |
81 | protected function getFetch(string $url):string{ |
82 | $curlSession = curl_init(); |
83 | curl_setopt_array($curlSession, array( |
84 | CURLOPT_URL => $url, |
85 | CURLOPT_HEADER => false, |
86 | CURLOPT_CUSTOMREQUEST => 'GET', |
87 | CURLOPT_RETURNTRANSFER => 1, |
88 | CURLOPT_TIMEOUT => 60 |
89 | ) |
90 | ); |
91 | $response = trim(curl_exec($curlSession)); |
92 | curl_close($curlSession); |
93 | |
94 | return $response; |
95 | } |
96 | |
97 | /** |
98 | * Check if FDSN server version is supported |
99 | */ |
100 | private function fdsnSupportedVersion():bool{ |
101 | $this->version = trim( $this->getFetch($this->webserviceFullPath . '/version') ); |
102 | |
103 | return preg_match('/' . self::fdsnSupportedVersion . '/', $this->version); |
104 | |
105 | } |
106 | |
107 | } |
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.
35 | function __construct( string $fdsn_server = self::defaultFdsnServer ){ |
36 | |
37 | $this->fdsnServer = $fdsn_server; |
38 | |
39 | $this->webserviceFullPath = sprintf(self::basePath, |
40 | $this->fdsnServer |
41 | ); |
42 | |
43 | if( ! $this->fdsnSupportedVersion() ){ |
48 | } |
101 | $this->version = trim( $this->getFetch($this->webserviceFullPath . '/version') ); |
102 | |
103 | return preg_match('/' . self::fdsnSupportedVersion . '/', $this->version); |
104 | |
105 | } |
81 | protected function getFetch(string $url):string{ |
82 | $curlSession = curl_init(); |
83 | curl_setopt_array($curlSession, array( |
84 | CURLOPT_URL => $url, |
85 | CURLOPT_HEADER => false, |
86 | CURLOPT_CUSTOMREQUEST => 'GET', |
87 | CURLOPT_RETURNTRANSFER => 1, |
88 | CURLOPT_TIMEOUT => 60 |
89 | ) |
90 | ); |
91 | $response = trim(curl_exec($curlSession)); |
92 | curl_close($curlSession); |
93 | |
94 | return $response; |
95 | } |
74 | public function getIterator():Traversable { return new ArrayIterator($this->arrayOfResults); } |
62 | public function numRows():int { return count($this->arrayOfResults); } |
68 | public function version():string{ return $this->version; } |