33declare (strict_types=1 );
44namespace Rector \DeadCode \Rector \Expression ;
55
6+ use PhpParser \Comment \Doc ;
67use PhpParser \Node ;
78use PhpParser \Node \Expr \PropertyFetch ;
89use PhpParser \Node \Expr \StaticPropertyFetch ;
910use PhpParser \Node \Stmt \Expression ;
1011use PhpParser \Node \Stmt \Nop ;
1112use PhpParser \NodeVisitor ;
1213use PHPStan \Reflection \Php \PhpPropertyReflection ;
13- use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1414use Rector \DeadCode \NodeManipulator \LivingCodeManipulator ;
1515use Rector \NodeAnalyzer \PropertyFetchAnalyzer ;
16- use Rector \NodeTypeResolver \Node \AttributeKey ;
1716use Rector \Rector \AbstractRector ;
1817use Rector \Reflection \ReflectionResolver ;
1918use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -35,16 +34,11 @@ final class RemoveDeadStmtRector extends AbstractRector
3534 * @readonly
3635 */
3736 private ReflectionResolver $ reflectionResolver ;
38- /**
39- * @readonly
40- */
41- private PhpDocInfoFactory $ phpDocInfoFactory ;
42- public function __construct (LivingCodeManipulator $ livingCodeManipulator , PropertyFetchAnalyzer $ propertyFetchAnalyzer , ReflectionResolver $ reflectionResolver , PhpDocInfoFactory $ phpDocInfoFactory )
37+ public function __construct (LivingCodeManipulator $ livingCodeManipulator , PropertyFetchAnalyzer $ propertyFetchAnalyzer , ReflectionResolver $ reflectionResolver )
4338 {
4439 $ this ->livingCodeManipulator = $ livingCodeManipulator ;
4540 $ this ->propertyFetchAnalyzer = $ propertyFetchAnalyzer ;
4641 $ this ->reflectionResolver = $ reflectionResolver ;
47- $ this ->phpDocInfoFactory = $ phpDocInfoFactory ;
4842 }
4943 public function getRuleDefinition (): RuleDefinition
5044 {
@@ -108,10 +102,9 @@ private function hasGetMagic(Expression $expression): bool
108102 */
109103 private function removeNodeAndKeepComments (Expression $ expression )
110104 {
111- $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ expression );
112- if ($ expression ->getComments () !== []) {
105+ if ($ expression ->getDocComment () instanceof Doc) {
113106 $ nop = new Nop ();
114- $ nop ->setAttribute (AttributeKey:: PHP_DOC_INFO , $ phpDocInfo );
107+ $ nop ->setDocComment ( $ expression -> getDocComment () );
115108 return $ nop ;
116109 }
117110 return NodeVisitor::REMOVE_NODE ;
0 commit comments