示例#1
0
 private function _countCalls(PHP_Depend_Code_AbstractCallable $callable)
 {
     $callT = [\PDepend\Source\Tokenizer\Tokens::T_STRING, \PDepend\Source\Tokenizer\Tokens::T_VARIABLE];
     $chainT = [\PDepend\Source\Tokenizer\Tokens::T_DOUBLE_COLON, \PDepend\Source\Tokenizer\Tokens::T_OBJECT_OPERATOR];
     $called = [];
     $tokens = $callable->getTokens();
     $count = count($tokens);
     for ($i = 0; $i < $count; ++$i) {
         // break on function body open
         if ($tokens[$i]->type === \PDepend\Source\Tokenizer\Tokens::T_CURLY_BRACE_OPEN) {
             break;
         }
     }
     for (; $i < $count; ++$i) {
         // Skip non parenthesis tokens
         if ($tokens[$i]->type !== \PDepend\Source\Tokenizer\Tokens::T_PARENTHESIS_OPEN) {
             continue;
         }
         // Skip first token
         if (!isset($tokens[$i - 1]) || !in_array($tokens[$i - 1]->type, $callT)) {
             continue;
         }
         // Count if no other token exists
         if (!isset($tokens[$i - 2]) && !isset($called[$tokens[$i - 1]->image])) {
             $called[$tokens[$i - 1]->image] = true;
             ++$this->_calls;
             continue;
         } else {
             if (in_array($tokens[$i - 2]->type, $chainT)) {
                 $identifier = $tokens[$i - 2]->image . $tokens[$i - 1]->image;
                 for ($j = $i - 3; $j >= 0; --$j) {
                     if (!in_array($tokens[$j]->type, $callT) && !in_array($tokens[$j]->type, $chainT)) {
                         break;
                     }
                     $identifier = $tokens[$j]->image . $identifier;
                 }
                 if (!isset($called[$identifier])) {
                     $called[$identifier] = true;
                     ++$this->_calls;
                 }
             } else {
                 if ($tokens[$i - 2]->type !== \PDepend\Source\Tokenizer\Tokens::T_NEW && !isset($called[$tokens[$i - 1]->image])) {
                     $called[$tokens[$i - 1]->image] = true;
                     ++$this->_calls;
                 }
             }
         }
     }
 }
示例#2
0
 private function _countCalls(PHP_Depend_Code_AbstractCallable $callable)
 {
     $called = [];
     $tokens = $callable->getTokens();
     $count = count($tokens);
     for ($i = $this->_findOpenCurlyBrace($tokens); $i < $count; ++$i) {
         if ($this->_isCallableOpenParenthesis($tokens, $i) === false) {
             continue;
         }
         if ($this->_isMethodInvocation($tokens, $i) === true) {
             $image = $this->_getInvocationChainImage($tokens, $i);
         } else {
             if ($this->_isFunctionInvocation($tokens, $i) === true) {
                 $image = $tokens[$i - 1]->image;
             } else {
                 $image = null;
             }
         }
         if ($image !== null) {
             $called[$image] = $image;
         }
     }
     $this->_calls += count($called);
 }
示例#3
0
 /**
  * The magic sleep method will be called by the PHP engine when this class
  * gets serialized. It returns an array with those properties that should be
  * cached for all function instances.
  *
  * @return array(string)
  * @since 0.10.0
  */
 public function __sleep()
 {
     return array_merge(array('context', 'packageName'), parent::__sleep());
 }
示例#4
0
文件: Analyzer.php 项目: kingsj/core
 /**
  * This method will calculate the NPath complexity for the given callable
  * instance.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The context callable.
  *
  * @return void
  * @since 0.9.12
  */
 protected function calculateComplexity(PHP_Depend_Code_AbstractCallable $callable)
 {
     $npath = '1';
     foreach ($callable->getChildren() as $child) {
         $stmt = $child->accept($this, $npath);
         $npath = PHP_Depend_Util_MathUtil::mul($npath, $stmt);
     }
     $this->_metrics[$callable->getUUID()] = $npath;
 }
示例#5
0
 /**
  * The magic sleep method will be called by the PHP engine when this class
  * gets serialized. It returns an array with those properties that should be
  * cached for method instances.
  *
  * @return array(string)
  * @since 0.10.0
  */
 public function __sleep()
 {
     return array_merge(array('modifiers'), parent::__sleep());
 }
示例#6
0
文件: Analyzer.php 项目: kingsj/core
 /**
  * Visits the given callable instance.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The context callable.
  *
  * @return void
  */
 private function _visitCallable(PHP_Depend_Code_AbstractCallable $callable)
 {
     $this->_metrics[$callable->getUUID()] = array(self::M_CRAP_INDEX => $this->_calculateCrapIndex($callable));
 }
