mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 00:10:51 +00:00
740fedd8a5
74a7c51d38
[automated] Re-Generate Nodes/Rectors Documentation (#5664)
52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\NodeManipulator;
|
|
|
|
use PhpParser\Node\ComplexType;
|
|
use PhpParser\Node\Identifier;
|
|
use PhpParser\Node\Name;
|
|
use PhpParser\Node\Stmt\ClassConst;
|
|
use PhpParser\Node\Stmt\Property;
|
|
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
|
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
|
use Rector\StaticTypeMapper\StaticTypeMapper;
|
|
final class PropertyDecorator
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
|
*/
|
|
private $phpDocInfoFactory;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
|
*/
|
|
private $staticTypeMapper;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
|
*/
|
|
private $phpDocTypeChanger;
|
|
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, PhpDocTypeChanger $phpDocTypeChanger)
|
|
{
|
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
|
$this->staticTypeMapper = $staticTypeMapper;
|
|
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
|
}
|
|
/**
|
|
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassConst $property
|
|
* @param \PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|\PhpParser\Node\Name $typeNode
|
|
*/
|
|
public function decorateWithDocBlock($property, $typeNode) : void
|
|
{
|
|
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
|
if ($phpDocInfo->getVarTagValueNode() instanceof VarTagValueNode) {
|
|
return;
|
|
}
|
|
$newType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($typeNode);
|
|
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newType);
|
|
}
|
|
}
|