typeProvidingExprFromClassResolver = $typeProvidingExprFromClassResolver; $this->propertyNaming = $propertyNaming; $this->nodeNameResolver = $nodeNameResolver; $this->nodeFactory = $nodeFactory; $this->propertyFetchFactory = $propertyFetchFactory; $this->classDependencyManipulator = $classDependencyManipulator; } /** * @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\PropertyFetch|\PhpParser\Node\Expr\Variable */ public function matchTypeProvidingExpr(Class_ $class, ClassMethod $classMethod, ObjectType $objectType) { $expr = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass($class, $classMethod, $objectType); if ($expr instanceof Expr) { if ($expr instanceof Variable) { $this->addClassMethodParamForVariable($expr, $objectType, $classMethod); } return $expr; } $propertyName = $this->propertyNaming->fqnToVariableName($objectType); $this->classDependencyManipulator->addConstructorDependency($class, new PropertyMetadata($propertyName, $objectType)); return $this->propertyFetchFactory->createFromType($objectType); } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike */ private function addClassMethodParamForVariable(Variable $variable, ObjectType $objectType, $functionLike) : void { /** @var string $variableName */ $variableName = $this->nodeNameResolver->getName($variable); // add variable to __construct as dependency $functionLike->params[] = $this->nodeFactory->createParamFromNameAndType($variableName, $objectType); } }