Commit: d0e972cc2a5e8edfe66a025c5dad283db10bd3e5
Author: David Persson | Date: 2009-12-17 20:26:20 +0100
diff --git a/config/phpca_lithium_standard.ini b/config/phpca_lithium_standard.ini
index 49a2c8a..dbaf5fb 100644
--- a/config/phpca_lithium_standard.ini
+++ b/config/phpca_lithium_standard.ini
@@ -30,7 +30,8 @@ additional_rules = extensions/phpca/Rule
[MaximumLineLengthRule]
line_length = 100
[NoShortTypeNamesRule]
-[TightCastRule]
+[NoWhitespaceWithinCastRule]
+[OneSpaceAfterCastRule]
; Documentation
; [ClassesMustHaveDocBlockRule]
diff --git a/extensions/phpca/Rule/NoWhitespaceWithinCastRule.php b/extensions/phpca/Rule/NoWhitespaceWithinCastRule.php
new file mode 100644
index 0000000..006a875
--- /dev/null
+++ b/extensions/phpca/Rule/NoWhitespaceWithinCastRule.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace spriebsch\PHPca\Rule;
+
+/**
+ * Ensures that there are no whitespaces within a cast.
+ */
+class NoWhitespaceWithinCastRule extends Rule
+{
+ /**
+ * Performs the rule check.
+ *
+ * @returns null
+ */
+ protected function doCheck()
+ {
+ $casts = array(
+ T_BOOL_CAST, T_INT_CAST, T_ARRAY_CAST,
+ T_DOUBLE_CAST, T_OBJECT_CAST, T_UNSET_CAST
+ );
+ foreach ($casts as $id) {
+ while ($this->file->seekTokenId($id)) {
+ $token = $this->file->current();
+
+ if ($token->hasWhitespace()) {
+ $this->addViolation('Whitespace whithin cast', $token);
+ }
+ $this->file->next();
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/extensions/phpca/Rule/OneSpaceAfterCastRule.php b/extensions/phpca/Rule/OneSpaceAfterCastRule.php
new file mode 100644
index 0000000..82349f3
--- /dev/null
+++ b/extensions/phpca/Rule/OneSpaceAfterCastRule.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace spriebsch\PHPca\Rule;
+
+/**
+ * Ensures that there is one space after a cast.
+ */
+class OneSpaceAfterCastRule extends Rule
+{
+ /**
+ * Performs the rule check.
+ *
+ * @returns null
+ */
+ protected function doCheck()
+ {
+ $casts = array(
+ T_BOOL_CAST, T_INT_CAST, T_ARRAY_CAST,
+ T_DOUBLE_CAST, T_OBJECT_CAST, T_UNSET_CAST
+ );
+ foreach ($casts as $id) {
+ while ($this->file->seekTokenId($id)) {
+ $this->file->next();
+ $token = $this->file->current();
+
+ if ($token->getId() !== T_WHITESPACE) {
+ $this->addViolation('No space after cast', $token);
+ } elseif (strlen($token->getText()) > 1) {
+ $this->addViolation('More than one space after cast', $token);
+ }
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/extensions/phpca/Rule/TightCastRule.php b/extensions/phpca/Rule/TightCastRule.php
deleted file mode 100644
index 65028b3..0000000
--- a/extensions/phpca/Rule/TightCastRule.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-namespace spriebsch\PHPca\Rule;
-
-/**
- * Ensures that there are no whitespaces after or within a cast.
- */
-class TightCastRule extends Rule
-{
- /**
- * Performs the rule check.
- *
- * @returns null
- */
- protected function doCheck()
- {
- $casts = array(
- T_BOOL_CAST, T_INT_CAST, T_ARRAY_CAST,
- T_DOUBLE_CAST, T_OBJECT_CAST, T_UNSET_CAST
- );
- foreach ($casts as $id) {
- while ($this->file->seekTokenId($id)) {
- $token = $this->file->current();
-
- if ($token->hasWhitespace()) {
- $this->addViolation('Whitespace whithin cast', $token);
- }
-
- $this->file->next();
- $token = $this->file->current();
-
- if ($token->getId() === T_WHITESPACE) {
- $this->addViolation('Whitespace after cast', $token);
- }
- }
- }
- }
-}
-?>
\ No newline at end of file