Skip to content

Commit

Permalink
Closes #183: exceptions for CamelCaseVariableName and UnusedLocalVari…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
Manuel Pichler committed Sep 9, 2014
1 parent 3cbcf02 commit 5f9e8a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/main/php/PHPMD/Rule/Controversial/CamelCaseVariableName.php
Expand Up @@ -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.
Expand All @@ -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));
}
}
}
3 changes: 3 additions & 0 deletions src/site/docx/changes.xml
Expand Up @@ -19,6 +19,9 @@
<action due-to="piotr-cz" dev="manuelpichler" issue="168" system="github" type="fix">
--version argument doesn't return version
</action>
<action due-to="till" dev="manuelpichler" issue="183" system="github" type="add">
exceptions for CamelCaseVariableName and UnusedLocalVariable
</action>
</release>
<release version="2.1.0"
date="2014/09/08"
Expand Down

0 comments on commit 5f9e8a2

Please sign in to comment.