Skip to content

Commit

Permalink
action default return mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Dec 18, 2023
1 parent b34a2e0 commit 233af7d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Chevere\Action;

use Chevere\Action\Interfaces\ActionInterface;
use Chevere\Parameter\Attributes\ReturnAttr;
use Chevere\Parameter\Cast;
use Chevere\Parameter\Interfaces\CastInterface;
use Chevere\Parameter\Interfaces\ParameterInterface;
Expand All @@ -26,7 +27,8 @@
use TypeError;
use function Chevere\Message\message;
use function Chevere\Parameter\arguments;
use function Chevere\Parameter\arrayp;
use function Chevere\Parameter\mixed;
use function Chevere\Parameter\reflectionToReturnParameter;

/**
* @method mixed run()
Expand Down Expand Up @@ -64,7 +66,7 @@ final public function __invoke(mixed ...$argument): CastInterface

public static function return(): ParameterInterface
{
return arrayp();
return mixed();
}

final public static function assert(): void
Expand Down Expand Up @@ -96,11 +98,16 @@ final protected static function assertMethod(): array
)
);
}
$method = new ReflectionMethod(static::class, static::RUN_METHOD);
$return = static::return();
if (! $method->hasReturnType()) {
$reflection = new ReflectionMethod(static::class, static::RUN_METHOD);
$attributes = $reflection->getAttributes(ReturnAttr::class);
if ($attributes === []) {
$return = static::return();
} else {
$return = reflectionToReturnParameter($reflection);
}
if (! $reflection->hasReturnType()) {
if ($return->type()->typeHinting() === 'null') {
return [$method, $return];
return [$reflection, $return];
}

throw new TypeError(
Expand All @@ -112,7 +119,7 @@ final protected static function assertMethod(): array
);
}

return [$method, $return];
return [$reflection, $return];
}

/**
Expand Down Expand Up @@ -169,6 +176,9 @@ final protected static function assertTypes(
default => $expectName,
};
}
if (in_array('mixed', $expect, true)) {
return;
}
if (! in_array($return, $expect, true)) {
throw new TypeError(
(string) message(
Expand Down

0 comments on commit 233af7d

Please sign in to comment.