Merge pull request #806 from rectorphp/compat-fix

Compat fix
This commit is contained in:
Tomáš Votruba 2018-12-03 19:59:25 +01:00 committed by GitHub
commit e05ccbef70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 12 deletions

View File

@ -13,8 +13,7 @@ new class {
namespace Rector\Php\Tests\Rector\ClassMethod\ParamAndReturnScalarTypehintsRector\Integration\AnonClass;
new class
{
new class {
/** @param int $a */
public function test(int $a) {}
};

View File

@ -35,7 +35,7 @@ final class TolerantRectorYamlFileLoader extends AbstractParameterMergingYamlFil
/**
* @param string $file
* @return array|mixed|mixed[]
* @return mixed|mixed[]
*/
protected function loadFile($file)
{

View File

@ -93,12 +93,12 @@ final class NodeAddingCommander implements CommanderInterface
private function createNodeVisitor(): NodeVisitor
{
return new class($this->nodesToAdd) extends NodeVisitorAbstract
{
return new class($this->nodesToAdd) extends NodeVisitorAbstract {
/**
* @var Stmt[][]
*/
private $nodesToAdd = [];
/**
* @param Stmt[][] $nodesToAdd
*/
@ -106,6 +106,7 @@ final class NodeAddingCommander implements CommanderInterface
{
$this->nodesToAdd = $nodesToAdd;
}
/**
* @return Node[]|Node|null
*/

View File

@ -51,12 +51,12 @@ final class NodeRemovingCommander implements CommanderInterface
private function createNodeVisitor(): NodeVisitor
{
return new class($this->nodesToRemove) extends NodeVisitorAbstract
{
return new class($this->nodesToRemove) extends NodeVisitorAbstract {
/**
* @var Stmt[]
*/
private $nodesToRemove = [];
/**
* @param Stmt[] $nodesToRemove
*/
@ -64,6 +64,7 @@ final class NodeRemovingCommander implements CommanderInterface
{
$this->nodesToRemove = $nodesToRemove;
}
/**
* @return int|Node|Node[]|null
*/

View File

@ -58,16 +58,17 @@ final class PropertyAddingCommander implements CommanderInterface
private function createNodeVisitor(): NodeVisitor
{
return new class($this->classMaintainer, $this->propertiesByClass) extends NodeVisitorAbstract
{
return new class($this->classMaintainer, $this->propertiesByClass) extends NodeVisitorAbstract {
/**
* @var ClassMaintainer
*/
private $classMaintainer;
/**
* @var VariableInfo[][]
*/
private $propertiesByClass = [];
/**
* @param VariableInfo[][] $propertiesByClass
*/
@ -76,6 +77,7 @@ final class PropertyAddingCommander implements CommanderInterface
$this->classMaintainer = $classMaintainer;
$this->propertiesByClass = $propertiesByClass;
}
public function enterNode(Node $node): ?Node
{
if (! $node instanceof Class_ || $node->isAnonymous()) {
@ -84,6 +86,7 @@ final class PropertyAddingCommander implements CommanderInterface
return $this->processClassNode($node);
}
private function processClassNode(Class_ $classNode): Class_
{
$variableInfos = $this->propertiesByClass[spl_object_hash($classNode)] ?? [];

View File

@ -23,16 +23,17 @@ final class CallableNodeTraverser
private function createNodeVisitor(callable $callable): NodeVisitor
{
return new class($callable) extends NodeVisitorAbstract
{
return new class($callable) extends NodeVisitorAbstract {
/**
* @var callable
*/
private $callable;
public function __construct(callable $callable)
{
$this->callable = $callable;
}
/**
* @return int|Node|null
*/

View File

@ -149,7 +149,11 @@ final class BetterStandardPrinter extends Standard
if ($node->class->name instanceof Identifier) {
$className = $node->class->name->toString();
if (Strings::startsWith($className, 'AnonymousClass')) {
$node->setAttribute(Attribute::ORIGINAL_NODE, null);
/** @var Class_ $originalNode */
$originalNode = $node->class->getAttribute(Attribute::ORIGINAL_NODE);
$originalNode->name = null;
$node->class->setAttribute(Attribute::ORIGINAL_NODE, $originalNode);
$node->class->name = null;
}
}