value = $value; $this->target = $target; $this->roundingPrecision = 2; } /** * Indicate that the metric represents a dollar value. * * @param string $symbol * @return $this */ public function dollars($symbol = '$') { return $this->prefix($symbol); } /** * Indicate that the metric represents a euro value. * * @param string $symbol * @return $this */ public function euros($symbol = '€') { return $this->prefix($symbol); } /** * Set the metric value prefix. * * @param string $prefix * @return $this */ public function prefix($prefix) { $this->prefix = $prefix; return $this; } /** * Set the metric value suffix. * * @param string $suffix * @return $this */ public function suffix($suffix) { $this->suffix = $suffix; return $this; } /** * Don't apply suffix inflections. * * @return $this */ public function withoutSuffixInflection() { $this->suffixInflection = false; return $this; } /** * Set the metric value formatting. * * @param string $format * @return $this */ public function format($format) { $this->format = $format; return $this; } /** * Indicates that this progress metric is tracking a "goal" that should be avoided. * * @return $this */ public function avoid() { $this->avoid = true; return $this; } /** * Prepare the metric result for JSON serialization. * * @return array */ public function jsonSerialize(): array { $target = max($this->value, $this->target); return [ 'value' => $this->resolveTransformedValue($this->value), 'target' => $this->resolveTransformedValue($target), 'percentage' => $target > 0 ? round(($this->value / $target) * 100, $this->roundingPrecision, $this->roundingMode) : 0, 'prefix' => $this->prefix, 'suffix' => $this->suffix, 'suffixInflection' => $this->suffixInflection, 'format' => $this->format, 'avoid' => $this->avoid, ]; } }