diff --git a/data/CodingStandard/OpenPNE3/OpenPNE3CodingStandard.php b/data/CodingStandard/OpenPNE3/OpenPNE3CodingStandard.php deleted file mode 100644 index 6cb9caaee..000000000 --- a/data/CodingStandard/OpenPNE3/OpenPNE3CodingStandard.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -class PHP_CodeSniffer_Standards_OpenPNE3_OpenPNE3CodingStandard extends PHP_CodeSniffer_Standards_CodingStandard -{ - public function getIncludedSniffs() - { - return array( - 'Zend', - 'Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php', - 'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php', - 'Squiz/Sniffs/Scope/MemberVarScopeSniff.php', - 'Squiz/Sniffs/Scope/MethodScopeSniff.php', - 'Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php', - ); - } - - public function getExcludedSniffs() - { - return array( - 'PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php', - 'PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php', - 'Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php', - 'Squiz/Sniffs/Functions/GlobalFunctionSniff.php', - ); - } -} diff --git a/data/CodingStandard/OpenPNE3/Sniffs/Arrays/ArrayDeclarationSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/Arrays/ArrayDeclarationSniff.php index 9ac3068c2..9e18551a7 100644 --- a/data/CodingStandard/OpenPNE3/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/data/CodingStandard/OpenPNE3/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -23,6 +23,9 @@ public function register() public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + // this class is not stable yet... + return null; + $tokens = $phpcsFile->getTokens(); $arrayStart = $tokens[$stackPtr]['parenthesis_opener']; diff --git a/data/CodingStandard/OpenPNE3/Sniffs/Commenting/ClassCommentSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/Commenting/ClassCommentSniff.php index a126e4117..0eadc52d8 100644 --- a/data/CodingStandard/OpenPNE3/Sniffs/Commenting/ClassCommentSniff.php +++ b/data/CodingStandard/OpenPNE3/Sniffs/Commenting/ClassCommentSniff.php @@ -16,6 +16,174 @@ */ class OpenPNE3_Sniffs_Commenting_ClassCommentSniff extends Squiz_Sniffs_Commenting_ClassCommentSniff { + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + { + if ( + // myUser.class.php should be excluded + false !== strpos($phpcsFile->getFilename(), 'myUser.class.php') + ) + { + return null; + } + + $this->currentFile = $phpcsFile; + + $tokens = $phpcsFile->getTokens(); + $find = array (T_ABSTRACT, T_WHITESPACE, T_FINAL); + + // Extract the class comment docblock. + $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); + + if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_COMMENT) + { + $phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr); + + return; + } else if ($commentEnd === false || $tokens[$commentEnd]['code'] !== T_DOC_COMMENT) + { + $phpcsFile->addError('Missing class doc comment', $stackPtr); + + return; + } + + $commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1); + $commentNext = $phpcsFile->findPrevious(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar); + + // Distinguish file and class comment. + $prevClassToken = $phpcsFile->findPrevious(T_CLASS, ($stackPtr - 1)); + if ($prevClassToken === false) + { + // This is the first class token in this file, need extra checks. + $prevNonComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentStart - 1), null, true); + if ($prevNonComment !== false) + { + $prevComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($prevNonComment - 1)); + if ($prevComment === false) + { + // There is only 1 doc comment between open tag and class token. + $newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar); + if ($newlineToken !== false) + { + $newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($newlineToken + 1), $stackPtr, false, $phpcsFile->eolChar); + if ($newlineToken !== false) + { + // Blank line between the class and the doc block. + // The doc block is most likely a file comment. + $phpcsFile->addError('Missing class doc comment', ($stackPtr + 1)); + + return; + } + }//end if + }//end if + + // Exactly one blank line before the class comment. + $prevTokenEnd = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true); + if ($prevTokenEnd !== false) + { + $blankLineBefore = 0; + for ($i = ($prevTokenEnd + 1); $i < $commentStart; $i++) + { + if ($tokens[$i]['code'] === T_WHITESPACE && $tokens[$i]['content'] === $phpcsFile->eolChar) + { + $blankLineBefore++; + } + } + + if ($blankLineBefore !== 2) + { + $error = 'There must be exactly one blank line before the class comment'; + $phpcsFile->addError($error, ($commentStart - 1)); + } + } + }//end if + }//end if + + $commentString = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1)); + + // Parse the class comment docblock. + try + { + $this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($commentString, $phpcsFile); + $this->commentParser->parse(); + } + catch (PHP_CodeSniffer_CommentParser_ParserException $e) + { + $line = ($e->getLineWithinComment() + $commentStart); + $phpcsFile->addError($e->getMessage(), $line); + + return; + } + + $comment = $this->commentParser->getComment(); + if (is_null($comment) === true) + { + $error = 'Class doc comment is empty'; + $phpcsFile->addError($error, $commentStart); + + return; + } + + // The first line of the comment should just be the /** code. + $eolPos = strpos($commentString, $phpcsFile->eolChar); + $firstLine = substr($commentString, 0, $eolPos); + if ($firstLine !== '/**') + { + $error = 'The open comment tag must be the only content on the line'; + $phpcsFile->addError($error, $commentStart); + } + + // Check for a comment description. + $short = rtrim($comment->getShortComment(), $phpcsFile->eolChar); + if (trim($short) === '') + { + $error = 'Missing short description in class doc comment'; + $phpcsFile->addError($error, $commentStart); + + return; + } + + // No extra newline before short description. + $newlineCount = 0; + $newlineSpan = strspn($short, $phpcsFile->eolChar); + if ($short !== '' && $newlineSpan > 0) + { + $line = ($newlineSpan > 1) ? 'newlines' : 'newline'; + $error = "Extra $line found before class comment short description"; + $phpcsFile->addError($error, ($commentStart + 1)); + } + + // Exactly one blank line before tags. + $tags = $this->commentParser->getTagOrders(); + if (count($tags) > 1) + { + $newlineSpan = $comment->getNewlineAfter(); + if ($newlineSpan !== 2) + { + $error = 'There must be exactly one blank line before the tags in class comment'; + if ($long !== '') + { + $newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1); + } + + $phpcsFile->addError($error, ($commentStart + $newlineCount)); + $short = rtrim($short, $phpcsFile->eolChar.' '); + } + } + + // Check for unknown/deprecated tags. + $unknownTags = $this->commentParser->getUnknown(); + foreach ($unknownTags as $errorTag) + { + $error = "@$errorTag[tag] tag is not allowed in class comment"; + $phpcsFile->addWarning($error, ($commentStart + $errorTag['line'])); + + return; + } + + // Check each tag. + $this->processTags($commentStart, $commentEnd); + } + protected function processTags($commentStart, $commentEnd) { $foundTags = $this->commentParser->getTagOrders(); diff --git a/data/CodingStandard/OpenPNE3/Sniffs/Functions/FunctionCallSignatureSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/Functions/FunctionCallSignatureSniff.php new file mode 100644 index 000000000..b59f0c6b3 --- /dev/null +++ b/data/CodingStandard/OpenPNE3/Sniffs/Functions/FunctionCallSignatureSniff.php @@ -0,0 +1,23 @@ + + */ +class OpenPNE3_Sniffs_Functions_FunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff +{ + public function processMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) + { + return null; + } +} diff --git a/data/CodingStandard/OpenPNE3/Sniffs/NamingConventions/ValidClassNameSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/NamingConventions/ValidClassNameSniff.php index 0b3a420d9..6043ea735 100644 --- a/data/CodingStandard/OpenPNE3/Sniffs/NamingConventions/ValidClassNameSniff.php +++ b/data/CodingStandard/OpenPNE3/Sniffs/NamingConventions/ValidClassNameSniff.php @@ -18,9 +18,22 @@ class OpenPNE3_Sniffs_NamingConventions_ValidClassNameSniff extends Squiz_Sniffs { public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { - if (false !== strpos($phpcsFile->getFilename(), 'model') - || false !== strpos($phpcsFile->getFilename(), 'form') - || false !== strpos($phpcsFile->getFilename(), 'filter') + if ( + // sfOpenPNE... classes are already replaced to op... classes + // But these are still in the source code for BC reason. + false !== strpos($phpcsFile->getFilename(), 'sfOpenPNE') + + // don't check auto-generated files + || false !== strpos($phpcsFile->getFilename(), 'model') + || false !== strpos($phpcsFile->getFilename(), 'form') + || false !== strpos($phpcsFile->getFilename(), 'filter') + + // myUser.class.php should be excluded + || false !== strpos($phpcsFile->getFilename(), 'myUser.class.php') + // actioon classes should be excluded + || false !== strpos($phpcsFile->getFilename(), 'actions.class.php') + || false !== strpos($phpcsFile->getFilename(), 'components.class.php') + || false !== strpos($phpcsFile->getFilename(), 'Action.class.php') ) { return null; diff --git a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php deleted file mode 100644 index d89d61dda..000000000 --- a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -class OpenPNE3_Sniffs_WhiteSpace_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff -{ - protected function getPatterns() - { - return array( - 'tryEOL *{EOL...}EOL *catch (...)EOL *{EOL', - 'doEOL *{EOL...}EOL *while (...);EOL', - 'while (...)EOL *{EOL', - 'for (...)EOL *{EOL', - 'if (...)EOL *{EOL', - 'foreach (...)EOL *{EOL', - '} *EOLelseif (...)EOL *{EOL', - '} *EOLelseEOL *{EOL', - ); - } -} diff --git a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php deleted file mode 100644 index c79cc5c90..000000000 --- a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -class OpenPNE3_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff -{ - protected $indent = 2; -} diff --git a/data/CodingStandard/OpenPNE3/ruleset.xml b/data/CodingStandard/OpenPNE3/ruleset.xml new file mode 100644 index 000000000..0e580d7a4 --- /dev/null +++ b/data/CodingStandard/OpenPNE3/ruleset.xml @@ -0,0 +1,31 @@ + + + OpenPNE3 Coding Standard + + ^(cache|config|data|plugins|test|web)/ + ^lib/plugins/ + ^lib/vendor/ + ^lib/(filter|form|model)/doctrine/base/ + ^lib/(filter|form|model)/doctrine/op.+Plugin/ + (^|/)templates/ + + + + + + + + + + + + + + + + + + + + +