Commit: 988e0f4f1711a285f18c355819ebffe916cc29aa
Author: David Persson | Date: 2010-01-14 11:38:47 +0100
diff --git a/extensions/phpca/Rule/EmptyLineBeforeCloseTagRule.php b/extensions/phpca/Rule/EmptyLineBeforeCloseTagRule.php
index e7d221a..5363338 100644
--- a/extensions/phpca/Rule/EmptyLineBeforeCloseTagRule.php
+++ b/extensions/phpca/Rule/EmptyLineBeforeCloseTagRule.php
@@ -10,21 +10,26 @@ class EmptyLineBeforeCloseTagRule extends Rule
/**
* Performs the rule check.
*
+ * We need to check 2 tokens previous to the closing tag otherwise a comment followed by
+ * and empty line followed by the closing tag is not properly recognized.
+ *
* @returns null
*/
protected function doCheck()
{
$this->file->seekTokenId(T_CLOSE_TAG);
+
$this->file->prev();
- $token = $this->file->current();
+ $b = $this->file->current();
- if (!$token) {
- return null;
- }
+ $this->file->prev();
+ $a = $this->file->current();
+
+ $string = $a->getText() . $b->getText();
$lineEndings = $this->configuration->getLineEndings();
- if (addcslashes($token->getText(), "\0..\37") != $lineEndings . $lineEndings) {
- $this->addViolation('File has no empty line before PHP close tag', $token);
+ if (!preg_match("/{$lineEndings}{$lineEndings}$/", $string)) {
+ $this->addViolation('File has no empty line before PHP close tag', $b);
}
}
}