| Total Complexity | 11 |
| Total Lines | 104 |
| Duplicated Lines | 0 % |
| Coverage | 95.45% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | abstract class Metric |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $namespace; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $name; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $description; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string[] |
||
| 28 | */ |
||
| 29 | protected $labels = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Storage |
||
| 33 | */ |
||
| 34 | protected static $storage; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Metric constructor. |
||
| 38 | * |
||
| 39 | * @throws LabelException |
||
| 40 | */ |
||
| 41 | 56 | public function __construct() |
|
| 42 | { |
||
| 43 | 56 | foreach ($this->labels as $label) { |
|
| 44 | 56 | if (!preg_match('/^(?![_]{2})[a-zA-Z_][a-zA-Z0-9_]*$/', $label)) { |
|
| 45 | 56 | throw new LabelException("The label `{$label}` contains invalid characters."); |
|
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | 56 | if (!preg_match('/^[a-zA-Z_:][a-zA-Z0-9_:]*$/', $this->key())) { |
|
| 50 | throw new PrometheusException("The metric name `{$this->key()}` contains invalid characters."); |
||
| 51 | } |
||
| 52 | 56 | } |
|
| 53 | |||
| 54 | /** |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | 56 | final public function key(): string |
|
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | abstract public function type(): string; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | 56 | public function namespace(): string |
|
| 71 | { |
||
| 72 | 56 | return $this->namespace; |
|
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | 56 | public function name(): string |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | 25 | public function description(): string |
|
| 87 | { |
||
| 88 | 25 | return $this->description; |
|
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return Collection |
||
| 93 | */ |
||
| 94 | 51 | public function labels(): Collection |
|
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param Storage $storage |
||
| 101 | */ |
||
| 102 | 25 | public static function storeUsing(Storage $storage): void |
|
| 105 | 25 | } |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @return Storage |
||
| 109 | */ |
||
| 110 | 25 | public static function storage(): Storage |
|
| 115 |