Skip to content

Commit

Permalink
Fix bool & int return types
Browse files Browse the repository at this point in the history
Going to try to get $allowedTypes registered prior to the Sniffs files
soon. Requires an upstream change though.
  • Loading branch information
johnmaguire committed Nov 23, 2015
1 parent 8ad76ca commit 5171666
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 5171666

Please sign in to comment.