/**
  * Creates a Descriptor from the provided data.
  *
  * @param ArgumentReflector $data
  * @param ParamDescriptor[] $params
  *
  * @return ArgumentDescriptor
  */
 public function create($data, $params = array())
 {
     $argumentDescriptor = new ArgumentDescriptor();
     $argumentDescriptor->setName($data->getName());
     $argumentDescriptor->setTypes($data->getType() ? array($data->getType()) : array());
     /** @var ParamDescriptor $tag */
     foreach ($params as $tag) {
         if ($tag->getVariableName() == $data->getName()) {
             $argumentDescriptor->setDescription($tag->getDescription());
             $types = $tag->getTypes() ?: array($data->getType() ?: 'mixed');
             $argumentDescriptor->setTypes($types);
         }
     }
     $argumentDescriptor->setDefault($data->getDefault());
     return $argumentDescriptor;
 }
 /**
  * @covers phpDocumentor\Descriptor\ArgumentDescriptor::getDefault
  * @covers phpDocumentor\Descriptor\ArgumentDescriptor::setDefault
  */
 public function testSetAndGetDefault()
 {
     $this->assertSame(null, $this->fixture->getDefault());
     $this->fixture->setDefault('a');
     $this->assertSame('a', $this->fixture->getDefault());
 }
 /**
  * Construct an argument descriptor given the array representing an argument with a Method Tag in the Reflection
  * component.
  *
  * @param string[] $argument
  *
  * @return ArgumentDescriptor
  */
 private function createArgumentDescriptorForMagicMethod($argument)
 {
     $argumentType = null;
     $argumentName = null;
     $argumentDefault = false;
     // false means we have not encountered the '=' yet.
     foreach ($argument as $part) {
         $part = trim($part);
         if (!$part) {
             continue;
         }
         if (!$argumentType && $part[0] != '$') {
             $argumentType = $part;
         } elseif (!$argumentName) {
             $argumentName = $part;
         } elseif ($argumentName && !$argumentType) {
             $argumentType = $part;
         } elseif ($part == '=') {
             $argumentDefault = null;
         } elseif ($argumentDefault === null) {
             $argumentDefault = $part;
         }
     }
     if ($argumentDefault === false) {
         $argumentDefault = null;
     }
     // if no name is set but a type is then the input is malformed and we correct for it
     if ($argumentType && !$argumentName) {
         $argumentName = $argumentType;
         $argumentType = null;
     }
     // if there is no type then we assume it is 'mixed'
     if (!$argumentType) {
         $argumentType = 'mixed';
     }
     $argumentDescriptor = new ArgumentDescriptor();
     $argumentDescriptor->setTypes($this->builder->buildDescriptor(new Collection(array($argumentType))));
     $argumentDescriptor->setName($argumentName[0] == '$' ? $argumentName : '$' . $argumentName);
     $argumentDescriptor->setDefault($argumentDefault);
     return $argumentDescriptor;
 }