Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
e536adf
Refactor Undefined types: add null handling and clean up API
GeorgII-web Apr 9, 2026
ba82f3a
Reorder PHP version badges and tidy README sections
GeorgII-web Apr 9, 2026
c914a86
Change Undefined toDecimal return type to never
GeorgII-web Apr 9, 2026
b9d3eb2
Refactor BoolStandard: add null handling and exception
GeorgII-web Apr 10, 2026
f726c51
Add null handling to BoolSwitch: fromNull and toNull throw SwitchBool…
GeorgII-web Apr 10, 2026
90cf2e2
Add @throws UndefinedTypeException annotations and generic templates …
GeorgII-web Apr 10, 2026
0c1b091
Add null handling to TrueStandard: fromNull and toNull throw TrueBool…
GeorgII-web Apr 10, 2026
cd9f020
Add null handling to FalseStandard: fromNull and toNull throw FalseBo…
GeorgII-web Apr 10, 2026
cad236f
Add null handling to BoolTypeAbstract and BoolTypeInterface
GeorgII-web Apr 10, 2026
7fd01dd
Add null handling to BoolToggle: fromNull and toNull throw ToggleBool…
GeorgII-web Apr 10, 2026
143d6c4
Add null handling to DecimalMoney: fromNull and toNull throw MoneyDec…
GeorgII-web Apr 10, 2026
f7e0205
Add null handling to DecimalNegative: fromNull and toNull throw Negat…
GeorgII-web Apr 10, 2026
a8a6b05
Add null handling to DecimalNonNegative: fromNull and toNull throw No…
GeorgII-web Apr 10, 2026
ecfaab2
Add null handling to DecimalNonPositive: fromNull and toNull throw No…
GeorgII-web Apr 10, 2026
fd824ab
Add null handling to DecimalNonZero: fromNull and toNull throw NonZer…
GeorgII-web Apr 10, 2026
64bf753
Add null handling to DecimalPercent: fromNull and toNull throw Percen…
GeorgII-web Apr 10, 2026
fb1fd68
Add null handling to DecimalPositive: fromNull and toNull throw Posit…
GeorgII-web Apr 10, 2026
834167e
Add null handling to DecimalProbability: fromNull and toNull throw Pr…
GeorgII-web Apr 10, 2026
ec583ae
Add null handling to DecimalStandard: fromNull and toNull throw Decim…
GeorgII-web Apr 10, 2026
1f21a3f
Add abstract null handling to DecimalTypeAbstract
GeorgII-web Apr 10, 2026
a9c2020
Add null handling to FloatNegative: fromNull and toNull throw Negativ…
GeorgII-web Apr 10, 2026
cdd1599
Add null handling to FloatNonNegative: fromNull and toNull throw NonN…
GeorgII-web Apr 10, 2026
4636249
Add null handling to FloatNonPositive: fromNull and toNull throw NonP…
GeorgII-web Apr 10, 2026
4b581e6
Add null handling to FloatNonZero: fromNull and toNull throw NonZeroF…
GeorgII-web Apr 10, 2026
b427efc
Add null handling to FloatPercent: fromNull and toNull throw PercentF…
GeorgII-web Apr 10, 2026
d95d444
Add null handling to FloatPositive: fromNull and toNull throw Positiv…
GeorgII-web Apr 10, 2026
7ccae3a
Add null handling to FloatProbability: fromNull and toNull throw Prob…
GeorgII-web Apr 10, 2026
413c903
Add null handling to FloatStandard: fromNull and toNull throw FloatTy…
GeorgII-web Apr 10, 2026
d7445a8
Add abstract null handling to FloatTypeAbstract
GeorgII-web Apr 10, 2026
27fa1e9
Add @throws FloatTypeException to Float type methods
GeorgII-web Apr 10, 2026
a3a10be
Add null handling to IntegerAge: fromNull and toNull throw AgeInteger…
GeorgII-web Apr 10, 2026
959f09b
Add null handling to IntegerBig: fromNull and toNull throw BigInteger…
GeorgII-web Apr 10, 2026
c4ecfac
Add null handling to IntegerBigUnsigned: fromNull and toNull throw Un…
GeorgII-web Apr 10, 2026
0f234ba
Add null handling to IntegerDayOfMonth: fromNull and toNull throw Day…
GeorgII-web Apr 10, 2026
ad15b64
Add null handling to IntegerHour: fromNull and toNull throw HourInteg…
GeorgII-web Apr 10, 2026
e99d84f
Add null handling to IntegerHttpStatusCode: fromNull and toNull throw…
GeorgII-web Apr 10, 2026
54d24c0
Add null handling to IntegerMedium: fromNull and toNull throw MediumI…
GeorgII-web Apr 10, 2026
689e67d
Add null handling to IntegerMediumUnsigned: fromNull and toNull throw…
GeorgII-web Apr 10, 2026
6142bd0
Add null handling to IntegerMinute: fromNull and toNull throw MinuteI…
GeorgII-web Apr 10, 2026
bdb3a54
Add null handling to IntegerMonth: fromNull and toNull throw MonthInt…
GeorgII-web Apr 10, 2026
8277fa4
Add null handling tests for IntegerMonth
GeorgII-web Apr 10, 2026
71497d9
Add null handling to IntegerNegative: fromNull and toNull throw Negat…
GeorgII-web Apr 10, 2026
384c070
Add null handling to IntegerNonNegative: fromNull and toNull throw No…
GeorgII-web Apr 10, 2026
3c8738a
Add null handling to IntegerNonPositive: fromNull and toNull throw No…
GeorgII-web Apr 10, 2026
1f8b3df
Add null handling to IntegerNonZero: fromNull and toNull throw NonZer…
GeorgII-web Apr 10, 2026
b111c0d
Add null handling to IntegerNormal: fromNull and toNull throw NormalI…
GeorgII-web Apr 10, 2026
191f6ea
Add null handling to IntegerNormalUnsigned: fromNull and toNull throw…
GeorgII-web Apr 10, 2026
4b93580
Add null handling to IntegerPercent: fromNull and toNull throw Percen…
GeorgII-web Apr 10, 2026
e1c130d
Add null handling to IntegerPort: fromNull and toNull throw PortInteg…
GeorgII-web Apr 10, 2026
4b6db3e
Add null handling to IntegerPositive: fromNull and toNull throw Posit…
GeorgII-web Apr 10, 2026
4b35943
Add null handling to IntegerSecond: fromNull and toNull throw SecondI…
GeorgII-web Apr 10, 2026
5bc38fe
Add null handling to IntegerSmall: fromNull and toNull throw SmallInt…
GeorgII-web Apr 10, 2026
4e88097
Add null handling to IntegerSmallUnsigned: fromNull and toNull throw …
GeorgII-web Apr 10, 2026
606be36
Add null handling to IntegerStandard: fromNull and toNull throw Integ…
GeorgII-web Apr 10, 2026
e9bfe22
Add null handling to IntegerTiny: fromNull and toNull throw TinyInteg…
GeorgII-web Apr 10, 2026
5dfec2c
Add null handling to IntegerTinyUnsigned: fromNull and toNull throw U…
GeorgII-web Apr 10, 2026
3d9eae6
Add abstract null handling methods and tests for IntegerTinyUnsigned
GeorgII-web Apr 10, 2026
86cf4a3
Add null handling to IntegerWeekDay: fromNull and toNull throw WeekDa…
GeorgII-web Apr 10, 2026
fd18b47
Add null handling to IntegerYear: fromNull and toNull throw YearInteg…
GeorgII-web Apr 10, 2026
3e57b3f
Add abstract null handling methods to IntegerTypeInterface
GeorgII-web Apr 10, 2026
e7088d5
Add null handling to StringBase64: fromNull and toNull throw Base64St…
GeorgII-web Apr 10, 2026
c0dd0c1
Add null handling to StringCountryCode: fromNull and toNull throw Cou…
GeorgII-web Apr 10, 2026
c07f69a
Add null handling to StringCurrencyCode: fromNull and toNull throw Cu…
GeorgII-web Apr 10, 2026
b9812db
Add null handling to StringDomain: fromNull and toNull throw DomainSt…
GeorgII-web Apr 10, 2026
48fb442
Add null handling to StringEmail: fromNull and toNull throw EmailStri…
GeorgII-web Apr 10, 2026
80d96dc
Add null handling to StringEmpty: fromNull and toNull throw StringTyp…
GeorgII-web Apr 10, 2026
810e667
Add null handling to StringFileName: fromNull and toNull throw FileNa…
GeorgII-web Apr 10, 2026
9ab68b2
Add null handling to StringHex: fromNull and toNull throw HexStringTy…
GeorgII-web Apr 10, 2026
bd249ab
Add null handling to String: fromNull and toNull throw StringTypeExce…
GeorgII-web Apr 10, 2026
3d9ff26
Add null handling to DateIso8601: fromNull and toNull throw Iso8601Da…
GeorgII-web Apr 11, 2026
9580e51
Add null handling to DateTimeAtom: fromNull and toNull throw DateTime…
GeorgII-web Apr 11, 2026
8fdbece
Add null handling to DateTimeCookie: fromNull and toNull throw Cookie…
GeorgII-web Apr 11, 2026
ad81d6f
Add null handling to DateTimeRFC1123: fromNull and toNull throw RFC11…
GeorgII-web Apr 11, 2026
171c190
Add null handling to DateTimeRFC2822: fromNull and toNull throw RFC28…
GeorgII-web Apr 11, 2026
ab27eb8
Add null handling to DateTimeRFC3339 and DateTimeRFC3339Extended: fro…
GeorgII-web Apr 11, 2026
4a95795
Add null handling unit tests for DateTimeRFC3339 and DateTimeRFC3339E…
GeorgII-web Apr 11, 2026
3b37ec2
Add null handling to DateTimeSql: fromNull and toNull throw DateTimeT…
GeorgII-web Apr 11, 2026
612fc5e
Add abstract null handling methods to DateTimeTypeAbstract
GeorgII-web Apr 11, 2026
f209d7e
Add null handling to DateTimeW3C: fromNull and toNull throw DateTimeT…
GeorgII-web Apr 11, 2026
f071032
Add null handling to TimeIso8601: fromNull and toNull throw Iso8601Ti…
GeorgII-web Apr 11, 2026
3bf1931
Add null handling to TimestampMicroseconds: fromNull and toNull throw…
GeorgII-web Apr 11, 2026
be4b2f8
Add null handling to TimestampMilliseconds: fromNull and toNull throw…
GeorgII-web Apr 11, 2026
09c2a17
Add null handling to TimestampSeconds: fromNull and toNull throw `Tim…
GeorgII-web Apr 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,26 @@ Code quality:
![psalm](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/georgii-web/75977b7515de20d7382f6855d44a1d97/raw/psalm.json)
![cs-fixer](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/georgii-web/75977b7515de20d7382f6855d44a1d97/raw/cs_fixer.json)

PHP supported version:

![Version 3.x](https://img.shields.io/badge/Version-3.x-777BB4)
![PHP >=8.4](https://img.shields.io/badge/PHP->=8.4-8892BF?logo=php)

![Version 2.x](https://img.shields.io/badge/Version-2.x-777BB4)
![PHP >=8.2 <8.4](https://img.shields.io/badge/PHP->=8.2--<8.4-8892BF?logo=php)

![Version 1.x](https://img.shields.io/badge/Version-1.x-777BB4)
![PHP >=7.4 <8.2](https://img.shields.io/badge/PHP->=7.4--<8.2-8892BF?logo=php)

---

### Install

- Use V3 for PHP >=8.4:
![Version 3.x](https://img.shields.io/badge/Version-3.x-777BB4)
![PHP >=8.4](https://img.shields.io/badge/PHP->=8.4-8892BF?logo=php)

```bash
composer require georgii-web/php-typed-values:^3
```

- Use V2 for PHP >=8.2 & <8.4:
![Version 2.x](https://img.shields.io/badge/Version-2.x-777BB4)
![PHP >=8.2 <8.4](https://img.shields.io/badge/PHP->=8.2--<8.4-8892BF?logo=php)

```bash
composer require georgii-web/php-typed-values:^2
```

- Use V1 for PHP >=7.4 & <8.2:
![Version 1.x](https://img.shields.io/badge/Version-1.x-777BB4)
![PHP >=7.4 <8.2](https://img.shields.io/badge/PHP->=7.4--<8.2-8892BF?logo=php)

```bash
composer require georgii-web/php-typed-values:^1
Expand Down Expand Up @@ -100,9 +92,11 @@ final readonly class Profile

