Author: Kévin Dunglas (dunglas@gmail.com)
 /**
  * {@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>');
 }
Esempio n. 2
0
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare (strict_types=1);
// Cannot use PHPUnit right now because of this bug: https://github.com/phpDocumentor/Reflection/issues/85
require __DIR__ . '/../vendor/autoload.php';
use phpDocumentor\Reflection\Php\ProjectFactory;
use Dunglas\PhpDocToTypeHint\Converter;
function same($value1, $value2)
{
    if ($value1 !== $value2) {
        throw new \RuntimeException('Values are not the same.');
    }
}
$converter = new Converter();
$projectFactory = ProjectFactory::createInstance();
$project = $projectFactory->create('functions1', [__DIR__ . '/Fixtures/functions1.php']);
foreach ($project->getFiles() as $file) {
    same(<<<'PHP'
<?php

/**
 * @var string
 */
$foo = 'bar';

/**
 * Must not be modified.
 *
 * @return string|null
Esempio n. 3
0
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare (strict_types=1);
// Cannot use PHPUnit right now because of this bug: https://github.com/phpDocumentor/Reflection/issues/85
require __DIR__ . '/../vendor/autoload.php';
use phpDocumentor\Reflection\Php\ProjectFactory;
use Dunglas\PhpDocToTypeHint\Converter;
function same($value1, $value2)
{
    if ($value1 !== $value2) {
        throw new \RuntimeException('Values are not the same.');
    }
}
$converter = new Converter();
$projectFactory = ProjectFactory::createInstance();
$project = $projectFactory->create('functions1', [__DIR__ . '/Fixtures/functions1.php']);
foreach ($project->getFiles() as $file) {
    same(<<<'PHP'
<?php

/**
 * @var string
 */
$foo = 'bar';

/**
 * Must not be modified.
 *
 * @return string|null