1*f9a94e78SAndreas Gohr<?php 2*f9a94e78SAndreas Gohr 3*f9a94e78SAndreas Gohrnamespace dokuwiki\test\rector; 4*f9a94e78SAndreas Gohr 5*f9a94e78SAndreas Gohruse PhpParser\Node; 6*f9a94e78SAndreas Gohruse PhpParser\Node\Expr\FuncCall; 7*f9a94e78SAndreas Gohruse PhpParser\Node\Stmt\Echo_; 8*f9a94e78SAndreas Gohruse PhpParser\Node\Stmt\Expression; 9*f9a94e78SAndreas Gohruse Rector\Core\Rector\AbstractRector; 10*f9a94e78SAndreas Gohruse Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; 11*f9a94e78SAndreas Gohruse Symplify\RuleDocGenerator\ValueObject\RuleDefinition; 12*f9a94e78SAndreas Gohr 13*f9a94e78SAndreas Gohr/** 14*f9a94e78SAndreas Gohr * Replace ptln() calls with echo 15*f9a94e78SAndreas Gohr */ 16*f9a94e78SAndreas Gohrclass DokuWikiPtlnRector extends AbstractRector 17*f9a94e78SAndreas Gohr{ 18*f9a94e78SAndreas Gohr 19*f9a94e78SAndreas Gohr /** @inheritdoc */ 20*f9a94e78SAndreas Gohr public function getRuleDefinition(): RuleDefinition 21*f9a94e78SAndreas Gohr { 22*f9a94e78SAndreas Gohr return new RuleDefinition('Replace ptln() calls with echo', [ 23*f9a94e78SAndreas Gohr new CodeSample( 24*f9a94e78SAndreas Gohr <<<'CODE_SAMPLE' 25*f9a94e78SAndreas Gohrptln('Hello World', 7); 26*f9a94e78SAndreas GohrCODE_SAMPLE, 27*f9a94e78SAndreas Gohr <<<'CODE_SAMPLE' 28*f9a94e78SAndreas Gohrecho 'Hello World'; 29*f9a94e78SAndreas GohrCODE_SAMPLE 30*f9a94e78SAndreas Gohr ), 31*f9a94e78SAndreas Gohr ]); 32*f9a94e78SAndreas Gohr } 33*f9a94e78SAndreas Gohr 34*f9a94e78SAndreas Gohr /** @inheritdoc */ 35*f9a94e78SAndreas Gohr public function getNodeTypes(): array 36*f9a94e78SAndreas Gohr { 37*f9a94e78SAndreas Gohr return [Expression::class]; 38*f9a94e78SAndreas Gohr } 39*f9a94e78SAndreas Gohr 40*f9a94e78SAndreas Gohr /** @inheritdoc */ 41*f9a94e78SAndreas Gohr public function refactor(Node $node) 42*f9a94e78SAndreas Gohr { 43*f9a94e78SAndreas Gohr if (!$node->expr instanceof FuncCall) { 44*f9a94e78SAndreas Gohr return null; 45*f9a94e78SAndreas Gohr } 46*f9a94e78SAndreas Gohr 47*f9a94e78SAndreas Gohr if (!$this->nodeNameResolver->isName($node->expr, 'ptln')) { 48*f9a94e78SAndreas Gohr return null; 49*f9a94e78SAndreas Gohr } 50*f9a94e78SAndreas Gohr 51*f9a94e78SAndreas Gohr return new Echo_([ 52*f9a94e78SAndreas Gohr $node->expr->args[0]->value 53*f9a94e78SAndreas Gohr ]); 54*f9a94e78SAndreas Gohr } 55*f9a94e78SAndreas Gohr} 56