Pinq\Analysis\IExpressionAnalyser::createAnalysisContext PHP Method

createAnalysisContext() public method

Creates a new analysis context with the supplied evaluation context.
public createAnalysisContext ( Pinq\Expressions\IEvaluationContext $evaluationContext ) : Pinq\Analysis\IAnalysisContext
$evaluationContext Pinq\Expressions\IEvaluationContext
return Pinq\Analysis\IAnalysisContext
    public function createAnalysisContext(O\IEvaluationContext $evaluationContext);

Usage Example

 /**
  * @param callable $function
  * @param array    $variableTypeMap
  * @param mixed    $expression
  *
  * @return ITypeAnalysis
  */
 protected function getAnalysis(callable $function, array $variableTypeMap = [], &$expression = null)
 {
     $reflection = $this->functionInterpreter->getReflection($function);
     foreach ($reflection->getSignature()->getParameterExpressions() as $parameterExpression) {
         $variableTypeMap[$parameterExpression->getName()] = $this->typeSystem->getTypeFromTypeHint($parameterExpression->getTypeHint());
     }
     $analysisContext = $this->expressionAnalyser->createAnalysisContext($reflection->asEvaluationContext());
     foreach ($variableTypeMap as $variable => $type) {
         $analysisContext->setExpressionType(O\Expression::variable(O\Expression::value($variable)), $type);
     }
     $bodyExpressions = $this->functionInterpreter->getStructure($reflection)->getBodyExpressions();
     foreach ($bodyExpressions as $expression) {
         if ($expression instanceof O\ReturnExpression) {
             return $this->expressionAnalyser->analyse($analysisContext, $expression->getValue());
         } elseif (count($bodyExpressions) === 1) {
             return $this->expressionAnalyser->analyse($analysisContext, $expression);
         } else {
             $this->expressionAnalyser->analyse($analysisContext, $expression);
         }
     }
 }