Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
10 / 10 |
|
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Depth | |
100.00% |
8 / 8 |
|
100.00% |
10 / 10 |
|
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
__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 | |||
value | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isValid | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
equals | |
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 Depth value |
6 | * |
7 | * @param float $value depth |
8 | */ |
9 | class Depth { |
10 | private float $value; |
11 | |
12 | private $validValues = array('min' => -100, 'max' => 10000); |
13 | |
14 | function __construct( float $value) { |
15 | |
16 | if( ! $this->isValid($value) ) |
17 | throw new \InvalidArgumentException("Depth value invalid"); |
18 | |
19 | $this->value = $value; |
20 | } |
21 | |
22 | function __destruct(){ } |
23 | |
24 | /** |
25 | * Get depth value |
26 | * @return string Depth value in "%.2f km" format |
27 | */ |
28 | function __toString(){ return sprintf("%.2f km", $this->value); } |
29 | |
30 | /** |
31 | * Get depth value |
32 | * @return float Depth value |
33 | */ |
34 | public function value():float { return $this->value; } |
35 | |
36 | /** |
37 | * Check if depth value is valid |
38 | * @return bool True if is valid, false otherwise |
39 | */ |
40 | private function isValid(float $value):bool { return ($this->validValues['min'] <= $value && $value <= $this->validValues['max']); } |
41 | |
42 | /** |
43 | * Compare two objects |
44 | * @return bool true are equals, false otherwise |
45 | */ |
46 | public function equals(self $other):bool{ return $this->value == $other->value; } |
47 | } |