[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace dokuwiki\test\rector; 4 5 use PhpParser\Node; 6 use PhpParser\Node\Expr\FuncCall; 7 use PhpParser\Node\Stmt\Echo_; 8 use PhpParser\Node\Stmt\Expression; 9 use Rector\Core\Rector\AbstractRector; 10 use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; 11 use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; 12 13 /** 14 * Replace ptln() calls with echo 15 */ 16 class DokuWikiPtlnRector extends AbstractRector 17 { 18 19 /** @inheritdoc */ 20 public function getRuleDefinition(): RuleDefinition 21 { 22 return new RuleDefinition('Replace ptln() calls with echo', [ 23 new CodeSample( 24 <<<'CODE_SAMPLE' 25 ptln('Hello World', 7); 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 FuncCall) { 44 return null; 45 } 46 47 if (!$this->nodeNameResolver->isName($node->expr, 'ptln')) { 48 return null; 49 } 50 51 return new Echo_([ 52 $node->expr->args[0]->value 53 ]); 54 } 55 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body