convert() public method

Converts the given file.
public convert ( phpDocumentor\Reflection\Php\Project $project, phpDocumentor\Reflection\Php\File $file ) : string
$project phpDocumentor\Reflection\Php\Project
$file phpDocumentor\Reflection\Php\File
return string
コード例 #1
0
 /**
  * {@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>');
 }
コード例 #2
0
ファイル: test.php プロジェクト: kfreiman/phpdoc-to-typehint
{
}

/**
 * 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)
コード例 #3
0
ファイル: test.php プロジェクト: dunglas/phpdoc-to-typehint
{
}

/**
 * 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