Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nullable
Browse files Browse the repository at this point in the history
h4kuna committed Jul 23, 2024
1 parent 810e7f1 commit 007b51f
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Basic/Bools.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,12 @@ final class Bools
{
use StaticClass;

public static function nullable(mixed $value): ?bool
{
return $value === null ? null : self::from($value);
}


public static function from(mixed $value): bool
{
if ($value === true) {
6 changes: 6 additions & 0 deletions src/Basic/Floats.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@ final class Floats
{
use StaticClass;

public static function nullable(mixed $value): ?float
{
return $value === null ? null : self::from($value);
}


public static function from(
mixed $value,
string $decimalPoint = ',',
6 changes: 6 additions & 0 deletions src/Basic/Integer.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,12 @@ final class Integer
{
use StaticClass;

public static function nullable(mixed $value): ?int
{
return $value === null ? null : self::from($value);
}


public static function from(mixed $value): int
{
if (is_bool($value) || is_int($value) || $value === null || $value === '' || (is_numeric($value) && $value == (int) $value)) {
6 changes: 6 additions & 0 deletions src/Basic/Strings.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@ final class Strings
{
use StaticClass;

public static function nullable(mixed $value): ?string
{
return $value === null ? null : self::from($value);
}


public static function strokeToPoint(string $value): string
{
return strtr($value, ',', '.');

0 comments on commit 007b51f

Please sign in to comment.