-
-
Notifications
You must be signed in to change notification settings - Fork 739
Closed
Description
Question
I have the following code I want to refactor:
function getRequestParameter(Request $request, string $parameter, bool $force = false, $default = null);
// Example:
$this->getRequestParameter($request, 'locale', true);
$this->getRequestParameter($request, 'page', false, '1');This should be converted to Symfony's $request->get function.
The current approach
My current approach is to reorder and reuse the arguments based on their position in the call.=
/** @var MethodCall $node */
if ($this->nodeNameResolver->isName($node->var, '$this') || (string) $node->name !== 'getRequestParameter' ){ return; }
$request = $node->args[0]->value;
$parameterName = $node->args[1]->value;
$force = $node->args[2]?->value ?? $this->nodeFactory->createFalse();
$default = $node->args[3]?->value ?? $this->nodeFactory->createNull();But this raises the question: What is the best way to cover named arguments. Calls like this:
$this->getRequestParameter($request, 'locale', default: 'en');Is there already code in rector to handle this better? If not would be happy to provide an implementation.
Metadata
Metadata
Assignees
Labels
No labels