Permalink
Browse files

Merge remote-tracking branch 'joomla/master' into 24796

  • Loading branch information...
2 parents 502ed04 + 6ff7a47 commit a4997f6c21bc8a917130185892df2a141c3e277d @chdemko chdemko committed Oct 18, 2011
Showing with 1,196 additions and 892 deletions.
  1. +1 −1 build.xml
  2. +2 −0 build/phpcs/Joomla/Sniffs/Commenting/ClassCommentSniff.php
  3. +5 −6 build/phpcs/Joomla/Sniffs/ControlStructures/ControlSignatureSniff.php
  4. +1 −1 build/phpcs/Joomla/Sniffs/ControlStructures/InlineControlStructureSniff.php
  5. +15 −44 build/phpcs/Joomla/Sniffs/ControlStructures/MultiLineConditionSniff.php
  6. +6 −0 build/phpcs/Joomla/Sniffs/Files/IncludingFileSniff.php
  7. +228 −0 build/phpcs/Joomla/Sniffs/Functions/FunctionDeclarationSniff.php
  8. +1 −0 build/phpcs/Joomla/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php
  9. +0 −9 build/phpcs/Joomla/ruleset.xml
  10. +52 −16 libraries/joomla/access/access.php
  11. +1 −2 libraries/joomla/application/application.php
  12. +4 −3 libraries/joomla/application/component/controller.php
  13. +52 −0 libraries/joomla/application/component/modeladmin.php
  14. +0 −1 libraries/joomla/application/component/modelform.php
  15. +1 −1 libraries/joomla/database/database/sqlazure.php
  16. +4 −135 libraries/joomla/database/database/sqlazurequery.php
  17. +1 −1 libraries/joomla/database/table.php
  18. +1 −2 libraries/joomla/database/table/category.php
  19. +2 −0 libraries/joomla/database/table/extension.php
  20. +1 −2 libraries/joomla/database/table/menu.php
  21. +1 −2 libraries/joomla/database/table/user.php
  22. +2 −12 libraries/joomla/environment/request.php
  23. +54 −11 libraries/joomla/error/error.php
  24. +1 −2 libraries/joomla/form/fields/componentlayout.php
  25. +2 −1 libraries/joomla/form/fields/password.php
  26. +2 −3 libraries/joomla/form/rules/url.php
  27. +1 −1 libraries/joomla/html/editor.php
  28. +59 −84 libraries/joomla/html/grid.php
  29. +23 −0 libraries/joomla/html/html/batch.php
  30. +4 −4 libraries/joomla/html/html/behavior.php
  31. +14 −8 libraries/joomla/html/html/jgrid.php
  32. +5 −2 libraries/joomla/html/html/select.php
  33. +1 −1 libraries/joomla/html/parameter/element/hidden.php
  34. +2 −1 libraries/joomla/html/parameter/element/spacer.php
  35. +1 −2 libraries/joomla/installer/adapters/component.php
  36. +5 −6 libraries/joomla/installer/adapters/language.php
  37. +1 −2 libraries/joomla/installer/adapters/module.php
  38. +1 −2 libraries/joomla/installer/adapters/plugin.php
  39. +1 −2 libraries/joomla/installer/adapters/template.php
  40. +6 −0 libraries/joomla/language/language.php
  41. +1 −2 libraries/joomla/plugin/plugin.php
  42. +2 −0 libraries/joomla/registry/format/json.php
  43. +1 −0 libraries/joomla/registry/registry.php
  44. +1 −2 libraries/joomla/string/string.php
  45. +2 −3 libraries/joomla/updater/adapters/extension.php
  46. +1 −2 libraries/joomla/updater/update.php
  47. +1 −0 libraries/loader.php
  48. +1 −1 tests/.gitignore
  49. +55 −37 tests/bootstrap.php
  50. +12 −1 tests/{config.php-dist → config.dist.php}
  51. +0 −15 tests/includes/JUnitHelper.php
  52. +121 −102 tests/includes/JoomlaDatabaseTestCase.php
  53. +42 −57 tests/includes/JoomlaTestCase.php
  54. 0 tests/{suite/joomla/application → includes/mocks}/JApplicationMock.php
  55. 0 tests/{suite/joomla/application → includes/mocks}/JConfigMock.php
  56. +1 −1 tests/{suite/joomla/database → includes/mocks}/JDatabaseMock.php
  57. 0 tests/{suite/joomla/database/JDatabaseHelper.php → includes/mocks/JDatabaseQueryDummy.php}
  58. 0 tests/{suite/joomla/event → includes/mocks}/JDispatcherMock.php
  59. 0 tests/{suite/joomla/document → includes/mocks}/JDocumentMock.php
  60. 0 tests/{suite/joomla/language → includes/mocks}/JLanguageMock.php
  61. 0 tests/{suite/joomla/session → includes/mocks}/JSessionMock.php
  62. +1 −0 tests/includes/stubs/test.xml
  63. +0 −4 tests/objects/index.html
  64. +15 −15 tests/suite/JLoaderTest.php
  65. +6 −1 tests/suite/joomla/access/JAccessTest.php
  66. 0 tests/suite/joomla/access/{JAccessTest.xml → stubs/S01.xml}
  67. +1 −1 tests/suite/joomla/application/JCliTest.php
  68. +3 −3 tests/suite/joomla/application/JInputTest.php
  69. +1 −4 tests/suite/joomla/application/JWebTest.php
  70. +1 −4 tests/suite/joomla/application/cli/JDaemonTest.php
  71. 0 tests/suite/joomla/application/cli/{TestStubs/JDaemon_Inspector.php → stubs/JDaemonInspector.php}
  72. +14 −0 tests/suite/joomla/application/component/JControllerTest.php
  73. +2 −2 tests/suite/joomla/application/input/JInputCLITest.php
  74. +1 −1 ...suite/joomla/application/input/{TestStubs/JInputCLI_Inspector.php → stubs/JInputCliInspector.php}
  75. 0 tests/suite/joomla/application/{TestStubs/JCli_Inspector.php → stubs/JCliInspector.php}
  76. 0 tests/suite/joomla/application/{TestStubs/JFilterInput_Mock.php → stubs/JFilterInputMock.php}
  77. 0 .../joomla/application/{TestStubs/JFilterInput_Mock_Tracker.php → stubs/JFilterInputMockTracker.php}
  78. 0 tests/suite/joomla/application/{TestStubs/JInput_Inspector.php → stubs/JInputInspector.php}
  79. 0 tests/suite/joomla/application/{TestStubs/JWeb_Inspector.php → stubs/JWebInspector.php}
  80. +2 −5 tests/suite/joomla/application/web/JWebClientTest.php
  81. 0 ...suite/joomla/application/web/{TestStubs/JWebClient_Inspector.php → stubs/JWebClientInspector.php}
  82. +29 −13 tests/suite/joomla/base/JAdapterInstanceTest.php
  83. +65 −30 tests/suite/joomla/base/JAdapterTest.php
  84. 0 tests/suite/joomla/base/{TestAdapters → stubs}/testadapter.php
  85. 0 tests/suite/joomla/base/{TestAdapters → stubs}/testadapter2.php
  86. 0 tests/suite/joomla/base/{TestAdapters → stubs}/testadapter3.php
  87. 0 tests/suite/joomla/base/{TestAdapters → stubs}/testadapter4.php
  88. +3 −3 tests/suite/joomla/cache/controller/JCacheControllerCallbackCallbackTest.php
  89. +1 −1 tests/suite/joomla/cache/storage/JCacheStorageMainTest.php
  90. +3 −3 tests/suite/joomla/database/JTableNestedTest.php
  91. +1 −1 tests/suite/joomla/database/database/JDatabaseExporterMySqlTest.php
  92. +1 −1 tests/suite/joomla/database/database/JDatabaseImporterMySqlTest.php
  93. +1 −1 tests/suite/joomla/database/database/JDatabaseMySQLTest.php
  94. 0 tests/suite/joomla/database/database/{TestStubs → stubs}/database.xml
  95. 0 tests/{ → suite/joomla/database}/stubs/jos_assets.csv
  96. 0 tests/{ → suite/joomla/database}/stubs/jos_categories.csv
  97. 0 tests/{ → suite/joomla/database}/stubs/jos_menu.csv
  98. +21 −23 tests/suite/joomla/environment/JFilterInput-mock-general.php
  99. +1 −1 tests/suite/joomla/environment/JRequestCleanTest.php
  100. +22 −23 tests/suite/joomla/environment/JRequestGetVarTest.php
  101. +12 −12 tests/suite/joomla/form/JFormTest.php
  102. +1 −1 tests/suite/joomla/form/fields/JFormFieldAccessLevelTest.php
  103. +1 −1 tests/suite/joomla/form/fields/JFormFieldCacheHandlersTest.php
  104. +4 −4 tests/suite/joomla/form/fields/JFormFieldCalendarTest.php
  105. +1 −1 tests/suite/joomla/form/fields/JFormFieldCategoryTest.php
  106. +1 −1 tests/suite/joomla/form/fields/JFormFieldCheckboxTest.php
  107. +2 −2 tests/suite/joomla/form/fields/JFormFieldCheckboxesTest.php
  108. +1 −1 tests/suite/joomla/form/fields/JFormFieldComboTest.php
  109. +1 −1 tests/suite/joomla/form/fields/JFormFieldComponentLayoutsTest.php
  110. +1 −1 tests/suite/joomla/form/fields/JFormFieldContentLanguagesTest.php
  111. +1 −1 tests/suite/joomla/form/fields/JFormFieldEditorTest.php
  112. +1 −1 tests/suite/joomla/form/fields/JFormFieldEditorsTest.php
  113. +1 −1 tests/suite/joomla/form/fields/JFormFieldFileTest.php
  114. +1 −1 tests/suite/joomla/form/fields/JFormFieldHelpsiteTest.php
  115. +1 −1 tests/suite/joomla/form/fields/JFormFieldHiddenTest.php
  116. +1 −1 tests/suite/joomla/form/fields/JFormFieldIntegerTest.php
  117. +1 −1 tests/suite/joomla/form/fields/JFormFieldLanguageTest.php
  118. +1 −1 tests/suite/joomla/form/fields/JFormFieldListTest.php
  119. +1 −1 tests/suite/joomla/form/fields/JFormFieldMediaTest.php
  120. +1 −1 tests/suite/joomla/form/fields/JFormFieldModuleLayoutsTest.php
  121. +1 −1 tests/suite/joomla/form/fields/JFormFieldPasswordTest.php
  122. +1 −1 tests/suite/joomla/form/fields/JFormFieldRadioTest.php
  123. +1 −1 tests/suite/joomla/form/fields/JFormFieldRulesTest.php
  124. +1 −1 tests/suite/joomla/form/fields/JFormFieldSessionHandlersTest.php
  125. +1 −1 tests/suite/joomla/form/fields/JFormFieldSpacerTest.php
  126. +1 −1 tests/suite/joomla/form/fields/JFormFieldTemplateStyleTest.php
  127. +1 −1 tests/suite/joomla/form/fields/JFormFieldTextTest.php
  128. +1 −1 tests/suite/joomla/form/fields/JFormFieldTextareaTest.php
  129. +1 −1 tests/suite/joomla/form/fields/JFormFieldTimezoneTest.php
  130. +1 −1 tests/suite/joomla/form/fields/JFormFieldUserTest.php
  131. +1 −1 tests/suite/joomla/form/fields/JFormFieldUsergroupTest.php
  132. +58 −48 tests/suite/joomla/html/JGridTest.php
  133. +7 −3 tests/suite/joomla/html/JHtmlTest.php
  134. +4 −4 tests/suite/joomla/html/JParameterTest.php
  135. +1 −1 tests/suite/joomla/html/html/JHtmlBatchTest.php
  136. +23 −4 tests/suite/joomla/html/html/JHtmlSelectTest.php
  137. +24 −0 tests/suite/joomla/html/html/TestHelpers/JHtmlSelect-helper-dataset.php
  138. +18 −1 tests/suite/joomla/log/JLogTest.php
  139. +4 −4 tests/suite/joomla/log/loggers/JLoggerDatabaseTest.php
  140. +1 −1 tests/suite/joomla/log/loggers/JLoggerFormattedTextTest.php
  141. +1 −1 tests/suite/joomla/log/loggers/JLoggerMessageQueueTest.php
  142. +1 −1 tests/suite/joomla/log/loggers/JLoggerW3CTest.php
  143. +4 −4 tests/suite/joomla/registry/JRegistryTest.php
  144. 0 tests/suite/joomla/registry/{TestStubs/JRegistry_Inspector.php → stubs/JRegistryInspector.php}
  145. 0 tests/suite/joomla/registry/{TestStubs → stubs}/jregistry.ini
  146. 0 tests/suite/joomla/registry/{TestStubs → stubs}/jregistry.json
  147. +1 −1 tests/suite/joomla/user/JAuthenticationTest.php
  148. 0 tests/suite/joomla/user/{TestStubs → stubs}/FakeAuthenticationPlugin.php
  149. +3 −3 tests/suite/joomla/utilities/JSimpleXMLTest.php
  150. 0 tests/suite/joomla/utilities/{TestStubs → stubs}/empty.xml
  151. 0 tests/suite/joomla/utilities/{TestStubs → stubs}/test.xml
  152. 0 tests/suite/joomla/utilities/{TestStubs → stubs}/xmlFile.xml
  153. 0 tests/{objects → suite/stubs}/bogusload.php
  154. 0 tests/{objects → suite/stubs}/discover1/challenger.php
  155. 0 tests/{objects → suite/stubs}/discover1/columbia.php
  156. 0 tests/{objects → suite/stubs}/discover1/enterprise.txt
  157. 0 tests/{objects → suite/stubs}/discover2/challenger.php
  158. 0 tests/{objects → suite/stubs}/discover2/discover3/atlantis.php
  159. +0 −29 tests/test_application/defines.php
  160. +0 −4 tests/test_application/media/system/images/index.html
  161. +0 −4 tests/test_application/templates/index.html
  162. 0 tests/{test_application → tmp}/config.jweb-array.php
  163. 0 tests/{test_application → tmp}/config.jweb-snoopy.php
  164. 0 tests/{test_application → tmp}/config.jweb-wrongclass.php
  165. 0 tests/{test_application → tmp}/configuration.php
