// A call expression like $foo = $this->get('bar');
//
if (s.getValue().getClass() == PHPCallExpression.class) {
PHPCallExpression exp = (PHPCallExpression) s.getValue();
// are we requesting a Service?
if (exp.getName().equals("get")) {
service = ModelUtils.extractServiceFromCall(exp, source.getScriptProject().getPath());
if (service != null) {
String fqsn = service.getNamespace() != null ? service.getNamespace().getQualifiedName() : null;
TemplateVariable tempVar= new TemplateVariable(currentMethod, var.getName(), exp.sourceStart(), exp.sourceEnd(), fqsn, service.getClassName());
deferredVariables.push(tempVar);
}
// a more complex expression like
// $form = $this->get('form.factory')->create(new ContactType());
} else if (exp.getReceiver().getClass() == PHPCallExpression.class) {
// try to extract a service if it's a Servicecontainer call
service = ModelUtils.extractServiceFromCall((PHPCallExpression) exp.getReceiver(), source.getScriptProject().getPath());
// nothing found, return
if (service == null || exp.getCallName() == null) {
return true;
}
SimpleReference callName = exp.getCallName();
//TODO: this is a problematic case, as during a clean build
// it's possible that the SourceModule in which the
// called method was declared is not yet in the index, so
// the return type cannot be evaluated and therefore
// the templatevariable won't be created...
//
// Possible solution: check if there's an event fired when the
// build is completed and store those return types in a global
// singleton, evaluate them when the whole build process is finished.
String fqsn = service.getNamespace() != null ? service.getNamespace().getQualifiedName() : null;
TemplateVariable tempVar = null;
tempVar = SymfonyModelAccess.getDefault()
.createTemplateVariableByReturnType(source, currentMethod, callName,
service.getClassName(), fqsn, var.getName(), cache);
if (tempVar != null) {
deferredVariables.push(tempVar);
}
// something like $formView = $form->createView();
} else if (exp.getReceiver().getClass() == VariableReference.class) {
VariableReference varRef = (VariableReference) exp.getReceiver();
SimpleReference ref = exp.getCallName();
// check for a previosly declared variable
for (TemplateVariable tempVar : deferredVariables) {
if (tempVar.getName().equals(varRef.getName())) {