/** * Creates a new Descriptor from the given Reflector. * * @param ParamTag $data * * @return ParamDescriptor */ public function create($data) { $descriptor = new ParamDescriptor($data->getName()); $descriptor->setDescription($data->getDescription()); $descriptor->setVariableName($data->getVariableName()); $descriptor->setTypes($data->getTypes()); return $descriptor; }
/** * Creates a new Descriptor from the given Reflector. * * @param ParamTag $data * * @return ParamDescriptor */ public function create($data) { $descriptor = new ParamDescriptor($data->getName()); $descriptor->setDescription($data->getDescription()); $descriptor->setVariableName($data->getVariableName()); /** @var Collection $types */ $types = $this->builder->buildDescriptor(new Collection($data->getTypes())); $descriptor->setTypes($types); return $descriptor; }
/** * @param FunctionParameter $functionParameter * @param DocBlock\Tag\ParamTag $docBlockParam * * @return bool */ public function equalTypes(FunctionParameter $functionParameter, DocBlock\Tag\ParamTag $docBlockParam) { $functionType = ltrim($functionParameter->type, '\\'); $docBlockType = ltrim($docBlockParam->getType(), '\\'); if ($functionType == $docBlockType) { return true; } $docBlockTypes = explode('|', $docBlockType); $primitiveTypes = ['string', 'int', 'integer', 'float', 'bool', 'boolean', 'null']; if (!$functionType and count(array_intersect($docBlockTypes, $primitiveTypes)) == count($docBlockTypes)) { return true; } if ($functionType === 'array' && substr($docBlockType, -2, 2) === '[]') { return true; } return false; }
/** * Checks the typehint of the argument versus the @param tag. * * If the argument has no typehint we do not check anything. When multiple * type are given then the typehint needs to be one of them. * * @param \phpDocumentor\Reflection\DocBlock\Tag\ParamTag $param * @param \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $argument * * @return bool whether an issue occurred */ protected function doesArgumentTypehintMatchParam(\phpDocumentor\Reflection\DocBlock\Tag\ParamTag $param, \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $argument) { if (!$argument->getType() || in_array($argument->getType(), $param->getTypes())) { return true; } $this->logParserError('ERROR', 50016, $this->lineNumber, array($argument->getName(), $this->entityName . '()')); return false; }
/** * Checks the typehint of the argument versus the @param tag. * * If the argument has no typehint we do not check anything. When multiple * type are given then the typehint needs to be one of them. * * @param ParamTag $param * @param ArgumentReflector $argument * * @return Error|null */ protected function doesArgumentTypehintMatchParam(ParamTag $param, ArgumentReflector $argument, $element) { if (!$argument->getType() || in_array($argument->getType(), $param->getTypes())) { return null; } elseif ($argument->getType() == 'array' && substr($param->getType(), -2) == '[]') { return null; } return new Error(LogLevel::ERROR, 'PPC:ERR-50016', $argument->getLinenumber(), array($argument->getName(), $element->getName())); }
/** * @param array $options * @param array $method * @param string $className * @param string $file * @param DocBlock\Tag\ParamTag $docBlockParam * * @return Issue */ public function createIssueForMissingTypeInDocBlock(array $options, array $method, $className, $file, DocBlock\Tag\ParamTag $docBlockParam) { $issue = new Issue($this->gadget, sprintf('Missing type for variable %s in docblock of "%s"', $docBlockParam->getName(), $className)); $issue->setLevel($options['missing_type_in_docblock']); $issue->setLine($method['startLine']); $issue->setFile($file); return $issue; }
protected function makePropertyNameFromTag(ParamTag $paramTag) { $name = $paramTag->getVariableName(); return ltrim($name, '$'); }