diff --git a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php new file mode 100644 index 0000000..0028726 --- /dev/null +++ b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php @@ -0,0 +1,64 @@ +getTokens(); + + if ($tokens[($stackPtr + 1)]['content'] !== ' ') { + $error = 'Expected exactly one space after the function keyword'; + $phpcsFile->addError($error, ($stackPtr + 1), 'SpaceAfter'); + } + + if (isset($tokens[($stackPtr + 3)]) === true + && $tokens[($stackPtr + 3)]['code'] === T_WHITESPACE + ) { + $error = 'Space before opening parenthesis of function definition prohibited'; + $phpcsFile->addError($error, ($stackPtr + 3), 'SpaceBeforeParenthesis'); + } + + }//end process() + + +}//end class diff --git a/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc.fixed b/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc.fixed index f8c4404..ef88e24 100644 --- a/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc.fixed +++ b/coder_sniffer/Drupal/Test/WhiteSpace/ScopeIndentUnitTest.inc.fixed @@ -15,7 +15,7 @@ class MyClass { } -setTimeout(function () { +setTimeout(function() { $timer = parseInt($target, 10); if (timer > 0) { $target--; diff --git a/coder_sniffer/Drupal/Test/bad/bad.php.fixed b/coder_sniffer/Drupal/Test/bad/bad.php.fixed index 036fd21..cc0ad8f 100644 --- a/coder_sniffer/Drupal/Test/bad/bad.php.fixed +++ b/coder_sniffer/Drupal/Test/bad/bad.php.fixed @@ -693,14 +693,14 @@ function test17($x, $y) { /** * Too much space after the function keyword. */ -function test18() { +function test18() { } /** * Space before opening parenthesis is not allowed. */ -function test19() { +function test19 () { } diff --git a/coder_sniffer/Drupal/Test/good/good.php b/coder_sniffer/Drupal/Test/good/good.php index 4ea3b64..da9f6f4 100644 --- a/coder_sniffer/Drupal/Test/good/good.php +++ b/coder_sniffer/Drupal/Test/good/good.php @@ -348,7 +348,7 @@ multiline_call(Inspector::assertAllCallable([ 'strchr', [$x, 'callMe'], ['test', 'callMeStatic'], - function () { + function() { return TRUE; }, ])); @@ -356,7 +356,7 @@ multiline_call(Inspector::assertAllCallable(array( 'strchr', array($x, 'callMe'), array('test', 'callMeStatic'), - function () { + function() { return TRUE; }, ))); @@ -991,7 +991,7 @@ t('Some long mulit-line text is weird, but allowed.'); // Anonymous functions should not throw indentation errors here. -$test = array_walk($fragments, function (&$item) { +$test = array_walk($fragments, function(&$item) { if (strpos($item, '%') === 0) { $item = '%'; } diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index 8855746..32a3ef9 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -226,14 +226,6 @@ 0 - - - 0 - - - 0 - -