19declare(strict_types=1);
106 && !(
$stability === self::STABILITY_MIXED &&
$type === self::TYPE_COLLECTION)
108 throw new \InvalidArgumentException(
109 "Invalid stability for metric: $stability"
117 $type !== self::TYPE_BOOL
118 &&
$type !== self::TYPE_COUNTER
119 &&
$type !== self::TYPE_GAUGE
120 &&
$type !== self::TYPE_TIMESTAMP
121 &&
$type !== self::TYPE_TEXT
122 &&
$type !== self::TYPE_COLLECTION
124 throw new \InvalidArgumentException(
125 "Invalid type for metric: $type"
134 || (
$type === self::TYPE_COUNTER && !is_int(
$value))
136 || (
$type === self::TYPE_TIMESTAMP && !(
$value instanceof \DateTimeImmutable))
137 || (
$type === self::TYPE_TEXT && !is_string(
$value))
138 || (
$type === self::TYPE_COLLECTION && !is_array(
$value))
140 throw new \InvalidArgumentException(
141 "Invalid type " . gettype(
$value) .
" for metric of type $type"
145 if (
$type === self::TYPE_COLLECTION) {
147 if (!($v instanceof
Metric)) {
148 throw new \InvalidArgumentException(
149 "Every element of a collection needs to be a metric, found " . gettype($v)
179 public function toYAML(
int $indentation = 0): string
196 return sprintf(
"%.03f",
$value);
198 return $value->format(\DateTimeInterface::ISO8601);
200 if (substr_count(
$value,
"\n") > 0) {
201 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
208 function (
string $k,
Metric $v) use ($indentation):
string {
209 if ($v->
getType() === self::TYPE_COLLECTION) {
214 return $this->getIndentation($indentation) .
"$k:$split" . $v->
toYAML($indentation + 1);
221 throw new \LogicException(
"Unknown type: " . $this->
getType());
243 return sprintf(
"%.03f",
$value);
245 return $value->format(\DateTimeInterface::ISO8601);
247 if (substr_count(
$value,
"\n") > 0) {
248 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
253 foreach (
$value as $key => $val) {
254 $result[$key] = $val->toArray($indentation + 1);
258 throw new \LogicException(
"Unknown type: " . $this->
getType());
265 while ($indentation--) {
280 throw new \LogicException(
"Can not extract by mixed.");
284 return [$this,
null];
286 if ($this->
getType() !== self::TYPE_COLLECTION) {
287 return [
null, $this];
294 foreach ($values as $k => $v) {
304 if ($extracted !== []) {
307 self::TYPE_COLLECTION,
318 self::TYPE_COLLECTION,
326 return [$extracted, $rest];
332 $sub =
$f->panel()->sub(
"",
$f->legacy()->content(
"<pre>" . $yaml .
"</pre>"));
333 return $f->panel()->report($name, [$sub]);
Builds a Color from either hex- or rgb values.
A metric is something we can measure about the system.
getIndentation(int $indentation=0)
__construct(string $stability, string $type, $value, ?string $description=null)
toYAML(int $indentation=0)
checkValue($type, $value)
checkStability(string $stability, string $type)
extractByStability(string $stability)
The extracted part will be the first entry of the array, the second will be the rest of the metrics.
toArray(int $indentation=0)
const TYPE_BOOL
The type of the metric tells what to expect of the values.
toUIReport(Factory $f, string $name)
const STABILITY_CONFIG
The stability of a metric tells how often we expect changes in the metric.
This describes how a Report could be modified during construction of UI.