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.'));
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
 public function pStmt_ClassMethod(\PHPParser_Node_Stmt_ClassMethod $node)
 {
     $firstToken = '';
     $lastToken = '';
     if (count($node->params) > 0) {
         if ($node->getAttribute('startLine') != reset($node->params)->getAttribute('startLine')) {
             $firstToken = LF . $this->indentToken;
         }
         // if the last parameters endline is 2 lines above the first statements
         // startLine, the closing bracket is in a new line (except if there is a comment)
         if ($this->getFirstLineOfMoethodBody($node->stmts) - end($node->params)->getAttribute('endLine') > 1) {
             $lastToken = LF;
         }
     }
     return $this->pModifiers($node->type) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(' . $firstToken . $this->pParameterNodes($node->params) . $lastToken . ')' . (NULL !== $node->stmts ? ' {' . LF . $this->pStmts($node->stmts) . LF . '}' . LF : ';');
 }
 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.'));
     }
 }
예제 #5
0
 /**
  * @param \PHPParser_Node_Stmt_ClassMethod $node
  */
 private function processMethod(\PHPParser_Node_Stmt_ClassMethod $node)
 {
     /** @var $method \TheSeer\phpDox\Collector\MethodObject */
     $method = $this->unit->addMethod($node->name);
     $method->setStartLine($node->getAttribute('startLine'));
     $method->setEndLine($node->getAttribute('endLine'));
     $method->setAbstract($node->isAbstract());
     $method->setFinal($node->isFinal());
     $method->setStatic($node->isStatic());
     $visibility = 'public';
     if ($node->isPrivate()) {
         $visibility = 'private';
     } elseif ($node->isProtected()) {
         $visibility = 'protected';
     }
     $method->setVisibility($visibility);
     $docComment = $node->getDocComment();
     if ($docComment !== NULL) {
         $block = $this->dockblocParser->parse($docComment, $this->aliasMap);
         $method->setDocBlock($block);
     }
     $this->processMethodParams($method, $node->params);
     if ($node->stmts) {
         $this->processInlineComments($method, $node->stmts);
     }
 }
예제 #6
0
 public function buildClassMethodObjectFromNode(PHPParser_Node_Stmt_ClassMethod $methodNode)
 {
     $methodObject = new Tx_PhpParser_Domain_Model_Class_Method($methodNode->getName());
     $this->setPropertiesFromNode($methodNode, $methodObject);
     return $methodObject;
 }