Пример #1
0
 /**
  * @param Parameter $parameter
  *
  * @return array<integer,IStatement>
  */
 public function visitParameter(Parameter $parameter)
 {
     $this->typeCheck->visitParameter(func_get_args());
     $typeExpression = $parameter->type()->accept($this->typeGenerator());
     if (null === $typeExpression) {
         return array();
     }
     $expressions = array();
     if ($typeExpression instanceof Closure) {
         $checkVariable = new Variable(new Identifier('check'));
         $expressions[] = new ExpressionStatement(new Assign($checkVariable, $typeExpression));
         $conditionExpression = new Call($checkVariable);
         $conditionExpression->add($this->argumentExpression);
     } else {
         $conditionExpression = $typeExpression;
     }
     $newExceptionCall = new Call(QualifiedIdentifier::fromString($this->validatorNamespace()->joinAtoms('Exception', 'UnexpectedArgumentValueException')->string()));
     $newExceptionCall->add(new Literal($parameter->name()));
     $newExceptionCall->add($this->indexExpression);
     $newExceptionCall->add($this->argumentExpression);
     $newExceptionCall->add(new Literal($this->renderTypeName($parameter->type())));
     $ifStatement = new IfStatement(new LogicalNot($conditionExpression));
     $ifStatement->trueBranch()->add(new ThrowStatement(new NewOperator($newExceptionCall)));
     $expressions[] = $ifStatement;
     return $expressions;
 }
Пример #2
0
 /**
  * @param RuntimeConfiguration $configuration
  * @param ClassDefinition|null $classDefinition
  * @param MethodDefinition     $methodDefinition
  * @param Parameter            $documentedParameter
  * @param Parameter            $nativeParameter
  *
  * @return Parameter
  */
 protected function mergeParameter(RuntimeConfiguration $configuration, ClassDefinition $classDefinition = null, MethodDefinition $methodDefinition, Parameter $documentedParameter, Parameter $nativeParameter)
 {
     $this->typeCheck->mergeParameter(func_get_args());
     if ($documentedParameter->name() !== $nativeParameter->name()) {
         $this->handleError(new DocumentedParameterNameMismatch($classDefinition, $methodDefinition, $nativeParameter->name(), $documentedParameter->name()));
         return $nativeParameter;
     }
     if ($documentedParameter->isByReference() !== $nativeParameter->isByReference()) {
         $this->handleError(new DocumentedParameterByReferenceMismatch($classDefinition, $methodDefinition, $nativeParameter->name(), $nativeParameter->isByReference()));
     }
     return new Parameter($documentedParameter->name(), $this->mergeType($configuration, $classDefinition, $methodDefinition, $documentedParameter->name(), $documentedParameter->type(), $nativeParameter->type()), $documentedParameter->description(), $nativeParameter->isOptional(), $documentedParameter->isByReference());
 }
 /**
  * @param Parameter $parameter
  *
  * @return mixed
  */
 public function visitParameter(Parameter $parameter)
 {
     $this->typeCheck->visitParameter(func_get_args());
     return new Parameter($parameter->name(), $parameter->type()->accept($this->typeResolver()), $parameter->description(), $parameter->isOptional(), $parameter->isByReference());
 }