Skip to content

Commit

Permalink
Publish code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 26, 2024
1 parent 94f945f commit 3901b14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class UserController extends AbstractController
{
public function registerUser(Request $request): Response
{
$username = $request->request->get('username');
$username = $request->get('username');

$hasher = $this->container->get('password_hasher');

Expand Down
15 changes: 8 additions & 7 deletions utils/rector/src/Rector/UseRequestRequestGetRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use PhpParser\Node\Expr\PropertyFetch;
use PHPStan\Type\ObjectType;
use Rector\Rector\AbstractRector;
use SelectiveVarDump\SelectiveVarDumper;
use SelectiveVarDump\VarDumperConfig;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class UseRequestRequestGetRector extends AbstractRector
{
// crop-start

/**
* @param MethodCall $node
*/
Expand All @@ -24,23 +24,24 @@ public function refactor(Node $node): ?Node
return null;
}

$varDumper = new SelectiveVarDumper(new VarDumperConfig([
'className',
]));
echo $varDumper->dump($this->getType($node->var)) . "\n\n";

if (! $this->isObjectType(
$node->var,
new ObjectType('Symfony\Component\HttpFoundation\Request')
)) {
return null;
}

/*
* Make the original method call on the fetched `request`
* property instead:
*/
$node->var = new PropertyFetch($node->var, 'request');

return $node;
}

// crop-end

/**
* @return array<class-string<Node>>
*/
Expand Down

0 comments on commit 3901b14

Please sign in to comment.