mirror of https://github.com/rectorphp/rector.git
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
|
|
|
use PhpParser\Node\Param;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use PhpParser\Node\Stmt\Property;
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
|
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
|
|
final class AutowiredClassMethodOrPropertyAnalyzer
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
|
*/
|
|
private $phpDocInfoFactory;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
|
|
*/
|
|
private $phpAttributeAnalyzer;
|
|
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer)
|
|
{
|
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
|
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
|
|
}
|
|
/**
|
|
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Param|\PhpParser\Node\Stmt\Property $node
|
|
*/
|
|
public function detect($node) : bool
|
|
{
|
|
$nodePhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
|
if ($nodePhpDocInfo->hasByNames(['required', 'inject'])) {
|
|
return \true;
|
|
}
|
|
return $this->phpAttributeAnalyzer->hasPhpAttributes($node, ['Symfony\\Contracts\\Service\\Attribute\\Required', 'Nette\\DI\\Attributes\\Inject']);
|
|
}
|
|
}
|