Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 52 additions & 37 deletions src/FileGenerators/SyncClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,10 @@ public function generate(): Node
'wait',
[
new Node\Expr\MethodCall(
new Node\Expr\MethodCall(
new Node\Expr\Variable('this'),
'handleCommand',
[
new Node\Expr\New_(
new Node\Name('BuildAsyncFromSyncCommand'),
[
new Node\Expr\ClassConstFetch(
new Node\Name('self'),
'HYDRATE_CLASS'
),
new Node\Expr\Variable('this'),
]
),
]
),
$this->callCommandBus(),
'then',
[
new Node\Expr\Closure(
[
'params' => [
new Node\Param(
Inflector::camelize($className),
null,
$interfaceName
)
],
'stmts' => [
new Node\Stmt\Return_(
new Node\Expr\MethodCall(
new Node\Expr\Variable(
Inflector::camelize($className)
),
'refresh'
)
)
],
]
)
$this->createRefreshClosure($className, $interfaceName),
]
),
]
Expand All @@ -97,4 +62,54 @@ public function generate(): Node
->getNode()
;
}

protected function callCommandBus(): Node\Expr\MethodCall
{
return new Node\Expr\MethodCall(
new Node\Expr\Variable('this'),
'handleCommand',
[
$this->createCommand(),
]
);
}

protected function createCommand(): Node\Expr\New_
{
return new Node\Expr\New_(
new Node\Name('BuildAsyncFromSyncCommand'),
[
new Node\Expr\ClassConstFetch(
new Node\Name('self'),
'HYDRATE_CLASS'
),
new Node\Expr\Variable('this'),
]
);
}

protected function createRefreshClosure(string $className, string $interfaceName): Node\Expr\Closure
{
return new Node\Expr\Closure(
[
'params' => [
new Node\Param(
Inflector::camelize($className),
null,
$interfaceName
)
],
'stmts' => [
new Node\Stmt\Return_(
new Node\Expr\MethodCall(
new Node\Expr\Variable(
Inflector::camelize($className)
),
'refresh'
)
)
],
]
);
}
}