/** * 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($this->builder->buildDescriptor($data->getType() ? new Collection(array($data->getType())) : new Collection())); foreach ($params as $paramDescriptor) { $this->overwriteTypeAndDescriptionFromParamTag($data, $paramDescriptor, $argumentDescriptor); } $argumentDescriptor->setDefault($data->getDefault()); $argumentDescriptor->setByReference($data->isByRef()); return $argumentDescriptor; }
/** * 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; }
/** * Creates a new Descriptor from the given Reflector. * * @param MethodTag $data * * @return MethodDescriptor */ public function create($data) { $descriptor = new MethodDescriptor($data->getName()); $descriptor->setDescription($data->getDescription()); $descriptor->setMethodName($data->getMethodName()); $response = new ReturnDescriptor('return'); $response->setTypes($data->getTypes()); $descriptor->setResponse($response); foreach ($data->getArguments() as $argument) { if (count($argument) > 1) { list($argumentType, $argumentName) = $argument; } else { $argumentName = current($argument); $argumentType = 'mixed'; } $argumentDescriptor = new ArgumentDescriptor(); $argumentDescriptor->setTypes(array($argumentType)); $argumentDescriptor->setName($argumentName); $descriptor->getArguments()->set($argumentName, $argumentDescriptor); } return $descriptor; }
/** * Checks if there is a variadic argument in the `@param` tags and adds it to the list of Arguments in * the Descriptor unless there is already one present. * * @param MethodReflector $data * @param MethodDescriptor $methodDescriptor * * @return void */ protected function addVariadicArgument($data, $methodDescriptor) { if (!$data->getDocBlock()) { return; } $paramTags = $data->getDocBlock()->getTagsByName('param'); /** @var ParamTag $lastParamTag */ $lastParamTag = end($paramTags); if (!$lastParamTag) { return; } if ($lastParamTag->isVariadic() && !in_array($lastParamTag->getVariableName(), array_keys($methodDescriptor->getArguments()->getAll()))) { $types = $this->builder->buildDescriptor(new Collection($lastParamTag->getTypes())); $argument = new ArgumentDescriptor(); $argument->setName($lastParamTag->getVariableName()); $argument->setTypes($types); $argument->setDescription($lastParamTag->getDescription()); $argument->setLine($methodDescriptor->getLine()); $argument->setVariadic(true); $methodDescriptor->getArguments()->set($argument->getName(), $argument); } }
/** * 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; }