22
33namespace HealthMonitor \Dto ;
44
5+ /**
6+ * Represents the result of a health check operation
7+ * Contains the health status and related information for a monitored service
8+ */
59class HealthResult
610{
11+ /**
12+ * @param string $name The name/identifier of the monitored service
13+ * @param string $category The category/type of the service being checked
14+ * @param bool $isHealthy Whether the service is healthy (true) or not (false)
15+ * @param string|null $exception The exception message if health check failed
16+ */
717 public function __construct (
818 protected string $ name ,
919 protected string $ category ,
@@ -14,31 +24,56 @@ public function __construct(
1424 //
1525 }
1626
27+ /**
28+ * Gets the name of the monitored service
29+ * @return string The service name
30+ */
1731 public function getName (): string
1832 {
1933 return $ this ->name ;
2034 }
2135
36+ /**
37+ * Gets the category of the monitored service
38+ * @return string The service category
39+ */
2240 public function getCategory (): string
2341 {
2442 return $ this ->category ;
2543 }
2644
45+ /**
46+ * Checks if the service is healthy
47+ * @return bool True if healthy, false otherwise
48+ */
2749 public function isHealthy (): bool
2850 {
2951 return $ this ->isHealthy ;
3052 }
3153
54+ /**
55+ * Gets the cleaned exception message (if any)
56+ * @return string|null The sanitized exception message or null if no exception
57+ */
3258 public function getException (): string |null
3359 {
3460 return $ this ->clean ($ this ->exception );
3561 }
3662
63+ /**
64+ * Sanitizes exception messages by:
65+ * - Removing newlines and tabs
66+ * - Collapsing multiple spaces
67+ * - Trimming quotes and whitespace
68+ * - Removing slashes
69+ * @param string|null $message The raw exception message
70+ * @return string|null The cleaned message
71+ */
3772 private function clean (string |null $ message ): string |null
3873 {
3974 $ message = str_replace (["\n" , "\r" , "\t" ], ' ' , $ message );
4075 $ message = preg_replace ('/\s+/ ' , ' ' , $ message );
4176 $ message = trim ($ message , "\"' " );
4277 return stripslashes ($ message );
4378 }
44- }
79+ }
0 commit comments