Commit: 1264ce8439ed17d73c43b20ae649cc83e6605b28
Author: Marke Hallowell | Date: 2010-01-31 02:52:36 -0800
diff --git a/config/phpca_lithium_standard.ini b/config/phpca_lithium_standard.ini
index 9faeab2..a049d4a 100644
--- a/config/phpca_lithium_standard.ini
+++ b/config/phpca_lithium_standard.ini
@@ -35,6 +35,7 @@ line_length = 100
[OneSpaceAfterCastsRule]
[OperatorsSurroundedBySpacesRule]
[DocTagsOrderRule]
+[ConstantsUppercaseRule]
; Documentation
; [ClassesMustHaveDocBlockRule]
diff --git a/extensions/phpca/Rule/ConstantsUppercaseRule.php b/extensions/phpca/Rule/ConstantsUppercaseRule.php
new file mode 100644
index 0000000..cc28cfc
--- /dev/null
+++ b/extensions/phpca/Rule/ConstantsUppercaseRule.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace spriebsch\PHPca\Rule;
+
+use spriebsch\PHPca\Token;
+
+/**
+ * Ensures that Constants are upper case
+ */
+class ConstantsUppercaseRule extends Rule {
+ /**
+ * Performs the rule check.
+ *
+ * @returns null
+ */
+ public function doCheck() {
+ $source = $this->file->getSourceCode();
+
+ $namedConstants = array();
+ $definePattern = '/' . $this->configuration->getLineEndings() . '.*?define\("(.*?)".*[^';
+ $definePattern .= $this->configuration->getLineEndings() . ']/';
+
+ preg_match_all($definePattern, $source, $namedConstants);
+ $declarations = array_shift($namedConstants);
+ $namedConstants = array_shift($namedConstants);
+
+ foreach($namedConstants as $i => $const) {
+ if($const != strtoupper($const)) {
+ $lines = array();
+ $line = preg_match_all(
+ '/.*?' . $this->configuration->getLineEndings() . '.*?/',
+ substr($source, 0, strpos($source, 'define("' . $const)),
+ $lines
+ );
+
+ $this->addViolation(
+ "Named Constant `" . $const . "` not upper case",
+ null,
+ $line + 1,
+ strpos($declarations[$i], $const)
+ );
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file