Example #1
0
 /**
  * Returns the source file where this method was declared.
  *
  * @return PHP_Depend_Code_File
  * @throws PHP_Depend_Code_Exceptions_SourceNotFoundException When no parent
  *         class or interface was set for this method instance.
  * @since 0.10.0
  */
 public function getSourceFile()
 {
     if ($this->parent === null) {
         throw new PHP_Depend_Code_Exceptions_SourceNotFoundException($this);
     }
     return $this->parent->getSourceFile();
 }
 /**
  * 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());
 }
Example #3
0
 /**
  * Parses a class/interface/trait body.
  *
  * @param PHP_Depend_Code_AbstractType $type Context class, trait or interface
  *
  * @return PHP_Depend_Code_AbstractType
  */
 private function _parseTypeBody(PHP_Depend_Code_AbstractType $type)
 {
     $this->_classOrInterface = $type;
     // Consume comments and read opening curly brace
     $this->consumeComments();
     $this->consumeToken(self::T_CURLY_BRACE_OPEN);
     $defaultModifier = self::IS_PUBLIC;
     if ($type instanceof PHP_Depend_Code_Interface) {
         $defaultModifier |= self::IS_ABSTRACT;
     }
     $this->reset();
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== self::T_EOF) {
         switch ($tokenType) {
             case self::T_ABSTRACT:
             case self::T_PUBLIC:
             case self::T_PRIVATE:
             case self::T_PROTECTED:
             case self::T_STATIC:
             case self::T_FINAL:
             case self::T_FUNCTION:
             case self::T_VARIABLE:
             case self::T_VAR:
                 $methodOrProperty = $this->_parseMethodOrFieldDeclaration($defaultModifier);
                 if ($methodOrProperty instanceof PHP_Depend_Code_ASTNode) {
                     $type->addChild($methodOrProperty);
                 }
                 $this->reset();
                 break;
             case self::T_CONST:
                 $type->addChild($this->_parseConstantDefinition());
                 $this->reset();
                 break;
             case self::T_CURLY_BRACE_CLOSE:
                 $this->consumeToken(self::T_CURLY_BRACE_CLOSE);
                 $this->reset();
                 // Reset context class or interface instance
                 $this->_classOrInterface = null;
                 // Stop processing
                 return $type;
             case self::T_COMMENT:
                 $token = $this->consumeToken(self::T_COMMENT);
                 $comment = $this->builder->buildASTComment($token->image);
                 $comment->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
                 $type->addChild($comment);
                 break;
             case self::T_DOC_COMMENT:
                 $token = $this->consumeToken(self::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 self::T_USE:
                 $type->addChild($this->_parseTraitUseStatement());
                 break;
             default:
                 throw new PHP_Depend_Parser_UnexpectedTokenException($this->tokenizer->next(), $this->tokenizer->getSourceFile());
         }
         $tokenType = $this->tokenizer->peek();
     }
     throw new PHP_Depend_Parser_TokenStreamEndException($this->tokenizer);
 }
Example #4
0
 /**
  * This method will initialize a temporary coupling container for the given
  * given class or interface instance.
  *
  * @param PHP_Depend_Code_AbstractType $type The currently
  *        visited/traversed class or interface instance.
  *
  * @return void
  * @since 0.10.2
  */
 private function _initDependencyMap(PHP_Depend_Code_AbstractType $type)
 {
     if (isset($this->_dependencyMap[$type->getUUID()])) {
         return;
     }
     $this->_dependencyMap[$type->getUUID()] = array('ce' => array(), 'ca' => array());
 }
 /**
  * Constructs a new exception instance.
  *
  * @param PHP_Depend_Code_Method       $method The method that could not be
  *        applied to the given <b>$type</b>.
  * @param PHP_Depend_Code_AbstractType $type   The class or trait that cannot
  *        resolve the imported methods.
  */
 public function __construct(PHP_Depend_Code_Method $method, PHP_Depend_Code_AbstractType $type)
 {
     parent::__construct(sprintf('Trait method %s has not been applied, because there are ' . 'collisions with other trait methods on %s\\%s.', $method->getName(), preg_replace('(\\W+)', '\\', $type->getPackage()->getName()), $type->getName()));
 }
Example #6
0
 /**
  * Calculates the Weight Method Per Class metric.
  *
  * @param PHP_Depend_Code_AbstractType $type The context type instance.
  *
  * @return integer[]
  * @since 1.0.6
  */
 private function calculateWmci(PHP_Depend_Code_AbstractType $type)
 {
     $ccn = array();
     foreach ($type->getMethods() as $method) {
         $ccn[$method->getName()] = $this->cyclomaticAnalyzer->getCcn2($method);
     }
     return $ccn;
 }