-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttribute.php
More file actions
57 lines (48 loc) · 1.23 KB
/
Attribute.php
File metadata and controls
57 lines (48 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace TinyBlocks\Http\Internal\Request;
final readonly class Attribute
{
private function __construct(private mixed $value)
{
}
public static function from(mixed $value): Attribute
{
return new Attribute(value: $value);
}
public function toArray(): array
{
return match (true) {
is_array($this->value) => $this->value,
default => []
};
}
public function toFloat(): float
{
return match (true) {
is_scalar($this->value) => (float)$this->value,
default => 0.00
};
}
public function toString(): string
{
return match (true) {
is_scalar($this->value) => (string)$this->value,
default => ''
};
}
public function toInteger(): int
{
return match (true) {
is_scalar($this->value) => (int)$this->value,
default => 0
};
}
public function toBoolean(): bool
{
return match (true) {
is_scalar($this->value) => (bool)$this->value,
default => false
};
}
}