Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Allow stdin input for single file refactors #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

LeighBicknell
Copy link

@LeighBicknell LeighBicknell commented Jun 22, 2016

Allowing stdin input has many uses and is, in my opinion essential.

I'm not familiar with the codebase, but I came up with these changes to support stdin.

Example of use:
$ cat home.php | php refactor.phar extract-method - 7-7 myNewFunction
(obviously this isn't a great example of a use case)

Replacing the filename parameter with - will tell refactor.phar to use stdin as the file contents instead of a specific file.

As most commands have a dependency on the File class, it will create a tmpfile() with the stdin contents, and then create a File object from the temporary file. I've added a static File::createFromContents() function to facilitate this.

Use cases are numerous, but my specific use case/reason for implementation is for the vim-php-refactoring plugin (i've also forked to support this change). Which has multiple restrictions thrust upon it due to php-refactoring-browser not supporting stdin input.

Example:
:%!php refactor.phar extract-method - 7-7 myNewFunction | patch --silent --ouput=- --dir="/tmp"

This allows on-the-fly refactoring of modified vim buffers, without worrying about loosing unsaved buffer changes, or directly modifying and having the reload the file on disk. It makes the whole experience much more seamless.

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

Successfully merging this pull request may close these issues.

2 participants