| Total Complexity | 10 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Coverage | 89.47% |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | abstract class Summary extends Metric implements Observable |
||
| 12 | { |
||
| 13 | use TracksExecutionTime; |
||
| 14 | |||
| 15 | protected array $quantiles = [ |
||
| 16 | .01, |
||
| 17 | .05, |
||
| 18 | .5, |
||
| 19 | .9, |
||
| 20 | .99, |
||
| 21 | ]; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * {@inheritdoc} |
||
| 25 | */ |
||
| 26 | 14 | public function __construct() |
|
| 27 | { |
||
| 28 | 14 | parent::__construct(); |
|
| 29 | |||
| 30 | 14 | foreach ($this->labels as $label) { |
|
| 31 | 12 | if (preg_match('/^quantile$/', $label)) { |
|
| 32 | 1 | throw new LabelException('The label `quantile` is used internally to designate summary quantiles.'); |
|
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | 13 | foreach ($this->quantiles as $quantile) { |
|
| 37 | 13 | if ($quantile < 0 || $quantile > 1) { |
|
| 38 | 1 | throw new PrometheusException('Quantiles have to be in the range between 0 and 1.'); |
|
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | 12 | sort($this->quantiles); |
|
| 43 | 12 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | 5 | public function type(): string |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | 5 | public function observe(float $value, array $labels = []): static |
|
| 57 | { |
||
| 58 | 5 | static::$storage->observe($this, $value, $labels); |
|
| 59 | |||
| 60 | 5 | return $this; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return Collection |
||
| 65 | */ |
||
| 66 | 9 | public function quantiles(): Collection |
|
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | protected function track(float $value, array $labels = []): void |
||
| 77 | } |
||
| 78 | } |
||
| 79 |