Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit 5d1ef26

Browse files
committed
feat: add status constants
1 parent e53190b commit 5d1ef26

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Instantiate the client class and pass the configuration as parameters:
6868
```php
6969
$data = new Phash\MonitoringData(
7070
'monitoring id',
71-
'ok',
71+
Phash\MonitoringData::STATUS_OK,
7272
'this detail message will be displayed if a tile is clicked by a user',
7373
60,
7474
1,

Diff for: src/MonitoringData.php

+9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
namespace Phash;
66

77
use DateTimeInterface;
8+
use RuntimeException;
89

910
class MonitoringData
1011
{
12+
public const STATUS_OK = 'ok';
13+
public const STATUS_ERROR = 'error';
14+
15+
private const STATUSES = [self::STATUS_ERROR, self::STATUS_OK];
16+
1117
private $id;
1218
private $status;
1319
private $payload;
@@ -27,6 +33,9 @@ public function __construct(
2733
DateTimeInterface $date,
2834
?string $path
2935
) {
36+
if (!in_array($status, self::STATUSES, true)) {
37+
throw new RuntimeException(sprintf('status must be one of [%s]', implode(',', self::STATUSES)));
38+
}
3039
$this->id = $id;
3140
$this->status = $status;
3241
$this->payload = $payload;

0 commit comments

Comments
 (0)