Skip to content

Commit

Permalink
Merge pull request #2 from barracudanetworks/bugfix/return-var-type
Browse files Browse the repository at this point in the history
Fix bool & int return types
  • Loading branch information
Andy Borek committed Nov 24, 2015
2 parents 8ad76ca + 5171666 commit 4fdaa20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
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

0 comments on commit 4fdaa20

Please sign in to comment.