public function testRelativePathConstructionForAbsoluteVFSFiles() { $src = $this->createFileSystem()->getChild('src')->url(); $bar = $src . DIRECTORY_SEPARATOR . 'Foo' . DIRECTORY_SEPARATOR . 'Bar.php'; $file = File::createFromPath($bar, $notRelatedWorkingDir = __DIR__); $this->assertEquals('vfs://project/src/Foo/Bar.php', $file->getRelativePath()); }
public function testFindNames() { $file = File::createFromPath(__FILE__, __DIR__); $scanner = new ParserPhpNameScanner(); $names = $scanner->findNames($file); $this->assertEquals(array(new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Adapters\\PHPParser', 'QafooLabs\\Refactoring\\Adapters\\PHPParser', PhpName::TYPE_NAMESPACE), $file, 3), new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Domain\\Model\\File', 'QafooLabs\\Refactoring\\Domain\\Model\\File', PhpName::TYPE_USE), $file, 5), new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Domain\\Model\\PhpName', 'QafooLabs\\Refactoring\\Domain\\Model\\PhpName', PhpName::TYPE_USE), $file, 6), new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Domain\\Model\\PhpNameOccurance', 'QafooLabs\\Refactoring\\Domain\\Model\\PhpNameOccurance', PhpName::TYPE_USE), $file, 7), new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Adapters\\PHPParser\\ParserPhpNameScannerTest', 'ParserPhpNameScannerTest', PhpName::TYPE_CLASS), $file, 9), new PhpNameOccurance(new PhpName('PHPUnit_Framework_TestCase', 'PHPUnit_Framework_TestCase', PhpName::TYPE_USAGE), $file, 9), new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Domain\\Model\\File', 'File', PhpName::TYPE_USAGE), $file, 13), new PhpNameOccurance(new PhpName('QafooLabs\\Refactoring\\Adapters\\PHPParser\\ParserPhpNameScanner', 'ParserPhpNameScanner', PhpName::TYPE_USAGE), $file, 14)), array_slice($names, 0, 8)); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = File::createFromPath($input->getArgument('file'), getcwd()); $codeAnalysis = new StaticCodeAnalysis(); $editor = new PatchEditor(new OutputPatchCommand($output)); $phpNameScanner = new ParserPhpNameScanner(); $optimizeUse = new OptimizeUse($codeAnalysis, $editor, $phpNameScanner); $optimizeUse->refactor($file); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = File::createFromPath($input->getArgument('file'), getcwd()); $line = (int) $input->getArgument('line'); $variable = new Variable($input->getArgument('variable')); $scanner = new ParserVariableScanner(); $codeAnalysis = new StaticCodeAnalysis(); $editor = new PatchEditor(new OutputPatchCommand($output)); $convertRefactoring = new ConvertLocalToInstanceVariable($scanner, $codeAnalysis, $editor); $convertRefactoring->refactor($file, $line, $variable); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = File::createFromPath($input->getArgument('file'), getcwd()); $range = LineRange::fromString($input->getArgument('range')); $newMethodName = $input->getArgument('newmethod'); $scanner = new ParserVariableScanner(); $codeAnalysis = new StaticCodeAnalysis(); $editor = new PatchEditor(new OutputPatchCommand($output)); $extractMethod = new ExtractMethod($scanner, $codeAnalysis, $editor); $extractMethod->refactor($file, $range, $newMethodName); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = File::createFromPath($input->getArgument('file'), getcwd()); $line = (int) $input->getArgument('line'); $name = new Variable($input->getArgument('name')); $newName = new Variable($input->getArgument('new-name')); $scanner = new ParserVariableScanner(); $codeAnalysis = new StaticCodeAnalysis(); $editor = new PatchEditor(new OutputPatchCommand($output)); $renameLocalVariable = new RenameLocalVariable($scanner, $codeAnalysis, $editor); $renameLocalVariable->refactor($file, $line, $name, $newName); }
/** * @return File[] */ public function findAllPhpFilesRecursivly() { $workingDirectory = $this->workingDirectory; $iterator = new AppendIterator(); foreach ($this->paths as $path) { $iterator->append(new CallbackTransformIterator(new CallbackFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY), function (SplFileInfo $file) { return substr($file->getFilename(), -4) === ".php"; }), function ($file) use($workingDirectory) { return File::createFromPath($file->getPathname(), $workingDirectory); })); } $files = iterator_to_array($iterator); return new StandardCallbackFilterIterator($iterator, function ($file, $filename) use($files) { return !in_array($filename, $files); }); }