2021-07-06 13:09:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
2021-07-06 13:09:53 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Param;
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
|
|
use PhpParser\Node\Stmt\Property;
|
|
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
|
|
|
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
|
2021-07-25 07:47:04 +00:00
|
|
|
final class AutowiredClassMethodOrPropertyAnalyzer
|
2021-07-06 13:09:53 +00:00
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-07-06 13:09:53 +00:00
|
|
|
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
|
|
|
*/
|
|
|
|
private $phpDocInfoFactory;
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-11-05 10:25:23 +00:00
|
|
|
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
|
2021-07-06 13:09:53 +00:00
|
|
|
*/
|
2021-11-05 10:25:23 +00:00
|
|
|
private $phpAttributeAnalyzer;
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer)
|
2021-07-06 13:09:53 +00:00
|
|
|
{
|
|
|
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
2021-11-05 10:25:23 +00:00
|
|
|
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
|
2021-07-06 13:09:53 +00:00
|
|
|
}
|
2021-07-25 07:47:04 +00:00
|
|
|
/**
|
2022-04-26 08:13:18 +00:00
|
|
|
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Param|\PhpParser\Node\Stmt\Property $node
|
2021-07-25 07:47:04 +00:00
|
|
|
*/
|
|
|
|
public function detect($node) : bool
|
2021-07-06 13:09:53 +00:00
|
|
|
{
|
2021-07-25 07:47:04 +00:00
|
|
|
$nodePhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
|
|
|
if ($nodePhpDocInfo->hasByNames(['required', 'inject'])) {
|
2021-07-06 13:09:53 +00:00
|
|
|
return \true;
|
|
|
|
}
|
2024-04-01 17:58:30 +00:00
|
|
|
return $this->phpAttributeAnalyzer->hasPhpAttributes($node, ['Symfony\\Contracts\\Service\\Attribute\\Required', 'Nette\\DI\\Attributes\\Inject']);
|
2021-07-06 13:09:53 +00:00
|
|
|
}
|
|
|
|
}
|