/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $finder = (new Finder())->in($input->getArgument('input'))->exclude($input->getOption('exclude'))->name('*.php')->files(); $files = []; foreach ($finder as $file) { $files[] = $file->getRealpath(); } $project = ProjectFactory::createInstance()->create('current', $files); $converter = new Converter(); $output->writeln('<comment>Running the PHPDoc to Type Hint converter. Brought to you by Kévin Dunglas and Les-Tilleuls.coop.</comment>'); $output->writeln(''); $progress = new ProgressBar($output, count($files)); $changed = []; foreach ($project->getFiles() as $file) { $old = $file->getSource(); $new = $converter->convert($project, $file); if ($new !== $old) { if ($input->getOption('dry-run')) { $changed[] = ['path' => $file->getPath(), 'diff' => $this->differ->diff($old, $new)]; } else { file_put_contents($file->getPath(), $new); } } $progress->advance(); } $progress->finish(); $output->writeln(''); $output->writeln(''); foreach ($changed as $i => $file) { $output->writeln(sprintf('<fg=blue>%d) %s</>', $i + 1, $file['path'])); $output->writeln(''); $output->writeln($file['diff']); $output->writeln(''); } $output->writeln('<info>Conversion done.</info>'); }
trait BazTrait { /** * @param int $a * * @return \DateTime */ protected function inTrait(int $a) : \DateTime{ } } PHP , $converter->convert($project, $file)); } $projectFactory = ProjectFactory::createInstance(); $childPath = __DIR__ . '/Fixtures/Child.php'; $project = $projectFactory->create('inheritance', [$childPath, __DIR__ . '/Fixtures/Foo.php', __DIR__ . '/Fixtures/BarInterface.php']); foreach ($project->getFiles() as $path => $file) { if ($childPath === $path) { same(<<<'PHP' <?php namespace bar; class Child extends Foo implements BarInterface { use BazTrait; public function test(float $a) {