Exemplo n.º 1
0
 public function make(MethodModel $methodModel, ParameterDataProvider $parameterDataProvider)
 {
     $optional = $parameterDataProvider->hasDefaultValue();
     $parameter = new ParameterModel($methodModel, $parameterDataProvider->getName(), $optional);
     $parameter->setTypeHint($parameterDataProvider->getTypeHint());
     if ($optional) {
         $parameter->setDefaultValue($parameterDataProvider->getDefaultValue());
     }
     return $parameter;
 }
 /**
  * Create constructor
  *
  * @param ClassModel $classModel
  */
 private function addConstructor(ClassModel $classModel)
 {
     $methodModel = new MethodModel($classModel, '__construct');
     $baseUrl = new ParameterModel($methodModel, 'baseUrl', false);
     $client = new ParameterModel($methodModel, 'client', false);
     $client->setTypeHint('\\Tebru\\Retrofit\\Adapter\\HttpClientAdapter');
     $serializer = new ParameterModel($methodModel, 'serializer', false);
     $serializer->setTypeHint('\\JMS\\Serializer\\SerializerInterface');
     $eventDispatcher = new ParameterModel($methodModel, 'eventDispatcher', false);
     $eventDispatcher->setTypeHint('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $methodModel->addParameter($baseUrl);
     $methodModel->addParameter($client);
     $methodModel->addParameter($serializer);
     $methodModel->addParameter($eventDispatcher);
     $methodBody = ['$this->baseUrl = $baseUrl;', '$this->client = $client;', '$this->serializer = $serializer;', '$this->eventDispatcher = $eventDispatcher;'];
     $methodModel->setBody(implode($methodBody));
     $classModel->addMethod($methodModel);
 }
 public function testIsCallbackOptional()
 {
     $method = new MethodModel(new ClassModel('Foo', 'FooClass', ApiClient::class), 'fooMethod');
     $parameter = new ParameterModel($method, 'callback', true);
     $parameter->setTypeHint('\\' . Callback::class);
     $method->addParameter($parameter);
     $collection = new AnnotationCollection();
     $provider = new AnnotationProvider($collection, $method);
     $callbackOptional = $provider->isCallbackOptional();
     $this->assertTrue($callbackOptional);
 }