From 535dbda6b48171f8115b455e54790de94d97d42a Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 16:41:48 -0300 Subject: Initial import --- lib/cepis/Health.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 lib/cepis/Health.php (limited to 'lib/cepis/Health.php') diff --git a/lib/cepis/Health.php b/lib/cepis/Health.php new file mode 100644 index 0000000..08f7547 --- /dev/null +++ b/lib/cepis/Health.php @@ -0,0 +1,76 @@ + $data + */ + public static function fromArray(array $data): self + { + return new self( + status: self::asString($data['status'] ?? ''), + dne: self::asString($data['dne'] ?? ''), + ceps: self::asInt($data['ceps'] ?? 0), + geo: self::asInt($data['geo'] ?? 0), + base_gerada_em: self::asString($data['base_gerada_em'] ?? ''), + ); + } + + /** + * `true` when the API reports itself healthy. + */ + public function isOk(): bool + { + return $this->status === 'ok'; + } + + /** + * @return array + */ + public function toArray(): array + { + return [ + 'status' => $this->status, + 'dne' => $this->dne, + 'ceps' => $this->ceps, + 'geo' => $this->geo, + 'base_gerada_em' => $this->base_gerada_em, + ]; + } + + private static function asString(mixed $value): string + { + return is_scalar($value) ? (string) $value : ''; + } + + private static function asInt(mixed $value): int + { + return is_numeric($value) ? (int) (float) $value : 0; + } +} -- cgit v1.3