Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php declare (strict_types=1); namespace Rector\DowngradePhp81\Rector\FunctionLike; use..
Decoded Output download
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp81\Rector\FunctionLike;
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\NeverType;
use Rector\PhpDocDecorator\PhpDocFromTypeDeclarationDecorator;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/noreturn_type
*
* @see \Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector\DowngradeNeverTypeDeclarationRectorTest
*/
final class DowngradeNeverTypeDeclarationRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PhpDocDecorator\PhpDocFromTypeDeclarationDecorator
*/
private $phpDocFromTypeDeclarationDecorator;
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
{
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Function_::class, ClassMethod::class, Closure::class];
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove "never" return type, add a "@return never" tag instead', [new CodeSample(<<<'CODE_SAMPLE'
function someFunction(): never
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
/**
* @return never
*/
function someFunction()
{
}
CODE_SAMPLE
)]);
}
/**
* @param ClassMethod|Closure|Function_ $node
*/
public function refactor(Node $node) : ?Node
{
$neverType = new NeverType();
if (!$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, $neverType)) {
return null;
}
return $node;
}
}
?>
Did this file decode correctly?
Original Code
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp81\Rector\FunctionLike;
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\NeverType;
use Rector\PhpDocDecorator\PhpDocFromTypeDeclarationDecorator;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/noreturn_type
*
* @see \Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector\DowngradeNeverTypeDeclarationRectorTest
*/
final class DowngradeNeverTypeDeclarationRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\PhpDocDecorator\PhpDocFromTypeDeclarationDecorator
*/
private $phpDocFromTypeDeclarationDecorator;
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
{
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Function_::class, ClassMethod::class, Closure::class];
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove "never" return type, add a "@return never" tag instead', [new CodeSample(<<<'CODE_SAMPLE'
function someFunction(): never
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
/**
* @return never
*/
function someFunction()
{
}
CODE_SAMPLE
)]);
}
/**
* @param ClassMethod|Closure|Function_ $node
*/
public function refactor(Node $node) : ?Node
{
$neverType = new NeverType();
if (!$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, $neverType)) {
return null;
}
return $node;
}
}
Function Calls
| None |
Stats
| MD5 | c40bcb51cea30d9730c25d56d747a046 |
| Eval Count | 0 |
| Decode Time | 266 ms |