示例#7
0
 /**
  * This method will return the class where the parent method was declared.
  * The returned value will be <b>null</b> if the parent is a function.
  *
  * @return PHP_Depend_Code_AbstractClassOrInterface
  * @since 0.9.5
  */
 public function getDeclaringClass()
 {
     // TODO: Review this for refactoring, maybe create a empty getParent()?
     if ($this->_declaringFunction instanceof PHP_Depend_Code_Method) {
         return $this->_declaringFunction->getParent();
     }
     return null;
 }
示例#8
0
文件: Parser.php 项目: rouffj/pdepend
 /**
  * Extracts documented <b>throws</b> and <b>return</b> types and sets them
  * to the given <b>$callable</b> instance.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The context callable.
  *
  * @return void
  */
 private function _prepareCallable(PHP_Depend_Code_AbstractCallable $callable)
 {
     // Skip, if ignore annotations is set
     if ($this->_ignoreAnnotations === true) {
         return;
     }
     // Get all @throws Types
     $throws = $this->_parseThrowsAnnotations($callable->getDocComment());
     foreach ($throws as $qualifiedName) {
         $callable->addExceptionClassReference($this->builder->buildASTClassOrInterfaceReference($qualifiedName));
     }
     // Get return annotation
     $qualifiedName = $this->_parseReturnAnnotation($callable->getDocComment());
     if ($qualifiedName !== null) {
         $callable->setReturnClassReference($this->builder->buildASTClassOrInterfaceReference($qualifiedName));
     }
 }
示例#9
0
 /**
  * Constructs a new closure instance.
  */
 public function __construct()
 {
     parent::__construct('#closure');
 }
示例#10
0
 /**
  * This method can be called by the PHP_Depend runtime environment or a
  * utilizing component to free up memory. This methods are required for
  * PHP version < 5.3 where cyclic references can not be resolved
  * automatically by PHP's garbage collector.
  *
  * @return void
  * @since 0.9.12
  */
 public function free()
 {
     parent::free();
     $this->_removeReferenceToParentClass();
 }
示例#11
0
 /**
  * Calculates the NPath complexity for the given callable instance.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The context callable.
  *
  * @return string
  * @since 0.9.12
  */
 private function _calculateNPathComplexity(PHP_Depend_Code_AbstractCallable $callable)
 {
     $analyzer = new PHP_Depend_Metrics_NPathComplexity_Analyzer();
     $callable->accept($analyzer);
     $metrics = $analyzer->getNodeMetrics($callable);
     return $metrics['npath'];
 }
示例#12
0
 /**
  * Visits methods, functions or closures and calculated their complexity.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The visited callable.
  *
  * @return void
  * @since 0.9.8
  */
 public function calculateComplexity(PHP_Depend_Code_AbstractCallable $callable)
 {
     $data = array(self::M_CYCLOMATIC_COMPLEXITY_1 => 1, self::M_CYCLOMATIC_COMPLEXITY_2 => 1);
     foreach ($callable->getChildren() as $child) {
         $data = $child->accept($this, $data);
     }
     $this->_storeNodeComplexityAndUpdateProject($callable->getUUID(), $data);
 }
示例#13
0
 /**
  * Counts all calls within the given <b>$callable</b>
  *
  * @param PHP_Depend_Code_AbstractCallable $callable Context callable.
  *
  * @return void
  */
 private function _countCalls(PHP_Depend_Code_AbstractCallable $callable)
 {
     $invocations = $callable->findChildrenOfType(PHP_Depend_Code_ASTInvocation::CLAZZ);
     $invoked = array();
     foreach ($invocations as $invocation) {
         $parents = $invocation->getParentsOfType(PHP_Depend_Code_ASTMemberPrimaryPrefix::CLAZZ);
         $image = '';
         foreach ($parents as $parent) {
             $child = $parent->getChild(0);
             if ($child !== $invocation) {
                 $image .= $child->getImage() . '.';
             }
         }
         $image .= $invocation->getImage() . '()';
         $invoked[$image] = $image;
     }
     $this->_calls += count($invoked);
 }
示例#14
0
文件: Function.php 项目: kingsj/core
 /**
  * The magic wakeup method will be called by PHP's runtime environment when
  * a serialized instance of this class was unserialized. This implementation
  * of the wakeup method will register this object in the the global function
  * context.
  *
  * @return void
  * @since 0.10.0
  */
 public function __wakeup()
 {
     parent::__wakeup();
     $this->context->registerFunction($this);
 }
示例#15
0
 /**
  * Visits methods, functions or closures and calculated their complexity.
  *
  * @param PHP_Depend_Code_AbstractCallable $callable The visited callable.
  *
  * @return void
  * @since 0.9.8
  */
 public function calculateComplexity(PHP_Depend_Code_AbstractCallable $callable)
 {
     $data = array(self::M_CYCLOMATIC_COMPLEXITY_1 => 1, self::M_CYCLOMATIC_COMPLEXITY_2 => 1);
     foreach ($callable->getChildren() as $child) {
         $data = $child->accept($this, $data);
     }
     $this->metrics[$callable->getUuid()] = $data;
 }