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