Example #1
0
 /**
  * Tests if the given variable node os part of an index expression.
  *
  * @param PHP_PMD_Node_ASTNode $node The variable to test.
  *
  * @return boolean
  */
 protected function isWrappedByIndexExpression(PHP_PMD_Node_ASTNode $node)
 {
     return $node->getParent()->isInstanceOf('ArrayIndexExpression') || $node->getParent()->isInstanceOf('StringIndexExpression');
 }
Example #2
0
 /**
  * This method checks that the given property postfix is accessed on an
  * instance or static reference to the given class.
  *
  * @param PHP_PMD_Node_Class   $class   The context class node instance.
  * @param PHP_PMD_Node_ASTNode $postfix The context property postfix node.
  *
  * @return boolean
  */
 protected function isInScopeOfClass(PHP_PMD_Node_Class $class, PHP_PMD_Node_ASTNode $postfix)
 {
     $owner = $postfix->getParent()->getChild(0);
     if ($owner->isInstanceOf('PropertyPostfix')) {
         $owner = $owner->getParent()->getParent()->getChild(0);
     }
     return $owner->isInstanceOf('SelfReference') || $owner->isInstanceOf('StaticReference') || strcasecmp($owner->getImage(), '$this') === 0 || strcasecmp($owner->getImage(), $class->getImage()) === 0;
 }
 /**
  * Stores the given variable node in an internal list of found variables.
  *
  * @param PHP_PMD_Node_ASTNode $node The context variable node.
  *
  * @return void
  */
 private function _collectVariable(PHP_PMD_Node_ASTNode $node)
 {
     if (!isset($this->_images[$node->getImage()])) {
         $this->_images[$node->getImage()] = array();
     }
     $this->_images[$node->getImage()][] = $node;
 }
Example #4
0
 /**
  * This method checks that the given method postfix is accessed on an
  * instance or static reference to the given class.
  *
  * @param PHP_PMD_Node_Class   $class   The context class node instance.
  * @param PHP_PMD_Node_ASTNode $postfix The context method postfix node.
  *
  * @return boolean
  */
 private function _isClassScope(PHP_PMD_Node_Class $class, PHP_PMD_Node_ASTNode $postfix)
 {
     $prefix = $postfix->getParent()->getChild(0);
     return $prefix->isInstanceOf('SelfReference') || $prefix->isInstanceOf('StaticReference') || strcasecmp($prefix->getImage(), '$this') === 0 || strcasecmp($prefix->getImage(), $class->getImage()) === 0;
 }
Example #5
0
 /**
  * testGetPackageNameReturnsNull
  *
  * @return void
  * @covers PHP_PMD_Node_ASTNode
  * @group phpmd
  * @group phpmd::node
  * @group unittest
  */
 public function testGetPackageNameReturnsNull()
 {
     $mock = $this->getMock('PHP_Depend_Code_ASTNode');
     $node = new PHP_PMD_Node_ASTNode($mock, __FILE__);
     $this->assertNull($node->getPackageName());
 }
Example #6
0
 /**
  * This method checks that the given method postfix is accessed on an
  * instance or static reference to the given class.
  *
  * @param PHP_PMD_Node_Class   $class   The context class node instance.
  * @param PHP_PMD_Node_ASTNode $postfix The context method postfix node.
  *
  * @return boolean
  */
 private function _isClassScope(PHP_PMD_Node_Class $class, PHP_PMD_Node_ASTNode $postfix)
 {
     $owner = $postfix->getParent()->getChild(0);
     if ($owner->isInstanceOf('MethodPostfix')) {
         $owner = $owner->getParent()->getParent()->getChild(0);
     }
     return $owner->isInstanceOf('SelfReference') || $owner->isInstanceOf('StaticReference') || strcasecmp($owner->getImage(), '$this') === 0 || strcasecmp($owner->getImage(), $class->getImage()) === 0;
 }
Example #7
0
 /**
  * testGetNamespaceNameReturnsNull
  *
  * @return void
  */
 public function testGetNamespaceNameReturnsNull()
 {
     $mock = $this->getMock('PDepend\\Source\\AST\\ASTNode');
     $node = new PHP_PMD_Node_ASTNode($mock, __FILE__);
     $this->assertNull($node->getNamespaceName());
 }
 /**
  * Stores the given literal node in an internal list of found variables.
  *
  * @param PHP_PMD_Node_ASTNode $node The context variable node.
  *
  * @return void
  */
 private function collectLiteral(PHP_PMD_Node_ASTNode $node)
 {
     $variable = '$' . trim($node->getImage(), '\'');
     if (!isset($this->images[$variable])) {
         $this->images[$variable] = array();
     }
     $this->images[$variable][] = $node;
 }