/** * @param array $options * @param array $method * @param string $className * @param string $file * @param FunctionParameter $functionParameter * @param DocBlock\Tag\ParamTag $docBlockParam * * @return Issue */ public function createIssueForMismatchingTypes(array $options, array $method, $className, $file, FunctionParameter $functionParameter, DocBlock\Tag\ParamTag $docBlockParam) { $issue = new Issue($this->gadget, sprintf('"%s" variable %s has type %s in docblock', $className . ($className ? '::' : '') . $method['signature'], $functionParameter->name, $docBlockParam->getType())); $issue->setLevel($options['obsolete_variable']); $issue->setLine($method['startLine']); $issue->setFile($file); return $issue; }
/** * @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 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())); }
/** * 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; } elseif ($argument->getType() == 'array' && substr($param->getType(), -2) == '[]') { return true; } $this->logParserError('ERROR', 50016, $this->lineNumber, array($argument->getName(), $this->entityName . '()')); return false; }