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\CodeQuality\Rector\FuncCall; use PhpPar..
Decoded Output download
<?php
declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\FuncCall;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector\BoolvalToTypeCastRectorTest
*/
final class BoolvalToTypeCastRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change boolval() to faster and readable (bool) $value', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
{
return boolval($value);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
{
return (bool) $value;
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node) : ?Node
{
if ($node->isFirstClassCallable()) {
return null;
}
if (!$this->isName($node, 'boolval')) {
return null;
}
if (!isset($node->getArgs()[0])) {
return null;
}
return new Bool_($node->getArgs()[0]->value);
}
}
?>
Did this file decode correctly?
Original Code
<?php
declare (strict_types=1);
namespace Rector\CodeQuality\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\FuncCall;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector\BoolvalToTypeCastRectorTest
*/
final class BoolvalToTypeCastRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change boolval() to faster and readable (bool) $value', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
{
return boolval($value);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
{
return (bool) $value;
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node) : ?Node
{
if ($node->isFirstClassCallable()) {
return null;
}
if (!$this->isName($node, 'boolval')) {
return null;
}
if (!isset($node->getArgs()[0])) {
return null;
}
return new Bool_($node->getArgs()[0]->value);
}
}
Function Calls
None |
Stats
MD5 | 0048f0ca7789a6b30d0065c230965e74 |
Eval Count | 0 |
Decode Time | 117 ms |