1<?php 2 3namespace dokuwiki\test\rector; 4 5use PhpParser\Node; 6use PhpParser\Node\Expr\FuncCall; 7use PhpParser\Node\Expr\Print_; 8use PhpParser\Node\Stmt\Echo_; 9use PhpParser\Node\Stmt\Expression; 10use Rector\Core\Rector\AbstractRector; 11use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; 12use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; 13 14/** 15 * Replace print calls with echo 16 */ 17class 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' 26print 'Hello World'; 27CODE_SAMPLE, 28 <<<'CODE_SAMPLE' 29echo 'Hello World'; 30CODE_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} 50