Ejemplo n.º 1
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()));
     }
 }
 /**
  * @param AbstractNode|MethodNode $node
  */
 public function apply(AbstractNode $node)
 {
     $meaninglessNames = $this->getStringProperty('meaninglessNames');
     $delimiter = $this->getStringProperty('delimiter');
     $methodName = $node->getImage();
     if (in_array(strtolower($methodName), explode($delimiter, strtolower($meaninglessNames)))) {
         $this->addViolation($node, [$methodName, $meaninglessNames]);
     }
 }
 /**
  * @param AbstractNode $methodPostfix
  *
  * @return bool
  */
 private function isMethodPostfixContainsNames(AbstractNode $methodPostfix)
 {
     foreach ($this->names as $name) {
         if (false !== strpos($methodPostfix->getImage(), $name)) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param AbstractNode|ClassNode $node
  */
 public function apply(AbstractNode $node)
 {
     $suffixes = $this->getStringProperty('suffixes');
     $generalSuffixes = explode($this->getStringProperty('delimiter'), $suffixes);
     foreach ($generalSuffixes as $generalSuffix) {
         if ($generalSuffix === substr($node->getImage(), strlen($generalSuffix) * -1)) {
             $this->addViolation($node, [$suffixes, $generalSuffix]);
             break;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * This method checks if a method/function has boolean flag arguments and warns about them.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('FormalParameter') as $param) {
         $declarator = $param->getFirstChildOfType('VariableDeclarator');
         $value = $declarator->getValue();
         if (false === $this->isBooleanValue($value)) {
             continue;
         }
         $this->addViolation($param, array($node->getImage(), $declarator->getImage()));
     }
 }
Ejemplo n.º 6
0
 /**
  * This method checks if a method/function uses an else expression and add a violation for each one found.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('ScopeStatement') as $scope) {
         $parent = $scope->getParent();
         if (false === $this->isIfOrElseIfStatement($parent)) {
             continue;
         }
         if (false === $this->isElseScope($scope, $parent)) {
             continue;
         }
         $this->addViolation($scope, array($node->getImage()));
     }
 }
 /**
  * @param AbstractNode|MethodNode $node
  */
 public function apply(AbstractNode $node)
 {
     $classReferences = $node->findChildrenOfType('ClassReference');
     if ('__construct' !== $node->getImage() || 0 === count($classReferences)) {
         return;
     }
     $allowedClassNames = explode($this->getStringProperty('delimiter'), $this->getStringProperty('allowedClassNames'));
     foreach ($classReferences as $classReference) {
         if (false === $this->containsClassName($classReference->getImage(), $allowedClassNames)) {
             $this->addViolation($classReference);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Checks if the given node was already processed.
  *
  * @param \PHPMD\AbstractNode $node
  * @return boolean
  */
 protected function isNotProcessed(AbstractNode $node)
 {
     return !isset($this->processedVariables[$node->getImage()]);
 }
Ejemplo n.º 9
0
 /**
  * AST puts namespace prefix to global functions called from a namespace.
  * This method checks if the last part of function fully qualified name is equal to $name
  *
  * @param \PHPMD\AbstractNode $node
  * @param string $name
  * @return boolean
  */
 protected function isFunctionNameEndingWith(AbstractNode $node, $name)
 {
     $parts = explode('\\', trim($node->getImage(), '\\'));
     return 0 === strcasecmp(array_pop($parts), $name);
 }