| Total Complexity | 8 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | abstract class Histogram extends Metric implements Observable |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var float[] |
||
| 17 | */ |
||
| 18 | protected $buckets = [ |
||
| 19 | .005, |
||
| 20 | .01, |
||
| 21 | .025, |
||
| 22 | .05, |
||
| 23 | .1, |
||
| 24 | .25, |
||
| 25 | .5, |
||
| 26 | 1, |
||
| 27 | 2.5, |
||
| 28 | 5, |
||
| 29 | 10, |
||
| 30 | ]; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | 21 | public function __construct() |
|
| 36 | { |
||
| 37 | 21 | parent::__construct(); |
|
| 38 | |||
| 39 | 21 | foreach ($this->labels as $label) { |
|
| 40 | 19 | if (preg_match('/^le$/', $label)) { |
|
| 41 | 19 | throw new LabelException('The label `le` is used internally to designate buckets.'); |
|
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 20 | if (count($this->buckets) < 1) { |
|
| 46 | 1 | throw new PrometheusException('Histograms must contain at least one bucket.'); |
|
| 47 | } |
||
| 48 | |||
| 49 | 19 | sort($this->buckets); |
|
| 50 | 19 | } |
|
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | 6 | final public function builder(Collection $items): SamplesBuilder |
|
| 56 | { |
||
| 57 | 6 | return new HistogramSamplesBuilder($this, $items); |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | 5 | final public function type(): string |
|
| 64 | { |
||
| 65 | 5 | return 'histogram'; |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritdoc} |
||
| 70 | */ |
||
| 71 | 5 | public function observe(float $value, array $labels): self |
|
| 72 | { |
||
| 73 | 5 | static::$storage->observe($this, $value, $labels); |
|
| 74 | |||
| 75 | 5 | return $this; |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return Collection |
||
| 80 | */ |
||
| 81 | 14 | public function buckets(): Collection |
|
| 84 | } |
||
| 85 | } |
||
| 86 |