forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More changes to comment sniffs in the Squiz standard to make them mor…
…e generic by pushing some product-specific code to the MySource standard git-svn-id: http://svn.php.net/repository/pear/packages/PHP_CodeSniffer/trunk@302088 c90b9560-bf6c-de11-be94-00142212c4b1
- Loading branch information
Showing
16 changed files
with
580 additions
and
357 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
CodeSniffer/Standards/MySource/Sniffs/Commenting/FunctionCommentSniff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* Parses and verifies the doc comments for functions. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @author Marc McIntyre <[email protected]> | ||
* @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: FunctionCommentSniff.php 302056 2010-08-10 03:47:09Z squiz $ | ||
* @link http://pear.php.net/package/PHP_CodeSniffer | ||
*/ | ||
|
||
if (class_exists('Squiz_Sniffs_Commenting_FunctionCommentSniff', true) === false) { | ||
$error = 'Class Squiz_Sniffs_Commenting_FunctionCommentSniff not found'; | ||
throw new PHP_CodeSniffer_Exception($error); | ||
} | ||
|
||
/** | ||
* Parses and verifies the doc comments for functions. | ||
* | ||
* Same as the Squiz standard, but adds support for API tags. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence | ||
* @version Release: @package_version@ | ||
* @link http://pear.php.net/package/PHP_CodeSniffer | ||
*/ | ||
class MySource_Sniffs_Commenting_FunctionCommentSniff extends Squiz_Sniffs_Commenting_FunctionCommentSniff | ||
{ | ||
|
||
|
||
/** | ||
* Process a list of unknown tags. | ||
* | ||
* @param int $commentStart The position in the stack where the comment started. | ||
* @param int $commentEnd The position in the stack where the comment ended. | ||
* | ||
* @return void | ||
*/ | ||
protected function processUnknownTags($commentStart, $commentEnd) | ||
{ | ||
$unknownTags = $this->commentParser->getUnknown(); | ||
$words = $this->commentParser->getWords(); | ||
$hasApiTag = false; | ||
foreach ($unknownTags as $errorTag) { | ||
$pos = $errorTag['pos']; | ||
if ($errorTag['tag'] === 'api') { | ||
if ($hasApiTag === true) { | ||
// We've come across an API tag already, which means | ||
// we were not the first tag in the API list. | ||
$error = 'The @api tag must come first in the @api tag list in a function comment'; | ||
$this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiNotFirst'); | ||
} | ||
|
||
$hasApiTag = true; | ||
|
||
// There needs to be a blank line before the @api tag. | ||
// So expect a single space before the tag, then 2 newlines before | ||
// that, then some content. | ||
if (trim($words[($pos - 2)]) !== '' | ||
|| strpos($words[($pos - 2)], $this->currentFile->eolChar) === false | ||
|| strpos($words[($pos - 3)], $this->currentFile->eolChar) === false | ||
|| trim($words[($pos - 4)]) === '' | ||
) { | ||
$error = 'There must be one blank line before the @api tag in a function comment'; | ||
$this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiSpacing'); | ||
} | ||
} else if (substr($errorTag['tag'], 0, 4) === 'api-') { | ||
$hasApiTag = true; | ||
if (trim($words[($pos - 2)]) !== '' | ||
|| strpos($words[($pos - 2)], $this->currentFile->eolChar) === false | ||
|| trim($words[($pos - 3)]) === '' | ||
) { | ||
$error = 'There must be no blank line before the @%s tag in a function comment'; | ||
$data = array($errorTag['tag']); | ||
$this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiTagSpacing', $data); | ||
} | ||
} else { | ||
$error = '@%s tag is not allowed in function comment'; | ||
$data = array($errorTag['tag']); | ||
$this->currentFile->addWarning($error, ($commentStart + $errorTag['line']), 'TagNotAllowed', $data); | ||
} | ||
} | ||
|
||
if ($hasApiTag === true) { | ||
// API tags must be the last tags in a function comment. | ||
$order = $this->commentParser->getTagOrders(); | ||
$lastTag = array_pop($order); | ||
if ($lastTag !== 'api' | ||
&& substr($lastTag, 0, 4) !== 'api-' | ||
) { | ||
$error = 'The @api tags must be the last tags in a function comment'; | ||
$this->currentFile->addError($error, $commentEnd, 'ApiNotLast'); | ||
} | ||
} | ||
|
||
}//end processUnknownTags | ||
|
||
|
||
}//end class | ||
|
||
?> |
71 changes: 71 additions & 0 deletions
71
CodeSniffer/Standards/MySource/Tests/Commenting/FunctionCommentUnitTest.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Short content. | ||
* | ||
* @return void | ||
* | ||
* @api read | ||
* @api-privilege asset.read.content | ||
* @api-mustlock false | ||
*/ | ||
private function functionCall() {} | ||
|
||
/** | ||
* Short content. | ||
* | ||
* @return void | ||
* | ||
* @api read | ||
*/ | ||
private function functionCall() {} | ||
|
||
/** | ||
* Short content. | ||
* | ||
* @api read | ||
* | ||
* @return void | ||
*/ | ||
private function functionCall() {} | ||
|
||
/** | ||
* Short content. | ||
* | ||
* @return void | ||
* | ||
* @api-privilege asset.read.content | ||
* @api read | ||
* @api-mustlock false | ||
*/ | ||
private function functionCall() {} | ||
|
||
/** | ||
* Short content. | ||
* | ||
* @return void | ||
* | ||
* @api read | ||
* | ||
* @api-privilege asset.read.content | ||
* @api-mustlock false | ||
*/ | ||
private function functionCall() {} | ||
|
||
/** | ||
* Short content. | ||
* | ||
* @return void | ||
* @api read | ||
*/ | ||
private function functionCall() {} | ||
|
||
/** | ||
* Test unknown tags. | ||
* | ||
* @return void | ||
* @since read | ||
* @hello hello | ||
* @package Test | ||
*/ | ||
private function functionCall() {} | ||
?> |
73 changes: 73 additions & 0 deletions
73
CodeSniffer/Standards/MySource/Tests/Commenting/FunctionCommentUnitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Unit test class for FunctionCommentSniff. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @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: FunctionCommentUnitTest.php 292513 2009-12-23 00:41:20Z squiz $ | ||
* @link http://pear.php.net/package/PHP_CodeSniffer | ||
*/ | ||
|
||
/** | ||
* Unit test class for FunctionCommentSniff. | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence | ||
* @version Release: @package_version@ | ||
* @link http://pear.php.net/package/PHP_CodeSniffer | ||
*/ | ||
class MySource_Tests_Commenting_FunctionCommentUnitTest extends AbstractSniffUnitTest | ||
{ | ||
|
||
|
||
/** | ||
* Returns the lines where errors should occur. | ||
* | ||
* The key of the array should represent the line number and the value | ||
* should represent the number of errors that should occur on that line. | ||
* | ||
* @return array(int => int) | ||
*/ | ||
public function getErrorList() | ||
{ | ||
return array( | ||
28 => 1, | ||
36 => 1, | ||
37 => 2, | ||
49 => 1, | ||
58 => 1, | ||
65 => 1, | ||
); | ||
|
||
}//end getErrorList() | ||
|
||
|
||
/** | ||
* Returns the lines where warnings should occur. | ||
* | ||
* The key of the array should represent the line number and the value | ||
* should represent the number of warnings that should occur on that line. | ||
* | ||
* @return array(int => int) | ||
*/ | ||
public function getWarningList() | ||
{ | ||
return array( | ||
67 => 1, | ||
68 => 1, | ||
); | ||
|
||
}//end getWarningList() | ||
|
||
|
||
}//end class | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.