Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 8, 2024
1 parent 81486dc commit cf52087
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ Use the `main` method to determine your action's main logic. Use **attributes**
* Before validation rules:

```php
use Chevere\Action\Action;

class MyAction extends Action
class MyAction
{
protected function main(
string $value
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": "^8.1",
"chevere/message": "^0.1.0",
"chevere/message": "^1.0.0",
"chevere/parameter": "^1.0.x-dev"
},
"require-dev": {
Expand Down
9 changes: 7 additions & 2 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Chevere\Action\Interfaces\ControllerInterface;
use Chevere\Action\Interfaces\ReflectionActionInterface;
use Chevere\Action\Traits\ActionTrait;
use Chevere\Parameter\Interfaces\MixedParameterInterface;
use Chevere\Parameter\Interfaces\StringParameterInterface;
use InvalidArgumentException;
use function Chevere\Message\message;
Expand All @@ -31,18 +32,22 @@ protected static function assertStatic(ReflectionActionInterface $reflection): v
$invalid = [];
$parameters = reflectionToParameters($reflection->method());
foreach ($parameters as $name => $parameter) {
if ($parameter instanceof MixedParameterInterface) {
continue;
}
if (! ($parameter instanceof StringParameterInterface)) {
$invalid[] = $name;
}
}
if ($invalid === []) {
return;
}
$names = implode(', ', $invalid);

throw new InvalidArgumentException(
(string) message(
'Parameter `%parameters%` must be of type **%type%** for controller **%className%**',
parameters: implode(', ', $invalid),
'Parameter `%names%` must be of type **%type%** for controller `%className%`',
names: $names,
type: 'string',
className: static::class
)
Expand Down
4 changes: 2 additions & 2 deletions src/ReflectionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use TypeError;
use function Chevere\Message\message;
use function Chevere\Parameter\reflectionToParameters;
use function Chevere\Parameter\reflectionToReturnParameter;
use function Chevere\Parameter\reflectionToReturn;

final class ReflectionAction implements ReflectionActionInterface
{
Expand Down Expand Up @@ -76,7 +76,7 @@ interface: ActionInterface::class,
$attributes = $this->method->getAttributes(ReturnAttr::class);
$this->return = match (true) {
$attributes === [] => $action::return(),
default => reflectionToReturnParameter($this->method),
default => reflectionToReturn($this->method),
};
if (! $this->method->hasReturnType()) {
if ($this->return->type()->typeHinting() === 'null') {
Expand Down
2 changes: 1 addition & 1 deletion tests/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testIterableResponseError(): void
$this->expectException(ActionException::class);
$this->expectExceptionMessage(
<<<PLAIN
`Chevere\Tests\src\ActionTestIterableResponseError` InvalidArgumentException → [_V *iterable]: Chevere\Parameter\IntParameter::__invoke(): Argument #1 (\$value) must be of type int, string given
`Chevere\Tests\src\ActionTestIterableResponseError` InvalidArgumentException → [V *iterable]: Argument #1 (\$value) must be of type int, string given
PLAIN
);
$action->__invoke();
Expand Down

0 comments on commit cf52087

Please sign in to comment.