Skip to content

Commit

Permalink
Improve codebase docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 16, 2023
1 parent 73f4149 commit 553ee60
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Serializer/CastToArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use const JSON_THROW_ON_ERROR;

/**
* @implements TypeCasting<array|null>
* @implements TypeCasting<?array>
*/
final class CastToArray implements TypeCasting
{
Expand Down
3 changes: 3 additions & 0 deletions src/Serializer/CastToBool.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

use function filter_var;

/**
* @implements TypeCasting<?bool>
*/
final class CastToBool implements TypeCasting
{
private readonly bool $isNullable;
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/CastToFloat.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function filter_var;

/**
* @implements TypeCasting<float|null>
* @implements TypeCasting<?float>
*/
final class CastToFloat implements TypeCasting
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/CastToInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use function filter_var;

/**
* @implements TypeCasting<int|null>
* @implements TypeCasting<?int>
*/
final class CastToInt implements TypeCasting
{
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/CastToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use ReflectionProperty;

/**
* @implements TypeCasting<string|null>
* @implements TypeCasting<?string>
*/
final class CastToString implements TypeCasting
{
Expand Down
11 changes: 11 additions & 0 deletions src/Serializer/ClosureCasting.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
use function array_key_exists;
use function class_exists;

/**
* @template TValue
*/
final class ClosureCasting implements TypeCasting
{
/** @var array<string, Closure(?string, bool, mixed...): TValue> */
private static array $casters = [];

private readonly string $type;
private readonly bool $isNullable;
/** @var Closure(?string, bool, mixed...): TValue */
private readonly Closure $closure;
private readonly array $arguments;

Expand All @@ -41,6 +46,9 @@ public function __construct(ReflectionProperty|ReflectionParameter $reflectionPr
$this->arguments = $arguments;
}

/**
* @return TValue
*/
public function toVariable(?string $value): mixed
{
try {
Expand All @@ -60,6 +68,9 @@ public function toVariable(?string $value): mixed
}
}

/**
* @param Closure(?string, bool, mixed...): TValue $closure
*/
public static function register(string $type, Closure $closure): void
{
self::$casters[$type] = match (true) {
Expand Down

0 comments on commit 553ee60

Please sign in to comment.