Skip to content

Commit abb3718

Browse files
committed
Add isEmpty method to string and integer types with tests for consistent behavior
1 parent 15451fa commit abb3718

21 files changed

+112
-2
lines changed

src/Abstract/Primitive/PrimitiveTypeInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpTypedValues\Abstract\Primitive;
66

77
use JsonSerializable;
8+
use PhpTypedValues\Abstract\Shared\IsEmptyInterface;
89
use PhpTypedValues\Abstract\TypeInterface;
910
use PhpTypedValues\Exception\TypeException;
1011
use PhpTypedValues\Undefined\Alias\Undefined;
@@ -23,7 +24,7 @@
2324
*
2425
* @psalm-immutable
2526
*/
26-
interface PrimitiveTypeInterface extends TypeInterface, JsonSerializable
27+
interface PrimitiveTypeInterface extends TypeInterface, JsonSerializable, IsEmptyInterface
2728
{
2829
/**
2930
* Create an instance from a validated string representation.

src/Abstract/Shared/IsEmptyInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
interface IsEmptyInterface
1313
{
1414
/**
15-
* Returns if the Object value is empty.
15+
* Returns true if the Object value is empty.
1616
*/
1717
public function isEmpty(): bool;
1818
}

src/Integer/IntegerStandard.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,9 @@ public function jsonSerialize(): int
9292
{
9393
return $this->value();
9494
}
95+
96+
public function isEmpty(): bool
97+
{
98+
return false;
99+
}
95100
}

src/Integer/IntegerWeekDay.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,9 @@ public function __toString(): string
116116
{
117117
return $this->toString();
118118
}
119+
120+
public function isEmpty(): bool
121+
{
122+
return false;
123+
}
119124
}

src/Integer/MariaDb/IntegerTiny.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,9 @@ public function __toString(): string
112112
{
113113
return $this->toString();
114114
}
115+
116+
public function isEmpty(): bool
117+
{
118+
return false;
119+
}
115120
}

src/String/MariaDb/StringDecimal.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,10 @@ public function __toString(): string
119119
{
120120
return $this->toString();
121121
}
122+
123+
public function isEmpty(): bool
124+
{
125+
// Decimal values are never empty by construction; constructor rejects empty strings
126+
return false;
127+
}
122128
}

src/String/StringCountryCode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public function __toString(): string
9797
return $this->toString();
9898
}
9999

100+
public function isEmpty(): bool
101+
{
102+
return false;
103+
}
104+
100105
/**
101106
* ISO 3166-1 alpha-2 codes used for validation.
102107
*

src/String/StringEmail.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ public function __toString(): string
9393
{
9494
return $this->toString();
9595
}
96+
97+
public function isEmpty(): bool
98+
{
99+
return false;
100+
}
96101
}

src/String/StringJson.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@ public function __toString(): string
123123
{
124124
return $this->toString();
125125
}
126+
127+
public function isEmpty(): bool
128+
{
129+
// JSON values are never empty by construction; constructor rejects empty strings
130+
return false;
131+
}
126132
}

src/String/StringNonBlank.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,9 @@ public function __toString(): string
9191
{
9292
return $this->toString();
9393
}
94+
95+
public function isEmpty(): bool
96+
{
97+
return false;
98+
}
9499
}

0 commit comments

Comments
 (0)