부터: 1.0.0
상속: extends PDepend\Source\AST\AbstractASTArtifact
예제 #1
0
 /**
  * Returns the source file where this method was declared.
  *
  * @return \PDepend\Source\AST\ASTCompilationUnit
  * @throws \PDepend\Source\AST\ASTCompilationUnitNotFoundException When no parent was set.
  * @since  0.10.0
  */
 public function getCompilationUnit()
 {
     if ($this->parent === null) {
         throw new ASTCompilationUnitNotFoundException($this);
     }
     return $this->parent->getCompilationUnit();
 }
예제 #2
0
 /**
  * Parses a class/interface/trait body.
  *
  * @param  \PDepend\Source\AST\AbstractASTType $type
  * @return \PDepend\Source\AST\AbstractASTType
  * @throws \PDepend\Source\Parser\UnexpectedTokenException
  * @throws \PDepend\Source\Parser\TokenStreamEndException
  */
 private function parseTypeBody(AbstractASTType $type)
 {
     $this->classOrInterface = $type;
     // Consume comments and read opening curly brace
     $this->consumeComments();
     $this->consumeToken(Tokens::T_CURLY_BRACE_OPEN);
     $defaultModifier = State::IS_PUBLIC;
     if ($type instanceof ASTInterface) {
         $defaultModifier |= State::IS_ABSTRACT;
     }
     $this->reset();
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== Tokenizer::T_EOF) {
         switch ($tokenType) {
             case Tokens::T_ABSTRACT:
             case Tokens::T_PUBLIC:
             case Tokens::T_PRIVATE:
             case Tokens::T_PROTECTED:
             case Tokens::T_STATIC:
             case Tokens::T_FINAL:
             case Tokens::T_FUNCTION:
             case Tokens::T_VARIABLE:
             case Tokens::T_VAR:
                 $methodOrProperty = $this->parseMethodOrFieldDeclaration($defaultModifier);
                 if ($methodOrProperty instanceof \PDepend\Source\AST\ASTNode) {
                     $type->addChild($methodOrProperty);
                 }
                 $this->reset();
                 break;
             case Tokens::T_CONST:
                 $type->addChild($this->parseConstantDefinition());
                 $this->reset();
                 break;
             case Tokens::T_CURLY_BRACE_CLOSE:
                 $this->consumeToken(Tokens::T_CURLY_BRACE_CLOSE);
                 $this->reset();
                 // Reset context class or interface instance
                 $this->classOrInterface = null;
                 // Stop processing
                 return $type;
             case Tokens::T_COMMENT:
                 $token = $this->consumeToken(Tokens::T_COMMENT);
                 $comment = $this->builder->buildAstComment($token->image);
                 $comment->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
                 $type->addChild($comment);
                 break;
             case Tokens::T_DOC_COMMENT:
                 $token = $this->consumeToken(Tokens::T_DOC_COMMENT);
                 $comment = $this->builder->buildAstComment($token->image);
                 $comment->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
                 $type->addChild($comment);
                 $this->docComment = $token->image;
                 break;
             case Tokens::T_USE:
                 $type->addChild($this->parseTraitUseStatement());
                 break;
             default:
                 throw new UnexpectedTokenException($this->tokenizer->next(), $this->tokenizer->getSourceFile());
         }
         $tokenType = $this->tokenizer->peek();
     }
     throw new TokenStreamEndException($this->tokenizer);
 }
예제 #3
0
 /**
  * Calculates the Weight Method Per Class metric.
  *
  * @param  \PDepend\Source\AST\AbstractASTType $type
  * @return integer[]
  * @since  1.0.6
  */
 private function calculateWmci(AbstractASTType $type)
 {
     $ccn = array();
     foreach ($type->getMethods() as $method) {
         $ccn[$method->getName()] = $this->cyclomaticAnalyzer->getCcn2($method);
     }
     return $ccn;
 }
 /**
  * The magic sleep method is called by the PHP runtime environment before an
  * instance of this class gets serialized. It returns an array with the
  * names of all those properties that should be cached for this class or
  * interface instance.
  *
  * @return array
  * @since  0.10.0
  */
 public function __sleep()
 {
     return array_merge(array('constants', 'interfaceReferences', 'parentClassReference'), parent::__sleep());
 }
예제 #5
0
 /**
  * This method will initialize a temporary coupling container for the given
  * given class or interface instance.
  *
  * @param  \PDepend\Source\AST\AbstractASTType $type
  * @return void
  * @since  0.10.2
  */
 private function initDependencyMap(AbstractASTType $type)
 {
     if (isset($this->dependencyMap[$type->getId()])) {
         return;
     }
     $this->dependencyMap[$type->getId()] = array('ce' => array(), 'ca' => array());
 }