private function checkUnusedMethod(NodeTraversal $t, \PHPParser_Node_Stmt_ClassMethod $node) { if ((\PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE & $node->type) === 0) { return; } $classType = $t->getScope()->getTypeOfThis()->restrictByNotNull(); if (($method = $classType->toMaybeObjectType()->getMethod($node->name)) && 0 === count($method->getInMethodCallSites())) { $this->phpFile->addComment($node->getLine(), Comment::warning('cleanup.unused_method', 'This method is unused, and could be removed.')); } }
protected function addMethod(\PHPParser_Node_Stmt_ClassMethod $node) { $method = new MethodReflection($node->name, $node->getLine()); $method->setModifiers((string) $node->type); if ($this->context->getFilter()->acceptMethod($method)) { $this->context->getClass()->addMethod($method); $method->setByRef((string) $node->byRef); foreach ($node->params as $param) { $parameter = new ParameterReflection($param->name, $param->getLine()); $parameter->setModifiers((string) $param->type); $parameter->setByRef($param->byRef); if ($param->default) { $parameter->setDefault($this->context->getPrettyPrinter()->prettyPrintExpr($param->default)); } if ((string) $param->type) { $parameter->setHint($this->resolveHint(array(array((string) $param->type, false)))); } $method->addParameter($parameter); } $comment = $this->context->getDocBlockParser()->parse($node->getDocComment(), $this->context, $method); $method->setDocComment($node->getDocComment()); $method->setShortDesc($comment->getShortDesc()); $method->setLongDesc($comment->getLongDesc()); if (!($errors = $comment->getErrors())) { $errors = $this->updateMethodParametersFromTags($method, $comment->getTag('param')); if ($tag = $comment->getTag('return')) { $method->setHint($this->resolveHint($tag[0][0])); $method->setHintDesc($tag[0][1]); } $method->setExceptions($comment->getTag('throws')); $method->setTags($comment->getOtherTags()); } $this->context->addErrors((string) $method, $node->getLine(), $errors); } }
private function handlePrivateMethod(\PHPParser_Node_Stmt_ClassMethod $methodNode) { if (!$this->getSetting('overriding_private_members')) { return; } $classNode = $methodNode->getAttribute('parent')->getAttribute('parent'); $class = $this->typeRegistry->getClassByNode($classNode); if (!$class->isClass()) { return; } if (null !== ($superClass = $class->getSuperClassType()) && null !== ($superClass = $superClass->toMaybeObjectType()) && $superClass->hasMethod($methodNode->name) && $superClass->getMethod($methodNode->name)->isPrivate()) { $this->phpFile->addComment($methodNode->getLine(), Comment::warning('suspicious_code.overriding_private_method', 'Consider using a different method name as you override a private method of the parent class.')); } }