Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Depth
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 __destruct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 value
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 isValid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 equals
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Fdsn\Webservices\Event\Structs;
3
4/**
5 * Data structure to handle Depth value
6 *
7 * @param float $value     depth
8 */
9class 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     * 
27     * @return string     Depth value in "%.2f km" format
28     */
29    function __toString(){ return sprintf("%d km", round($this->value)); }
30
31    /**
32     * Get depth value
33     * 
34     * @param int $roundTo (nullable) if set, return value rounded to `roundTo` decimals
35     * @return float    Depth value
36     */
37    public function value(?int $roundTo = null):float { return is_null($roundTo) ? $this->value : round($this->value, $roundTo) ; }
38
39    /**
40     * Check if depth value is valid
41     * 
42     * @return bool     True if is valid, false otherwise
43     */
44    private function isValid(float $value):bool { return ($this->validValues['min'] <= $value && $value <= $this->validValues['max']); }
45
46    /**
47     * Compare two objects
48     * 
49     * @return bool        true are equals, false otherwise
50     */
51    public function equals(self $other):bool{ return $this->value == $other->value; }
52} 

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

Depth->__construct
14    function __construct( float $value) {
15
16        if( ! $this->isValid($value) )
17            throw new \InvalidArgumentException("Depth value invalid");
19        $this->value = $value;
20    }
Depth->__destruct
22    function __destruct(){ }
Depth->__toString
29    function __toString(){ return sprintf("%d km", round($this->value)); }
Depth->equals
51    public function equals(self $other):bool{ return $this->value == $other->value; }
Depth->isValid
44    private function isValid(float $value):bool { return ($this->validValues['min'] <= $value && $value <= $this->validValues['max']); }
44    private function isValid(float $value):bool { return ($this->validValues['min'] <= $value && $value <= $this->validValues['max']); }
44    private function isValid(float $value):bool { return ($this->validValues['min'] <= $value && $value <= $this->validValues['max']); }
Depth->value
37    public function value(?int $roundTo = null):float { return is_null($roundTo) ? $this->value : round($this->value, $roundTo) ; }
37    public function value(?int $roundTo = null):float { return is_null($roundTo) ? $this->value : round($this->value, $roundTo) ; }
37    public function value(?int $roundTo = null):float { return is_null($roundTo) ? $this->value : round($this->value, $roundTo) ; }
37    public function value(?int $roundTo = null):float { return is_null($roundTo) ? $this->value : round($this->value, $roundTo) ; }