Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions data/CodingStandard/OpenPNE3/OpenPNE3CodingStandard.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
168 changes: 168 additions & 0 deletions data/CodingStandard/OpenPNE3/Sniffs/Commenting/ClassCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* OpenPNE3_Sniffs_Functions_FunctionCallSignatureSniff
*
* @package OpenPNE
* @author Kousuke Ebihara <ebihara@php.net>
*/
class OpenPNE3_Sniffs_Functions_FunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff
{
public function processMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

This file was deleted.

31 changes: 31 additions & 0 deletions data/CodingStandard/OpenPNE3/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<ruleset name="OpenPNE3 Coding Standard">
<description>OpenPNE3 Coding Standard</description>

<exclude-pattern type="relative">^(cache|config|data|plugins|test|web)/</exclude-pattern>
<exclude-pattern type="relative">^lib/plugins/</exclude-pattern>
<exclude-pattern type="relative">^lib/vendor/</exclude-pattern>
<exclude-pattern type="relative">^lib/(filter|form|model)/doctrine/base/</exclude-pattern>
<exclude-pattern type="relative">^lib/(filter|form|model)/doctrine/op.+Plugin/</exclude-pattern>
<exclude-pattern type="relative">(^|/)templates/</exclude-pattern>

<rule ref="Zend">
<exclude name="PEAR.ControlStructures.ControlSignature"/>
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace"/>
<exclude name="PEAR.Functions.FunctionCallSignature"/>
<exclude name="Zend.NamingConventions.ValidVariableName"/>
<exclude name="Squiz.Functions.GlobalFunction"/>
</rule>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Squiz.Scope.MemberVarScope"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
</ruleset>