Skip to content

Commit f84a31f

Browse files
committed
Update Controller::prepareModel method
1 parent d158fe3 commit f84a31f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/Controller.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@ public function __construct(Request $request, Response $response)
5858
*/
5959
protected function prepareModel() : static
6060
{
61-
if ( ! \property_exists($this, 'model')) {
62-
return $this;
61+
if (\property_exists($this, 'model')) {
62+
$property = new ReflectionProperty($this, 'model');
63+
$type = $property->getType();
64+
if ( ! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
65+
throw new LogicException(
66+
'The ' . static::class
67+
. '::$model property must have one type to be instantiated'
68+
);
69+
}
70+
$name = $type->getName();
71+
$this->model = new $name();
6372
}
64-
$property = new ReflectionProperty($this, 'model');
65-
$type = $property->getType();
66-
if ( ! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
67-
throw new LogicException(
68-
'The ' . static::class
69-
. '::$model property must have one type to be instantiated'
70-
);
71-
}
72-
$name = $type->getName();
73-
$this->model = new $name();
7473
return $this;
7574
}
7675

0 commit comments

Comments
 (0)