Skip to content

Commit 0e5aa9d

Browse files
committed
chevere/action 2.0
1 parent 40352dd commit 0e5aa9d

File tree

5 files changed

+5
-51
lines changed

5 files changed

+5
-51
lines changed

src/Controller.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use BadMethodCallException;
1717
use Chevere\Action\Controller as BaseController;
18-
use Chevere\Action\Interfaces\ReflectionActionInterface;
1918
use Chevere\DataStructure\Interfaces\MapInterface;
2019
use Chevere\DataStructure\Map;
2120
use Chevere\Http\Exceptions\ControllerException;
@@ -228,7 +227,7 @@ final public function status(): StatusInterface
228227
/**
229228
* @infection-ignore-all
230229
*/
231-
protected function assertRuntime(ReflectionActionInterface $reflection): void
230+
public function acceptRulesRuntime(): void
232231
{
233232
if (! isset($this->_query, $this->_bodyParsed, $this->_files)) {
234233
throw new LogicException('Server request not set. Did you forget to call withServerRequest() method?');

src/Exceptions/ControllerException.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,21 @@
2929
* translate them to ControllerException with appropriate HTTP status codes.
3030
*
3131
* Example:
32+
*
3233
* ```php
3334
* try {
3435
* $user = $this->userService->findById($id);
3536
* } catch (UserNotFoundException $e) {
3637
* throw new ControllerException('User not found', 404);
3738
* }
3839
* ```
39-
*
40-
* @param mixed $return Return value compatible with the definition at Controller's `return()` method
4140
*/
4241
class ControllerException extends Exception
4342
{
44-
public readonly mixed $return;
45-
4643
public function __construct(
4744
string $message = '',
4845
int $code = 0,
49-
mixed $return = null,
50-
?Throwable $previous = null
46+
?Throwable $previous = null,
5147
) {
5248
/** @infection-ignore-all */
5349
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
@@ -69,24 +65,6 @@ interface: ControllerInterface::class
6965
$line
7066
);
7167
}
72-
if ($return !== null) {
73-
try {
74-
$this->return = $controllerName->__toString()::return()->__invoke($return);
75-
} catch (Throwable $e) {
76-
throw new ActionException(
77-
(string) message(
78-
'Argument `%argument%` value is not compatible with return type defined in %controller%::return() method',
79-
argument: '$return',
80-
controller: $controllerName
81-
),
82-
$e,
83-
$file,
84-
$line
85-
);
86-
}
87-
} else {
88-
$this->return = null;
89-
}
9068

9169
parent::__construct($message, $code, $previous);
9270
}

tests/ControllerExceptionTest.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
use Chevere\Http\Exceptions\ControllerException;
1818
use Chevere\Tests\src\ControllerThrowsControllerException;
1919
use Chevere\Tests\src\ControllerThrowsControllerExceptionDefault;
20-
use Chevere\Tests\src\ControllerWrongReturnControllerException;
2120
use Exception;
2221
use InvalidArgumentException;
2322
use PHPUnit\Framework\TestCase;
2423
use Throwable;
25-
use TypeError;
2624

2725
final class ControllerExceptionTest extends TestCase
2826
{
@@ -52,7 +50,6 @@ public function testThrowsDefaults(): void
5250
$this->assertSame('', $e->getMessage());
5351
$this->assertSame(0, $e->getCode());
5452
$this->assertNull($e->getPrevious());
55-
$this->assertNull($e->return);
5653
}
5754
}
5855

@@ -66,26 +63,6 @@ public function testThrows(): void
6663
$this->assertSame(123, $e->getCode());
6764
$this->assertInstanceOf(Exception::class, $e->getPrevious());
6865
$this->assertSame('previous', $e->getPrevious()->getMessage());
69-
$this->assertSame(1.5, $e->return);
70-
}
71-
}
72-
73-
public function testWrongReturn(): void
74-
{
75-
try {
76-
new ControllerWrongReturnControllerException();
77-
} catch (Throwable $e) {
78-
$this->assertInstanceOf(ActionException::class, $e);
79-
$this->assertSame(
80-
'Argument `$return` value is not compatible with return type defined in Chevere\Tests\src\ControllerWrongReturnControllerException::return() method',
81-
$e->getMessage()
82-
);
83-
$this->assertSame(TypeError::class, $e->getPrevious()::class);
84-
$this->assertSame(
85-
__DIR__ . '/src/ControllerWrongReturnControllerException.php',
86-
$e->getFile()
87-
);
88-
$this->assertSame(25, $e->getLine());
8966
}
9067
}
9168
}

tests/src/ControllerThrowsControllerException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ class ControllerThrowsControllerException extends Controller
2121
{
2222
public function __construct()
2323
{
24-
throw new ControllerException('test', 123, 1.5, new Exception('previous'));
24+
throw new ControllerException('test', 123, new Exception('previous'));
2525
}
2626
}

tests/src/ControllerWrongReturnControllerException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct()
2525
throw new ControllerException(return: false);
2626
}
2727

28-
public static function return(): IntParameterInterface
28+
public static function acceptReturn(): IntParameterInterface
2929
{
3030
return int(min: 1);
3131
}

0 commit comments

Comments
 (0)