-private $some_property;
+private $someProperty;
// ...
-$this->some_property
+$this->someProperty
The following preg_replace_callback seems can be used:
preg_replace_callback(
'#(?<start>[a-z]+)(_)(?<ucfirst>[a-z]+)#msU',
function ($matches) {
return $matches['start'] . ucfirst($matches['ucfirst']);
},
$property
);
Doctrine Inflector has camelize method
https://www.doctrine-project.org/projects/doctrine-inflector/en/2.0/index.html#camelize
We already use this library in other rules.
Who's volunteering for this feature? :)
Fight for the issue! :D I'll definitely take a look at PR if I won't be the one!
Ok :)
@samsonasik If you don't have any opened PRs, go for it.
This class in Rector could be used: https://github.com/rectorphp/rector/blob/869441eb983ee95a093bb7ea1f4cbdb78a858dae/src/Util/StaticRectorStrings.php#L38-L50
BTW, In my current PR I'm going to decouple Property renaming logic to separate PropertyRenamer class, thus it might a good idea to solve this issue after my PR.
Depends what it does and when you deliver :). It should not be a blocker.
Basically, I want to decouple this logic https://github.com/rectorphp/rector/blob/master/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php#L134-L140
I need it for the rule I'm working on. I'll try to deliver it this evening. We can then merge the PR and I'll finish other minor issues as a next PR.
I've created PR https://github.com/rectorphp/rector/pull/4231 for it.
Already handled by https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md#underscoretocamelcasepropertynamerector based on https://github.com/rectorphp/rector/pull/4231#issuecomment-693378597 conversation.
I am closing it.
Most helpful comment
Doctrine Inflector has
camelizemethodhttps://www.doctrine-project.org/projects/doctrine-inflector/en/2.0/index.html#camelize
We already use this library in other rules.