[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/rector/ -> DokuWikiRenamePrintToEcho.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\test\rector;
   4  
   5  use PhpParser\Node;
   6  use PhpParser\Node\Expr\Print_;
   7  use PhpParser\Node\Stmt\Echo_;
   8  use PhpParser\Node\Stmt\Expression;
   9  use Rector\Rector\AbstractRector;
  10  use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
  11  use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
  12  
  13  /**
  14   * Replace print calls with echo
  15   */
  16  class DokuWikiRenamePrintToEcho extends AbstractRector
  17  {
  18  
  19      /** @inheritdoc */
  20      public function getRuleDefinition(): RuleDefinition
  21      {
  22          return new RuleDefinition('Replace print calls with echo', [
  23              new CodeSample(
  24                  <<<'CODE_SAMPLE'
  25  print 'Hello World';
  26  CODE_SAMPLE,
  27                  <<<'CODE_SAMPLE'
  28  echo 'Hello World';
  29  CODE_SAMPLE
  30              ),
  31          ]);
  32      }
  33  
  34      /** @inheritdoc */
  35      public function getNodeTypes(): array
  36      {
  37          return [Expression::class];
  38      }
  39  
  40      /** @inheritdoc */
  41      public function refactor(Node $node)
  42      {
  43          if (!$node->expr instanceof Print_) {
  44              return null;
  45          }
  46          return new Echo_([$node->expr->expr], $node->getAttributes());
  47      }
  48  }