Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
35 / 35 |
|
58.82% |
20 / 34 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Intensity | |
100.00% |
25 / 25 |
|
100.00% |
35 / 35 |
|
58.82% |
20 / 34 |
|
100.00% |
4 / 4 |
51.79 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| rawValue | |
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 | |||
| convertToNumeric | |
100.00% |
19 / 19 |
|
100.00% |
30 / 30 |
|
53.33% |
16 / 30 |
|
100.00% |
1 / 1 |
46.37 | |||
| 1 | <?php |
| 2 | namespace Dbmi\Webservice\Analysis; |
| 3 | |
| 4 | /** |
| 5 | * Intensity |
| 6 | * |
| 7 | * @param string $value DBMI intensity non numeric |
| 8 | */ |
| 9 | class Intensity{ |
| 10 | private const errorValue = -1; |
| 11 | private string $value; |
| 12 | private float $numericValue; |
| 13 | |
| 14 | public function __construct( string $value){ |
| 15 | $this->value = $value; |
| 16 | $this->numericValue = $this->convertToNumeric($value); |
| 17 | if ( $this->numericValue == self::errorValue ) |
| 18 | throw new \InvalidArgumentException(sprintf("[%s] value '%s' not valid", __METHOD__, $value)); |
| 19 | |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Get intensity value as added (raw) |
| 24 | * |
| 25 | * @return string Intensity value |
| 26 | */ |
| 27 | public function rawValue():string { return $this->value; } |
| 28 | |
| 29 | /** |
| 30 | * Get numeric intensity value |
| 31 | * |
| 32 | * @return float intensity value |
| 33 | */ |
| 34 | public function value():float { return $this->numericValue; } |
| 35 | |
| 36 | /** |
| 37 | * Convert intensity string to a numeric value |
| 38 | * |
| 39 | * @param string value to convert |
| 40 | * @return float intensity value converted |
| 41 | */ |
| 42 | private function convertToNumeric(string $value):float { |
| 43 | // $value is simply numeric |
| 44 | if(is_numeric($value)) |
| 45 | return intval($value); |
| 46 | |
| 47 | // $value is a middle grade like x-(x+1) |
| 48 | if(preg_match('/(\d*)-(\d*)/', $value, $matches)) |
| 49 | return ($matches[1] + $matches[2]) / 2; |
| 50 | |
| 51 | // $value is a special string |
| 52 | switch(strtoupper($value)){ |
| 53 | case 'RS': |
| 54 | case 'NR': |
| 55 | case 'W': |
| 56 | case 'E': return 0; break; |
| 57 | case 'G': return 0.2; break; |
| 58 | case 'NF': return 1; break; |
| 59 | case 'NC': return 1.8; break; |
| 60 | case 'SF': return 2.9; break; |
| 61 | case 'F': return 3.9; break; |
| 62 | case 'HF': return 5.1; break; |
| 63 | case 'SD': return 5.6; break; |
| 64 | case 'D': return 6.4; break; |
| 65 | case 'HD': return 8.6; break; |
| 66 | default: return self::errorValue; break; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | ?> |