View
@@ -81,7 +81,7 @@
<exec executable="phpcs">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
- <arg value="--standard=Joomla" />
+ <arg value="--standard=${basedir}/build/phpcs/Joomla" />
<arg path="${source}/joomla" />
</exec>
</target>
@@ -19,6 +19,8 @@
throw new PHP_CodeSniffer_Exception($error);
}
+require_once 'FileCommentSniff.php';
+
if (class_exists('Joomla_Sniffs_Commenting_FileCommentSniff', true) === false) {
$error = 'Class Joomla_Sniffs_Commenting_FileCommentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
@@ -50,10 +50,9 @@ public function __construct()
protected function getPatterns()
{
return array(
- 'if (...)EOL...{...}EOL',
- 'elseEOL...{EOL',
- 'elseif (...)EOL...{EOL',
- 'else if (...)EOL...{EOL',
+ 'if (...)EOL...{...}EOL...elseEOL',
+ 'if (...)EOL...{...}EOL...elseif (...)EOL',
+ 'if (...)EOL',
'tryEOL...{EOL...}EOL',
'catch (...)EOL...{EOL',
@@ -88,8 +87,8 @@ protected function processPattern($patternInfo, PHP_CodeSniffer_File $phpcsFile
{
/*
* @todo disabled - This is a special sniff for the Joomla! CMS to exclude
- * the tmpl folder which may contain constructs in colon notation
- */
+ * the tmpl folder which may contain constructs in colon notation
+ */
$parts = explode(DIRECTORY_SEPARATOR, $phpcsFile->getFileName());
@@ -46,7 +46,7 @@ class Joomla_Sniffs_ControlStructures_InlineControlStructureSniff extends Generi
*
* @var bool
*/
- public $error = true;
+ public $error = false;
/**
@@ -29,7 +29,6 @@
class Joomla_Sniffs_ControlStructures_MultiLineConditionSniff implements PHP_CodeSniffer_Sniff
{
-
/**
* Returns an array of tokens this test wants to listen for.
*
@@ -41,7 +40,6 @@ public function register()
}//end register()
-
/**
* Processes this test, when one of its tokens is encountered.
*
@@ -74,25 +72,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
// function call, in which case it is ignored.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
- $lastLine = $tokens[$openBracket]['line'];
- for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
+ $lastLine = $tokens[$openBracket]['line'];
+
+ for ($i = ($openBracket + 1); $i <= $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
- if ($next !== $closeBracket) {
- // Closing bracket is on the same line as a condition.
- $error = 'Closing parenthesis of a multi-line IF statement must be on a new line';
- $phpcsFile->addError($error, $i, 'CloseBracketNewLine');
- $expectedIndent = ($statementIndent + 1);
- } else {
- // Closing brace needs to be indented to the same level
- // as the function.
- $expectedIndent = $statementIndent;
+ if ($next == $closeBracket) {
+ $error = 'Closing parenthesis of a multi-line IF statement must be on the same line';
+ $phpcsFile->addError($error, $i, 'CloseBracketNewLine');
+ $i ++;
+ continue;
}
- } else {
- $expectedIndent = ($statementIndent + 1);
}
+ $expectedIndent = ($statementIndent + 1);
+
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
@@ -109,12 +104,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $i, 'Alignment', $data);
}
- if ($tokens[$i]['line'] !== $tokens[$closeBracket]['line']) {
- $next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
- if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$booleanOperators) === false) {
- $error = 'Each line in a multi-line IF statement must begin with a boolean operator';
- $phpcsFile->addError($error, $i, 'StartWithBoolean');
- }
+ $next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
+
+ if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$booleanOperators) === false) {
+ $error = 'Each line in a multi-line IF statement must begin with a boolean operator';
+ $phpcsFile->addError($error, $i, 'StartWithBoolean');
}
$lastLine = $tokens[$i]['line'];
@@ -132,31 +126,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}//end for
- // From here on, we are checking the spacing of the opening and closing
- // braces. If this IF statement does not use braces, we end here.
- if (isset($tokens[$stackPtr]['scope_opener']) === false) {
- return;
- }
-
- // The opening brace needs to be one space away from the closing parenthesis.
- if ($tokens[($closeBracket + 1)]['code'] !== T_WHITESPACE) {
- $length = 0;
- } else if ($tokens[($closeBracket + 1)]['content'] === $phpcsFile->eolChar) {
- $length = -1;
- } else {
- $length = strlen($tokens[($closeBracket + 1)]['content']);
- }
-
- // And just in case they do something funny before the brace...
- $next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
- if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
- $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement';
- $phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
- }
-
}//end process()
-
}//end class
?>
@@ -83,6 +83,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $stackPtr, 'BracketsNotRequired', $data);
}
+ /*
+ * elkuku: The test for conditional including has been disabled.
+ */
+
+ return;
+
$inCondition = (count($tokens[$stackPtr]['conditions']) !== 0) ? true : false;
// Check to see if this including statement is within the parenthesis
@@ -0,0 +1,228 @@
+<?php
+/**
+ * Joomla_Sniffs_Functions_FunctionDeclarationSniff.
+ *
+ * PHP version 5
+ *
+ * @category PHP
+ * @package PHP_CodeSniffer
+ * @author Greg Sherwood <gsherwood@squiz.net>
+ * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
+ * @version CVS: $Id: FunctionDeclarationSniff.php 308840 2011-03-02 05:32:18Z squiz $
+ * @link http://pear.php.net/package/PHP_CodeSniffer
+ */
+
+/**
+ * Joomla_Sniffs_Functions_FunctionDeclarationSniff.
+ *
+ * Ensure single and multi-line function declarations are defined correctly.
+ *
+ * @category PHP
+ * @package PHP_CodeSniffer
+ * @author Greg Sherwood <gsherwood@squiz.net>
+ * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
+ * @version Release: 1.3.0
+ * @link http://pear.php.net/package/PHP_CodeSniffer
+ */
+class Joomla_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff
+{
+
+ /**
+ * Returns an array of tokens this test wants to listen for.
+ *
+ * @return array
+ */
+ public function register()
+ {
+ return array(T_FUNCTION);
+ }//end register()
+
+ /**
+ * Processes this test, when one of its tokens is encountered.
+ *
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
+ * @param int $stackPtr The position of the current token
+ * in the stack passed in $tokens.
+ *
+ * @return void
+ */
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ // Check if this is a single line or multi-line declaration.
+ $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
+ $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
+ if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
+ $this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
+ } else {
+ $this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
+ }
+
+ }//end process()
+
+ /**
+ * Processes single-line declarations.
+ *
+ * Just uses the Generic BSD-Allman brace sniff.
+ *
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
+ * @param int $stackPtr The position of the current token
+ * in the stack passed in $tokens.
+ * @param array $tokens The stack of tokens that make up
+ * the file.
+ *
+ * @return void
+ */
+ public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
+ {
+ if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff', true) === false) {
+ throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff not found');
+ }
+
+ $sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff();
+ $sniff->process($phpcsFile, $stackPtr);
+
+ }//end processSingleLineDeclaration()
+
+
+ /**
+ * Processes mutli-line declarations.
+ *
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
+ * @param int $stackPtr The position of the current token
+ * in the stack passed in $tokens.
+ * @param array $tokens The stack of tokens that make up
+ * the file.
+ *
+ * @return void
+ */
+ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
+ {
+ // We need to work out how far indented the function
+ // declaration itself is, so we can work out how far to
+ // indent parameters.
+ $functionIndent = 0;
+ for ($i = ($stackPtr - 1); $i >= 0; $i--) {
+ if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
+ $i++;
+ break;
+ }
+ }
+
+ if ($tokens[$i]['code'] === T_WHITESPACE) {
+ $functionIndent = strlen($tokens[$i]['content']);
+ }
+
+ // Each line between the parenthesis should be indented 4 spaces.
+ $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
+ $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
+ $lastLine = $tokens[$openBracket]['line'];
+ for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
+ if ($tokens[$i]['line'] !== $lastLine)
+ {
+ //-- elkuku: disabled
+// if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
+// // Closing brace needs to be indented to the same level
+// // as the function.
+// $expectedIndent = $functionIndent;
+// } else {
+// $expectedIndent = $functionIndent + 4;
+// }
+
+ $expectedIndent = $functionIndent + 1;
+
+ // We changed lines, so this should be a whitespace indent token.
+ if ($tokens[$i]['code'] !== T_WHITESPACE) {
+ $foundIndent = 0;
+ } else {
+ $foundIndent = strlen($tokens[$i]['content']);
+ }
+
+ if ($expectedIndent !== $foundIndent) {
+ $error = 'Multi-line function declaration not indented correctly; expected %s spaces but found %s';
+ $data = array(
+ $expectedIndent,
+ $foundIndent,
+ );
+ $phpcsFile->addError($error, $i, 'Indent', $data);
+ }
+
+ $lastLine = $tokens[$i]['line'];
+ }//end if
+
+ if ($tokens[$i]['code'] === T_ARRAY) {
+ // Skip arrays as they have their own indentation rules.
+ $i = $tokens[$i]['parenthesis_closer'];
+ $lastLine = $tokens[$i]['line'];
+ continue;
+ }
+ }//end for
+
+ if (isset($tokens[$stackPtr]['scope_opener']) === true) {
+ // The openning brace needs to be one space away
+ // from the closing parenthesis.
+ $next = $tokens[($closeBracket + 1)];
+ if ($next['code'] !== T_WHITESPACE) {
+ $length = 0;
+ } else if ($next['content'] === $phpcsFile->eolChar) {
+ $length = -1;
+ } else {
+ $length = strlen($next['content']);
+ }
+
+ if (false)//$length !== 1) {
+ {
+ $data = array($length);
+ $code = 'SpaceBeforeOpenBrace';
+
+ //-- elkuku: nonsens ?
+// $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found ';
+// if ($length === -1) {
+// $error .= 'newline';
+// $code = 'NewlineBeforeOpenBrace';
+// } else {
+// $error .= '%s spaces';
+// }
+
+ $phpcsFile->addError($error, ($closeBracket + 1), $code, $data);
+ return;
+ }
+
+ // And just in case they do something funny before the brace...
+ $next = $phpcsFile->findNext(
+ T_WHITESPACE,
+ ($closeBracket + 1),
+ null,
+ true
+ );
+
+ //-- elkuku: nonsens ?
+// if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
+// $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration';
+// $phpcsFile->addError($error, $next, 'NoSpaceBeforeOpenBrace');
+// }
+ }//end if
+
+ // The closing parenthesis must be on a new line, even
+ // when checking abstract function definitions.
+ $prev = $phpcsFile->findPrevious(
+ T_WHITESPACE,
+ ($closeBracket - 1),
+ null,
+ true
+ );
+
+ if ($tokens[$prev]['line'] != $tokens[$closeBracket]['line']) {
+ $error = 'The closing parenthesis of a multi-line function declaration must be on the same line';
+ $phpcsFile->addError($error, $closeBracket, 'CloseBracketLine');
+ }
+
+ }//end processMultiLineDeclaration()
+
+
+}//end class
+
+?>
Oops, something went wrong.

0 comments on commit a4997f6

Please sign in to comment.