|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
namespace DBUnt1tled\VO\VObjects\Scalar; |
|
7
|
|
|
|
|
8
|
|
|
use DBUnt1tled\VO\Exception\InvalidVOArgumentException; |
|
9
|
|
|
use DBUnt1tled\VO\VObjects\ValueObject; |
|
10
|
|
|
|
|
11
|
|
|
class Strings extends ValueObject |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param mixed $value |
|
15
|
|
|
* @param mixed ...$other |
|
16
|
|
|
* @throws \ReflectionException |
|
17
|
|
|
*/ |
|
18
|
21 |
|
public function guard($value, ...$other): void |
|
19
|
|
|
{ |
|
20
|
21 |
|
parent::guard($value); |
|
21
|
21 |
|
if (!\is_string($value)) { |
|
22
|
1 |
|
throw new InvalidVOArgumentException('Value is invalid. Allowed type is string', $value); |
|
23
|
|
|
} |
|
24
|
20 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param int $int |
|
28
|
|
|
* @return Strings |
|
29
|
|
|
* @throws \ReflectionException |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public static function createFromInt(int $int): self |
|
32
|
|
|
{ |
|
33
|
1 |
|
return new static((string)$int); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param float $float |
|
38
|
|
|
* @return Strings |
|
39
|
|
|
* @throws \ReflectionException |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public static function createFromFloat(float $float): self |
|
42
|
|
|
{ |
|
43
|
1 |
|
return new static((string)$float); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return int |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function length(): int |
|
50
|
|
|
{ |
|
51
|
1 |
|
return mb_strlen($this->value); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return Strings |
|
56
|
|
|
* @throws \ReflectionException |
|
57
|
|
|
*/ |
|
58
|
2 |
|
public function trim(): self |
|
59
|
|
|
{ |
|
60
|
2 |
|
return new static(trim($this->value)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return Strings |
|
65
|
|
|
* @throws \ReflectionException |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function toUpperCase(): self |
|
68
|
|
|
{ |
|
69
|
1 |
|
return new static(strtoupper($this->value)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return Strings |
|
74
|
|
|
* @throws \ReflectionException |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function toLowerCase(): self |
|
77
|
|
|
{ |
|
78
|
1 |
|
return new static(strtolower($this->value)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return bool |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function isEmpty(): bool |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->value === ''; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|