Rector: [Naming] Add property camel case naming rule

Created on 15 Sep 2020  路  10Comments  路  Source: rectorphp/rector

-private $some_property;
+private $someProperty;


// ...

-$this->some_property
+$this->someProperty

Most helpful comment

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.

All 10 comments

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
);

ref https://3v4l.org/b3sUK

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.

Was this page helpful?
0 / 5 - 0 ratings