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