#### Undefined

Prefer using the `Undefined` type over `null` to maintain consistency and improve type safety within the codebase.
Prefer using the `Undefined` type over `null` to maintain consistency and improve type safety within the codebase [null-is-evil](https://sidburn.github.io/blog/2016/03/20/null-is-evil).

#### Other usage examples

Other usage examples [docs/USAGE.md](docs/USAGE.md)
[docs/USAGE.md](docs/USAGE.md)

### Key features

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@
"echo \"Coverage\" && ./vendor/bin/pest --coverage --min=100 --parallel"
],
"mutate": [
"echo \"Undefined\" && ./vendor/bin/pest tests/Unit/Undefined --mutate --covered-only --parallel --min=100",
"echo \"String\" && ./vendor/bin/pest tests/Unit/String --mutate --covered-only --parallel --min=100",
"echo \"Integer\" && ./vendor/bin/pest tests/Unit/Integer --mutate --covered-only --parallel --min=100",
"echo \"DateTime\" && ./vendor/bin/pest tests/Unit/DateTime --mutate --covered-only --parallel --min=100",
"echo \"Decimal\" && ./vendor/bin/pest tests/Unit/Decimal --mutate --covered-only --parallel --min=100",
"echo \"Float\" && ./vendor/bin/pest tests/Unit/Float --mutate --covered-only --parallel --min=100",
"echo \"Base\" && ./vendor/bin/pest tests/Unit/Base --mutate --covered-only --parallel --min=100",
"echo \"Array\" && ./vendor/bin/pest tests/Unit/ArrayType --mutate --covered-only --parallel --min=100",
"echo \"Bool\" && ./vendor/bin/pest tests/Unit/Bool --mutate --covered-only --parallel --min=100",
"echo \"Undefined\" && ./vendor/bin/pest tests/Unit/Undefined --mutate --covered-only --parallel --min=100"
"echo \"Bool\" && ./vendor/bin/pest tests/Unit/Bool --mutate --covered-only --parallel --min=100"
]
},
"config": {
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Bool/BoolTypeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ abstract public static function fromFloat(float $value): static;

abstract public static function fromInt(int $value): static;

abstract public static function fromNull(null $value): never;

abstract public static function fromString(string $value): static;

abstract public function isTypeOf(string ...$classNames): bool;
Expand All @@ -46,6 +48,8 @@ abstract public function toFloat(): float;

abstract public function toInt(): int;

abstract public static function toNull(): never;

abstract public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Bool/BoolTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static function fromFloat(float $value): static;

public static function fromInt(int $value): static;

public static function fromNull(null $value): never;

public static function fromString(string $value): static;

public function isTypeOf(string ...$classNames): bool;
Expand All @@ -42,6 +44,8 @@ public function toFloat(): float;

public function toInt(): int;

public static function toNull(): never;

public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/DateTime/DateTimeTypeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
{
abstract public static function fromDateTime(DateTimeImmutable $value): static;

abstract public static function fromNull(null $value): never;

/**
* @param non-empty-string $timezone
*/
Expand All @@ -49,6 +51,8 @@ abstract public static function getFormat(): string;

abstract public function isTypeOf(string ...$classNames): bool;

abstract public static function toNull(): never;

abstract public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Decimal/DecimalTypeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ abstract public static function fromFloat(float $value): static;

abstract public static function fromInt(int $value): static;

abstract public static function fromNull(null $value): never;

abstract public static function fromString(string $value): static;

abstract public function isTypeOf(string ...$classNames): bool;
Expand Down Expand Up @@ -76,6 +78,8 @@ abstract public function toFloat(): float;

abstract public function toInt(): int;

abstract public function toNull(): never;

abstract public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Decimal/DecimalTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static function fromFloat(float $value): static;

public static function fromInt(int $value): static;

public static function fromNull(null $value): never;

public static function fromString(string $value): static;

public function isTypeOf(string ...$classNames): bool;
Expand All @@ -41,6 +43,8 @@ public function toFloat(): float;

public function toInt(): int;

public function toNull(): never;

public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Float/FloatTypeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ abstract public static function fromFloat(float $value): static;

abstract public static function fromInt(int $value): static;

abstract public static function fromNull(null $value): never;

abstract public static function fromString(string $value): static;

abstract public function toBool(): bool;
Expand All @@ -44,6 +46,8 @@ abstract public function toFloat(): float;

abstract public function toInt(): int;

abstract public static function toNull(): never;

abstract public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Float/FloatTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static function fromFloat(float $value): static;

public static function fromInt(int $value): static;

public static function fromNull(null $value): never;

public static function fromString(string $value): static;

public function isTypeOf(string ...$classNames): bool;
Expand All @@ -41,6 +43,8 @@ public function toFloat(): float;

public function toInt(): int;

public static function toNull(): never;

public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Integer/IntegerTypeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ abstract public static function fromFloat(float $value): static;

abstract public static function fromInt(int $value): static;

abstract public static function fromNull(null $value): never;

abstract public static function fromString(string $value): static;

abstract public function isTypeOf(string ...$classNames): bool;
Expand All @@ -46,6 +48,8 @@ abstract public function toFloat(): float;

abstract public function toInt(): int;

abstract public static function toNull(): never;

abstract public function toString(): string;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Base/Primitive/Integer/IntegerTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static function fromFloat(float $value): static;

public static function fromInt(int $value): static;

public static function fromNull(null $value): never;

public static function fromString(string $value): static;

public function isTypeOf(string ...$classNames): bool;
Expand All @@ -41,6 +43,8 @@ public function toFloat(): float;

public function toInt(): int;

public static function toNull(): never;

public function toString(): string;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Base/Primitive/PrimitiveTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
interface PrimitiveTypeInterface extends TypeInterface, JsonSerializable
{
// todo add all methods converters
/**
* Returns true if the Object value is empty.
*/
Expand Down
42 changes: 26 additions & 16 deletions src/Base/Primitive/Undefined/UndefinedTypeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,32 @@
{
abstract public static function create(): static;

abstract public static function fromArray(array $value): static;

/**
* @throws UndefinedTypeException
*/
abstract public static function fromBool(bool $value): static;

/**
* @throws UndefinedTypeException
*/
abstract public static function fromDecimal(string $value): static;

/**
* @throws UndefinedTypeException
*/
abstract public static function fromFloat(float $value): static;

/**
* @throws UndefinedTypeException
*/
abstract public static function fromInt(int $value): static;

abstract public static function fromString(string $value): static;
abstract public static function fromNull(null $value): static;

/**
* @throws UndefinedTypeException
*/
abstract public function toArray(): never;
abstract public static function fromString(string $value): static;

/**
* @throws UndefinedTypeException
Expand All @@ -54,7 +64,7 @@ abstract public function toBool(): never;
/**
* @throws UndefinedTypeException
*/
abstract public function toDecimal(): string;
abstract public function toDecimal(): never;

/**
* @throws UndefinedTypeException
Expand All @@ -66,51 +76,51 @@ abstract public function toFloat(): never;
*/
abstract public function toInt(): never;

abstract public function toNull(): null;

/**
* @throws UndefinedTypeException
*/
abstract public function toString(): string;

abstract public static function tryFromArray(
array $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;

abstract public static function tryFromBool(
bool $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;
): PrimitiveTypeAbstract|static;

abstract public static function tryFromDecimal(
string $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;
): PrimitiveTypeAbstract|static;

abstract public static function tryFromFloat(
float $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;
): PrimitiveTypeAbstract|static;

abstract public static function tryFromInt(
int $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;
): PrimitiveTypeAbstract|static;

abstract public static function tryFromMixed(
mixed $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;
): PrimitiveTypeAbstract|static;

abstract public static function tryFromString(
string $value,
PrimitiveTypeAbstract $default = new Undefined(),
): static;
): PrimitiveTypeAbstract|static;

/**
* @throws UndefinedTypeException
*/
abstract public function value(): string;

/**
* @throws UndefinedTypeException
*/
public function __toString(): string
{
return $this->toString();
Expand Down
Loading
Loading