diff --git a/README.md b/README.md index 1b3a4d5..871d41d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Based on data from these sources the Refactoring Browser consists of two distinc ## Install & Basic Usage -[Download PHAR](https://github.com/QafooLabs/php-refactoring-browser/releases) +[Download PHAR](https://github.com/FlickerBean/php-refactoring-browser/releases/tag/v0.1.1) The refactoring browser is used with: diff --git a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ConvertLocalToInstanceVariableCommand.php b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ConvertLocalToInstanceVariableCommand.php index 2f070b7..ed812f3 100644 --- a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ConvertLocalToInstanceVariableCommand.php +++ b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ConvertLocalToInstanceVariableCommand.php @@ -65,7 +65,20 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $file = File::createFromPath($input->getArgument('file'), getcwd()); + $filename = $input->getArgument('file'); + if ('-' == $filename) { + $filename = false; + $contents = ''; + while (!feof(STDIN)) { + $contents .= fread(STDIN, 1024); + } + } + if ($filename) { + $file = File::createFromPath($filename, getcwd()); + } else { + $file = File::createFromContents($contents, getcwd()); + } + $line = (int)$input->getArgument('line'); $variable = new Variable($input->getArgument('variable')); diff --git a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ExtractMethodCommand.php b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ExtractMethodCommand.php index 93db01b..d29f990 100644 --- a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ExtractMethodCommand.php +++ b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/ExtractMethodCommand.php @@ -72,7 +72,20 @@ function and generates the argument list and return statement accordingly. protected function execute(InputInterface $input, OutputInterface $output) { - $file = File::createFromPath($input->getArgument('file'), getcwd()); + $filename = $input->getArgument('file'); + if ('-' == $filename) { + $filename = false; + $contents = ''; + while (!feof(STDIN)) { + $contents .= fread(STDIN, 1024); + } + } + if ($filename) { + $file = File::createFromPath($filename, getcwd()); + } else { + $file = File::createFromContents($contents, getcwd()); + } + $range = LineRange::fromString($input->getArgument('range')); $newMethodName = $input->getArgument('newmethod'); diff --git a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/OptimizeUseCommand.php b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/OptimizeUseCommand.php index d21ca51..01386a0 100644 --- a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/OptimizeUseCommand.php +++ b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/OptimizeUseCommand.php @@ -72,7 +72,19 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $file = File::createFromPath($input->getArgument('file'), getcwd()); + $filename = $input->getArgument('file'); + if ('-' == $filename) { + $filename = false; + $contents = ''; + while (!feof(STDIN)) { + $contents .= fread(STDIN, 1024); + } + } + if ($filename) { + $file = File::createFromPath($filename, getcwd()); + } else { + $file = File::createFromContents($contents, getcwd()); + } $codeAnalysis = new StaticCodeAnalysis(); $editor = new PatchEditor(new OutputPatchCommand($output)); diff --git a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/RenameLocalVariableCommand.php b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/RenameLocalVariableCommand.php index f69d1f6..369ab6f 100644 --- a/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/RenameLocalVariableCommand.php +++ b/src/main/QafooLabs/Refactoring/Adapters/Symfony/Commands/RenameLocalVariableCommand.php @@ -64,7 +64,20 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $file = File::createFromPath($input->getArgument('file'), getcwd()); + $filename = $input->getArgument('file'); + if ('-' == $filename) { + $filename = false; + $contents = ''; + while (!feof(STDIN)) { + $contents .= fread(STDIN, 1024); + } + } + if ($filename) { + $file = File::createFromPath($filename, getcwd()); + } else { + $file = File::createFromContents($contents, getcwd()); + } + $line = (int)$input->getArgument('line'); $name = new Variable($input->getArgument('name')); $newName = new Variable($input->getArgument('new-name')); diff --git a/src/main/QafooLabs/Refactoring/Domain/Model/File.php b/src/main/QafooLabs/Refactoring/Domain/Model/File.php index 40fc0a8..ae0fac6 100644 --- a/src/main/QafooLabs/Refactoring/Domain/Model/File.php +++ b/src/main/QafooLabs/Refactoring/Domain/Model/File.php @@ -20,6 +20,7 @@ class File { private $relativePath; private $code; + private $temp_file; /** * @param string $path @@ -45,6 +46,31 @@ public static function createFromPath($path, $workingDirectory) return new self($relativePath, $code); } + /** + * @param mixed $content + * @param mixed $workingDirectory + * + * @return File + */ + public static function createFromContents($content, $workingDirectory) + { + $temp = tmpfile(); + $meta_datas = stream_get_meta_data($temp); + $tmp_filename = $meta_datas['uri']; + fwrite($temp, $content); + + // Now we move the file to prevent it being instantly deleted at the + // end of the script. This allows piping it to 'patch' for instance, + // which requires the original file. + $new_tmp_filename = $tmp_filename.'1'; + if (!rename($tmp_filename, $new_tmp_filename)) { + throw new RuntimeException("Could not move temporary file " . $tmp_filename); + } + + return File::createFromPath($new_tmp_filename, $workingDirectory); + } + + public function __construct($relativePath, $code) { $this->relativePath = $relativePath;