From 5f9e8a242da83b0efc540647a62d8b093e4fdb41 Mon Sep 17 00:00:00 2001 From: Manuel Pichler Date: Tue, 9 Sep 2014 20:34:13 +0200 Subject: [PATCH] Closes #183: exceptions for CamelCaseVariableName and UnusedLocalVariable --- .../Controversial/CamelCaseVariableName.php | 25 +++++++++++++------ src/site/docx/changes.xml | 3 +++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/php/PHPMD/Rule/Controversial/CamelCaseVariableName.php b/src/main/php/PHPMD/Rule/Controversial/CamelCaseVariableName.php index bc0c498a0..5d81a4626 100644 --- a/src/main/php/PHPMD/Rule/Controversial/CamelCaseVariableName.php +++ b/src/main/php/PHPMD/Rule/Controversial/CamelCaseVariableName.php @@ -61,6 +61,14 @@ */ class CamelCaseVariableName extends AbstractRule implements MethodAware, FunctionAware { + /** + * @var array + */ + private $exceptions = array( + '$php_errormsg', + '$http_response_header', + ); + /** * This method checks if a variable is not named in camelCase * and emits a rule violation. @@ -71,14 +79,17 @@ class CamelCaseVariableName extends AbstractRule implements MethodAware, Functio public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('Variable') as $variable) { - if (!preg_match('/^\$[a-z][a-zA-Z0-9]*$/', $variable->getImage())) { - $this->addViolation( - $node, - array( - $variable->getImage(), - ) - ); + $image = $variable->getImage(); + + if (in_array($image, $this->exceptions)) { + continue; } + + if (preg_match('/^\$[a-z][a-zA-Z0-9]*$/', $image)) { + continue; + } + + $this->addViolation($node, array($image)); } } } diff --git a/src/site/docx/changes.xml b/src/site/docx/changes.xml index 21ae1a7e9..30ef178a9 100644 --- a/src/site/docx/changes.xml +++ b/src/site/docx/changes.xml @@ -19,6 +19,9 @@ --version argument doesn't return version + + exceptions for CamelCaseVariableName and UnusedLocalVariable +