/** * {@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>'); }
{ } /** * Must not be converted (already using type hints). * * @param int $a * * @return string */ function bat(int $a): string { } PHP , $converter->convert($project, $file)); } $projectFactory = ProjectFactory::createInstance(); $project = $projectFactory->create('functions2', [__DIR__ . '/Fixtures/functions2.php']); foreach ($project->getFiles() as $file) { same(<<<'PHP' <?php namespace foo; /** * @param string|null $a * * @return int */ function test(string $a = null)
{ } /** * Must not be converted (already using type hints). * * @param int $a * * @return string */ function bat(int $a): string { } PHP , $converter->convert($project, $file)); } $projectFactory = ProjectFactory::createInstance(); $project = $projectFactory->create('functions2', [__DIR__ . '/Fixtures/functions2.php']); foreach ($project->getFiles() as $file) { same(<<<'PHP' <?php namespace foo; /** * @param string|null $a * * @return int */ function test(string $a = null): int