Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
MagnitudeRange
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
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
 __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
 min
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
 max
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
 average
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 magnitude range
6 *
7 * @param Magnitude $min    Min magnitude
8 * @param Magnitude $max    Max magnitude
9 *
10 * @return true, if every check is passed, false otherwise
11 */
12
13class MagnitudeRange {
14    private Magnitude $min;
15    private Magnitude $max;
16
17    function __construct( Magnitude $min, Magnitude $max) {
18        if( $min->value() <= $max->value() ){
19            $this->min = $min;
20            $this->max = $max;
21        }
22        else{
23            $this->min = $max;
24            $this->max = $min;
25        }
26    }
27
28    function __destruct(){ }
29
30    /**
31     * Returns magnitude range
32     *
33     * @return string [%s %.1f, %s%.1f] [min type value, max type value] format
34     */
35    function __toString(){ return sprintf("[%s, %s]", $this->min, $this->max); }
36
37    /**
38     * Get min magnitude obj
39     *
40     * @return Magnitude get min Magnitude obj
41     */
42    public function min():Magnitude { return $this->min; }
43
44    /**
45     * Get max magnitude obj
46     *
47     * @return Magnitude get max Magnitude obj
48     */
49    public function max():Magnitude { return $this->max; }
50
51    /**
52     * Get magnitude average obj
53     *
54     * @return Magnitude get average Magnitude obj
55     */
56    public function average():Magnitude { return new Magnitude( $this->min->type(), round( ( $this->min->value() + $this->max->value() ) / 2, 1) ); }
57}