Exemplo n.º 1
0
 /**
  * Extracts all variable and variable declarator nodes from the given node
  * and checks the variable name length against the configured minimum
  * length.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     $threshold = $this->getIntProperty('minimum');
     if ($threshold <= strlen($node->getName())) {
         return;
     }
     $exceptions = $this->getExceptionsList();
     if (in_array($node->getName(), $exceptions)) {
         return;
     }
     $this->addViolation($node, array($node->getParentName(), $node->getName(), $threshold));
 }
 public function apply(AbstractNode $node)
 {
     $filename = $node->getFileName();
     $base = basename($filename, '.php');
     if (!preg_match('/^(SS_)?' . $base . '(_[A-Z][a-zA-Z0-9]+)?$/', $node->getName())) {
         $this->addViolation($node, array($node->getName(), basename($filename)));
     }
 }
 /**
  * This method checks if a method is not named in camelCase
  * and emits a rule violation.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     $methodName = $node->getName();
     if (!in_array($methodName, $this->ignoredMethods)) {
         if (!$this->isValid($methodName)) {
             $this->addViolation($node, array($methodName));
         }
     }
 }
 /**
  * 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);
 }
 /**
  * This method checks if a method is not named in camelCase
  * and emits a rule violation.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     $methodName = $node->getName();
     if (!in_array($methodName, $this->ignoredMethods)) {
         $pattern = '/^[a-z][a-zA-Z0-9]*$/';
         $allowUnderscore = $this->getBooleanProperty('allow-underscore');
         if ($allowUnderscore == true) {
             $pattern = '/^[_]?[a-z][a-zA-Z0-9]*$/';
         }
         if (!preg_match($pattern, $methodName)) {
             $this->addViolation($node, array($methodName));
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Method checks for use of static access and warns about it.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     $exceptions = $this->getExceptionsList();
     $nodes = $node->findChildrenOfType('MemberPrimaryPrefix');
     foreach ($nodes as $methodCall) {
         if (!$this->isStaticMethodCall($methodCall)) {
             continue;
         }
         $className = $methodCall->getChild(0)->getNode()->getImage();
         if (in_array($className, $exceptions)) {
             continue;
         }
         $this->addViolation($methodCall, array($className, $node->getName()));
     }
 }
Exemplo n.º 7
0
 /**
  * This method checks if a class is not named in CamelCase
  * and emits a rule violation.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     if (!preg_match('/^[A-Z][a-zA-Z0-9]*$/', $node->getName())) {
         $this->addViolation($node, array($node->getName()));
     }
 }
Exemplo n.º 8
0
 /**
  * Returns <b>true</b> when the given node is a magic method signature
  * @param AbstractNode $node
  * @return boolean
  */
 private function isMagicMethod(AbstractNode $node)
 {
     static $names = array('call', 'callStatic', 'get', 'set', 'isset', 'unset', 'set_state');
     if ($node instanceof MethodNode) {
         return preg_match('/\\__(?:' . implode("|", $names) . ')/i', $node->getName());
     }
     return false;
 }
Exemplo n.º 9
0
 /**
  * @param AbstractNode|AbstractASTArtifact $node
  *
  * @return float
  */
 private function calculateNameToCommentSimilarityInPercent($node)
 {
     $docComment = $node->getDocComment();
     if (empty($docComment)) {
         return 0;
     }
     similar_text($this->transformString($node->getName()), $this->getCommentDescription($docComment), $percent);
     return round($percent);
 }
Exemplo n.º 10
0
 /**
  * This method should implement the violation analysis algorithm of concrete
  * rule implementations. All extending classes must implement this method.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('GotoStatement') as $goto) {
         $this->addViolation($goto, array($node->getType(), $node->getName()));
     }
 }
Exemplo n.º 11
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();
     }
 }
Exemplo n.º 12
0
 /**
  * This method checks if a given function or method contains an exit-expression
  * and emits a rule violation when it exists.
  *
  * @param \PHPMD\AbstractNode $node
  * @return void
  */
 public function apply(AbstractNode $node)
 {
     foreach ($node->findChildrenOfType('ExitExpression') as $exit) {
         $this->addViolation($exit, array($node->getType(), $node->getName()));
     }
 }