/**
  * Is method has the same name as the enclosing class
  * (php4 style constructor).
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     if ($node->getNode()->getParent() instanceof ASTTrait) {
         return;
     }
     if (strcasecmp($node->getName(), $node->getParentName()) !== 0) {
         return;
     }
     $this->addViolation($node);
 }
Ejemplo n.º 2
0
 /**
  * This method checks if a given function or method contains an eval-expression
  * and emits a rule violation when it exists.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('FunctionPostfix') as $postfix) {
         $image = strtolower($postfix->getImage());
         if (false === in_array($image, $this->getSuspectImages())) {
             continue;
         }
         $image = $node->getImage();
         if ($node instanceof MethodNode) {
             $image = sprintf('%s::%s', $node->getParentName(), $node->getImage());
         }
         $this->addViolation($postfix, array($node->getType(), $image, $postfix->getImage()));
     }
 }
Ejemplo n.º 3
0
 /**
  * Constructs a new rule violation instance.
  *
  * @param \PHPMD\Rule $rule
  * @param \PHPMD\AbstractNode $node
  * @param string $violationMessage
  * @param mixed $metric
  */
 public function __construct(Rule $rule, AbstractNode $node, $violationMessage, $metric = null)
 {
     $this->rule = $rule;
     $this->node = $node;
     $this->metric = $metric;
     $this->description = $violationMessage;
     if ($node instanceof AbstractTypeNode) {
         $this->className = $node->getName();
     } elseif ($node instanceof MethodNode) {
         $this->className = $node->getParentName();
         $this->methodName = $node->getName();
     } elseif ($node instanceof FunctionNode) {
         $this->functionName = $node->getName();
     }
 }