News for hackers. Stuff that matters.
Re:A command line refactoring tool for PHP by itry on Monday April 08, 2013 @05:26AM (#5510749)
Is this really needed? I get away with :%s/$abcd/$this->abcd/gc just fine.

When you leave vim and do this:

    $ php refactor.phar convert-local-to-instance-variable tests/FooServiceTest.php\
    6 dependency | patch -p1
I stay in vim and simply do this:

    :%s/$dependency/$this->dependency/gc
And hit y a couple of times.

Pros:

I dont need to install, trust and learn a new tool.

I dont have to worry if i broke somthing. Because of edge cases the tool did not handle or because I messed up the syntax.

Re:A command line refactoring tool for PHP by beberlei on Monday April 08, 2013 @05:45AM (#5510801)
You picked the simplest refactoring, for converting local to instance variable I agree with you, this is easy in Vim.

But still there are some potential problems:

1. The variable already exists in the class. 2. You accidently mark to much or to few lines with ":<,>%"

For refactorings such as extract method the number of preconditions and information to gather is much bigger, such as input and output variables, existance of return statement etc.

We plan to integrate the tool into vim as well, so that you can call the refactorings through vim directly.

Re:A command line refactoring tool for PHP by itry on Monday April 08, 2013 @05:49AM (#5510815)
I did not pick anything. It is your example. Right from your page. And the only one you provide. If you have a better one: show us.
Re:A command line refactoring tool for PHP by beberlei on Monday April 08, 2013 @05:55AM (#5510828)
The blog post shows extract method as well as a second refactoring

Edit: Also see the screenshot here for a more complex extract method refactoring: http://qafoolabs.github.io/php-refactoring-browser/

Re:A command line refactoring tool for PHP by itry on Monday April 08, 2013 @06:01AM (#5510841)
Ah, I missed the extract-method example.

Similarely to the convert-local-to-instance-variable example, to me it looks like overkill. I never had a problem, doing these things manually. But if you like doing it this way - I dont complain. To each his own.

Re:A command line refactoring tool for PHP by jasonlotito on Monday April 08, 2013 @08:31AM (#5511277)
I never had a problem doing things manually either. However, as soon as I can automate them, I do. If I can automate extract method to, in effect, a single keystroke, why not?

It's the difference between using hjkl for movement, and ignoring all the other commands vim as to offer. Why wouldn't want you to automate patterns in your work?

Re:A command line refactoring tool for PHP by pserwylo on Monday April 08, 2013 @06:04AM (#5510847)
I think that a tool like this will, with time, become much more efficient than a simple search replace. As mentioned in my sibling, there are edge cases which need thought, and a proper refactoring tool will excel.

I'd love to see a tool like this start to support a bunch of complex refactorings, especially on a project level. With time, it could start to support a bunch of nice things which make it easier to use, such as aliases or readline support for auto-completion, etc. People may then write plugins or scripts for various editors such as vim to make various refactorings even simpler to use.

Of course, this is all wild speculation, but it is what I would love to see. I hope it works out very well, because I am a massive fan of the refactoring in the IntelliJ PHP plugin/PHPStorm.