19 declare(strict_types=1);
41 public const DIC =
'DIC';
42 public const THIS =
'this';
56 TypeProvidingExprFromClassResolver $typeProvidingExprFromClassResolver,
58 PropertyToAddCollector $propertyToAddCollector,
59 ClassInsertManipulator $classInsertManipulator,
60 NodesToAddCollector $nodesToAddCollector,
61 \Rector\Core\PhpParser\Node\NodeFactory $nodeFactory,
62 ConstructorClassMethodFactory $constructClassMethodFactory,
63 \Rector\Core\NodeDecorator\PropertyTypeDecorator $propertyTypeDecorator,
64 \Rector\ChangesReporting\Collector\RectorChangeCollector $rectorChangeCollector
67 $this->dicDependencyManipulator = $classDependencyManipulator;
85 ClassMethod $classMethod
86 ): \PhpParser\Node\Expr\Variable {
88 $dic_variable = $this->dicDependencyManipulator->ensureGlobalDICinMethod($classMethod, $class);
92 $property_assign =
new Expression(
94 $dic_dependenc_variable,
101 $this->dicDependencyManipulator->addStmtToMethodIfNotThereAfterGlobalDIC(
107 return $dic_dependenc_variable;
113 ClassMethod $classMethod
121 $classMethodName = $classMethod->name->name ?? null;
122 if ($classMethod->isStatic()
123 || $classMethodName === \Rector\Core\ValueObject\MethodName::CONSTRUCT) {
128 $primary = $DICMember->getMainClass();
129 $dicPropertyFetch = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass(
134 if ($dicPropertyFetch instanceof PropertyFetch) {
135 return $dicPropertyFetch;
139 $alternatives = $DICMember->getAlternativeClasses();
140 foreach ($alternatives as $alternative) {
141 $dicPropertyFetch = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass(
146 if ($dicPropertyFetch instanceof PropertyFetch) {
147 return $dicPropertyFetch;
152 $this->propertyToAddCollector->addPropertyWithoutConstructorToClass(
153 $DICMember->getPropertyName(),
158 $dicPropertyFetch =
new PropertyFetch(
159 new Variable(self::THIS),
160 $DICMember->getPropertyName()
165 new Variable(self::DIC)
168 $this->dicDependencyManipulator->ensureGlobalDICinConstructor(
172 $property_assign =
new Expression(
178 $this->dicDependencyManipulator->addStmtToConstructorIfNotThereAfterGlobalDIC(
183 return $dicPropertyFetch;
189 $methodCall =
new MethodCall(
204 return new ObjectType($name);
ConstructorClassMethodFactory $constructClassMethodFactory
Rector ChangesReporting Collector RectorChangeCollector $rectorChangeCollector
ClassInsertManipulator $classInsertManipulator
TypeProvidingExprFromClassResolver $typeProvidingExprFromClassResolver
Rector Core NodeDecorator PropertyTypeDecorator $propertyTypeDecorator
__construct(TypeProvidingExprFromClassResolver $typeProvidingExprFromClassResolver, DICDependencyManipulator $classDependencyManipulator, PropertyToAddCollector $propertyToAddCollector, ClassInsertManipulator $classInsertManipulator, NodesToAddCollector $nodesToAddCollector, \Rector\Core\PhpParser\Node\NodeFactory $nodeFactory, ConstructorClassMethodFactory $constructClassMethodFactory, \Rector\Core\NodeDecorator\PropertyTypeDecorator $propertyTypeDecorator, \Rector\ChangesReporting\Collector\RectorChangeCollector $rectorChangeCollector)
appendDICMethods(DICMember $m, Expr $methodCall)
NodesToAddCollector $nodesToAddCollector
Rector Core PhpParser Node NodeFactory $nodeFactory
PropertyToAddCollector $propertyToAddCollector
getObjectType(string $name)
ensureDICDependency(string $name, Class_ $class, ClassMethod $classMethod)
getStaticDICCall(DICMember $DICMember, Class_ $class, ClassMethod $classMethod)
DICMemberMap $DICMemberMap
DICDependencyManipulator $dicDependencyManipulator
getDICMemberByName(string $name)