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