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\Doctrine\NodeManipulator; use PhpParser..
Decoded Output download
<?php
declare (strict_types=1);
namespace Rector\Doctrine\NodeManipulator;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\NodeManipulator\ClassInsertManipulator;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\NodeFactory;
use Rector\ValueObject\MethodName;
final class ConstructorManipulator
{
/**
* @readonly
* @var \Rector\PhpParser\Node\NodeFactory
*/
private $nodeFactory;
/**
* @readonly
* @var \Rector\NodeManipulator\ClassInsertManipulator
*/
private $classInsertManipulator;
public function __construct(NodeFactory $nodeFactory, ClassInsertManipulator $classInsertManipulator)
{
$this->nodeFactory = $nodeFactory;
$this->classInsertManipulator = $classInsertManipulator;
}
public function addStmtToConstructor(Class_ $class, Expression $newExpression) : void
{
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
if ($constructClassMethod instanceof ClassMethod) {
$constructClassMethod->stmts[] = $newExpression;
} else {
$constructClassMethod = $this->nodeFactory->createPublicMethod(MethodName::CONSTRUCT);
$constructClassMethod->stmts[] = $newExpression;
$this->classInsertManipulator->addAsFirstMethod($class, $constructClassMethod);
$class->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}
}
?>
Did this file decode correctly?
Original Code
<?php
declare (strict_types=1);
namespace Rector\Doctrine\NodeManipulator;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\NodeManipulator\ClassInsertManipulator;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\NodeFactory;
use Rector\ValueObject\MethodName;
final class ConstructorManipulator
{
/**
* @readonly
* @var \Rector\PhpParser\Node\NodeFactory
*/
private $nodeFactory;
/**
* @readonly
* @var \Rector\NodeManipulator\ClassInsertManipulator
*/
private $classInsertManipulator;
public function __construct(NodeFactory $nodeFactory, ClassInsertManipulator $classInsertManipulator)
{
$this->nodeFactory = $nodeFactory;
$this->classInsertManipulator = $classInsertManipulator;
}
public function addStmtToConstructor(Class_ $class, Expression $newExpression) : void
{
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
if ($constructClassMethod instanceof ClassMethod) {
$constructClassMethod->stmts[] = $newExpression;
} else {
$constructClassMethod = $this->nodeFactory->createPublicMethod(MethodName::CONSTRUCT);
$constructClassMethod->stmts[] = $newExpression;
$this->classInsertManipulator->addAsFirstMethod($class, $constructClassMethod);
$class->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}
}
Function Calls
None |
Stats
MD5 | ae4629cc0b52b27b67d3c0648af63065 |
Eval Count | 0 |
Decode Time | 435 ms |