Lines
100.00%
9 / 9
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ThresholdDirection | 100.00% | 9 / 9 | 100.00% | 3 / 3 | 9 | 100.00% | 1 / 1 | |||
| isBeyond | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | |||||
| hasReturned | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | |||||
| describeUsage | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Support\Stream; | |
| 6 | ||
| 7 | /** @internal */ | |
| 8 | enum ThresholdDirection | |
| 9 | { | |
| 10 | case Above; | |
| 11 | case Below; | |
| 12 | ||
| 13 | public function isBeyond(float $value, float $threshold): bool | |
| 14 | { | |
| 15 | return match ($this) { | |
| 16 | self::Above => $value > $threshold, | |
| 17 | self::Below => $value < $threshold, | |
| 18 | }; | |
| 19 | } | |
| 20 | ||
| 21 | public function hasReturned(float $value, float $threshold, float $hysteresis): bool | |
| 22 | { | |
| 23 | return match ($this) { | |
| 24 | self::Above => $value <= $threshold - $hysteresis, | |
| 25 | self::Below => $value >= $threshold + $hysteresis, | |
| 26 | }; | |
| 27 | } | |
| 28 | ||
| 29 | public function describeUsage(): string | |
| 30 | { | |
| 31 | return match ($this) { | |
| 32 | self::Above => 'whenAbove', | |
| 33 | self::Below => 'whenBelow', | |
| 34 | }; | |
| 35 | } | |
| 36 | } |