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