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.'));
     }
 }
Example #2
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 : ';');
 }
Example #3
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);
     }
 }