public function apply(AbstractNode $node) { foreach ($node->getProperties() as $property) { if (!$property->isStatic() && !preg_match('/^\\$[a-zA-Z][a-zA-Z0-9]*$/', $property->getName())) { $this->addViolation($node, array($property->getName())); } } }
/** * This method checks if a property is not named in camelCase * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $allowUnderscore = $this->getBooleanProperty('allow-underscore'); $pattern = '/^\\$[a-zA-Z][a-zA-Z0-9]*$/'; if ($allowUnderscore == true) { $pattern = '/^\\$[_]?[a-zA-Z][a-zA-Z0-9]*$/'; } foreach ($node->getProperties() as $property) { $propertyName = $property->getName(); if (!preg_match($pattern, $propertyName)) { $this->addViolation($node, array($propertyName)); } } }
/** * @param AbstractNode|ASTClass $node */ private function checkProperties(AbstractNode $node) { foreach ($node->getProperties() as $property) { $this->checkNode($node, 'property ' . $property->getName(), $this->calculateNameToCommentSimilarityInPercent($property)); } }