mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-19 17:42:23 +00:00
extend AutowiredClassMethodAnalyzer with property
This commit is contained in:
parent
771a3390b0
commit
4456c4690b
|
@ -13,9 +13,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(WrapReturnRector::class)
|
||||
->call('configure', [[
|
||||
WrapReturnRector::TYPE_METHOD_WRAPS => ValueObjectInliner::inline([
|
||||
|
||||
new WrapReturn(SomeReturnClass::class, 'getItem', true),
|
||||
|
||||
]),
|
||||
]]);
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
|||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp72\PhpDoc\NativeParamToPhpDocDecorator;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\AutowiredClassMethodAnalyzer;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\AutowiredClassMethodOrPropertyAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
@ -49,7 +49,7 @@ final class DowngradeParameterTypeWideningRector extends AbstractRector implemen
|
|||
public function __construct(
|
||||
private NativeParamToPhpDocDecorator $nativeParamToPhpDocDecorator,
|
||||
private ReflectionProvider $reflectionProvider,
|
||||
private AutowiredClassMethodAnalyzer $autowiredClassMethodAnalyzer
|
||||
private AutowiredClassMethodOrPropertyAnalyzer $autowiredClassMethodAnalyzer
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use PHPStan\Type\ObjectType;
|
|||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\TypeDeclaration\Matcher\PropertyAssignMatcher;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\AutowiredClassMethodAnalyzer;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\AutowiredClassMethodOrPropertyAnalyzer;
|
||||
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
|
||||
final class ConstructorAssignDetector
|
||||
|
@ -29,7 +29,7 @@ final class ConstructorAssignDetector
|
|||
private NodeTypeResolver $nodeTypeResolver,
|
||||
private PropertyAssignMatcher $propertyAssignMatcher,
|
||||
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
|
||||
private AutowiredClassMethodAnalyzer $autowiredClassMethodAnalyzer
|
||||
private AutowiredClassMethodOrPropertyAnalyzer $autowiredClassMethodAnalyzer
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ declare(strict_types=1);
|
|||
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
|
||||
final class AutowiredClassMethodAnalyzer
|
||||
final class AutowiredClassMethodOrPropertyAnalyzer
|
||||
{
|
||||
public function __construct(
|
||||
private PhpDocInfoFactory $phpDocInfoFactory,
|
||||
|
@ -17,14 +18,14 @@ final class AutowiredClassMethodAnalyzer
|
|||
) {
|
||||
}
|
||||
|
||||
public function detect(ClassMethod $classMethod): bool
|
||||
public function detect(ClassMethod | Property $node): bool
|
||||
{
|
||||
$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
if ($classMethodPhpDocInfo->hasByNames(['required', 'inject'])) {
|
||||
$nodePhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
if ($nodePhpDocInfo->hasByNames(['required', 'inject'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($classMethod->attrGroups as $attrGroup) {
|
||||
foreach ($node->attrGroups as $attrGroup) {
|
||||
foreach ($attrGroup->attrs as $attribute) {
|
||||
if ($this->nodeNameResolver->isNames(
|
||||
$attribute->name,
|
Loading…
Reference in New Issue
Block a user