Skip to content

Use this->t instead of t #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chrfritsch
Copy link

@chrfritsch chrfritsch commented Nov 9, 2022

Description

It checks if a t() call can be converted to $this->t()

To Test

  • Add steps to test this feature

Drupal.org issue

Provide a link to the issue from https://www.drupal.org/project/rector/issues. If no issue exists, please create one and link to this PR.

@tobiasbaehr
Copy link
Contributor

@bbrala
Copy link
Collaborator

bbrala commented May 6, 2025

This rector needs rewriting. Parent is no longer available by default, so we need to rearcitect this, see https://getrector.com/blog/rector-017-using-scoped-traverse

think something like:

  1. Add betternodefinder in constructor (public function __construct(protected BetterNodeFinder $betterNodeFinder){})
  2. Match on class method probably (Node\Stmt\ClassMethod::class)
  3. Then use $stmts = $this->betterNodeFinder->find($node, FuncCall::class); i think to find if t() is used
  4. Use the context of the class to find out if the class has a $this->t(...) availabe. This might neem swithcing with 3, it might be faster that way to first see if we have a t function available, then if so see if it is uses wrongly?
  5. Make the change to the functioncall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants