Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bool & int return types #2

Merged
merged 1 commit into from
Nov 24, 2015
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
*/
class Barracuda_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff
{
protected $customAllowedTypes = array('bool', 'int');
protected $allowedTypes = array(
'int',
'bool',
);

public function __construct()
{
PHP_CodeSniffer::$allowedTypes = array_merge(PHP_CodeSniffer::$allowedTypes, $this->allowedTypes);
}

/**
* Process the return comment of this function comment.
Expand Down Expand Up @@ -81,13 +89,6 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
$suggestedName = PHP_CodeSniffer::suggestType($typeName);
if (in_array($suggestedName, $suggestedNames) === false) {
$suggestedNames[] = $suggestedName;
if ($suggestedName == 'boolean') {
$suggestedNames[] = 'bool';
}

if ($suggestedName == 'integer') {
$suggestedNames[] = 'int';
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@

class Barracuda_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
{
protected $customAllowedTypes = array('bool', 'int');
protected $allowedTypes = array(
'bool',
'int',
);

public function __construct()
{
PHP_CodeSniffer::$allowedTypes = array_merge(PHP_CodeSniffer::$allowedTypes, $this->allowedTypes);
}

/**
* Called to process class member vars.
Expand Down Expand Up @@ -120,7 +128,7 @@ public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

$varType = $tokens[($foundVar + 2)]['content'];
$suggestedType = PHP_CodeSniffer::suggestType($varType);
if ($varType !== $suggestedType && !in_array($varType, $this->customAllowedTypes)) {
if ($varType !== $suggestedType) {
$error = 'Expected "%s" but found "%s" for @var tag in member variable comment';
$data = array(
$suggestedType,
Expand Down