Skip to content

Commit

Permalink
INDEV-9312 Invert current code sniffer rule to prefer short form over…
Browse files Browse the repository at this point in the history
… long form
  • Loading branch information
CMalvika committed Jan 17, 2018
1 parent 725ef89 commit cb7f279
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/InterNations/Sniffs/Syntax/DocBlockTypesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
class DocBlockTypesSniff implements Sniff
{
private static $typeMap = [
'bool' => 'boolean',
'real' => 'float',
'boolean' => 'bool',
'real' => 'float',
'double' => 'float',
'binary' => 'string',
'int' => 'integer',
'void' => 'null',
'$this' => 'self',
'this' => 'self',
'integer' => 'int',
'void' => 'null',
'$this' => 'self',
'this' => 'self',
];

public function register()
Expand All @@ -24,6 +24,7 @@ public function register()

public function process(File $file, $stackPtr)
{
$tokens = $file->getTokens();
$content = $file->getTokensAsString($stackPtr, 3);
$regex = '/@(?<annotation>var|param|return)\s+(?<types>[^\s]+)(?:\s+|$)/xi';

Expand All @@ -37,7 +38,7 @@ public function process(File $file, $stackPtr)
continue;
}

$file->addError(
$file->addFixableError(
sprintf(
'Found "@%1$s %2$s", expected "@%1$s %3$s"',
$matches['annotation'],
Expand All @@ -47,6 +48,12 @@ public function process(File $file, $stackPtr)
$stackPtr,
'ShortDocCommentTypes'
);

$commentStrPtr = $file->findNext([T_WHITESPACE, T_DOC_COMMENT_WHITESPACE], ($stackPtr + 1), null, true);

$file->fixer->beginChangeset();
$file->fixer->replaceToken($commentStrPtr, str_replace($type, static::$typeMap[$type], $tokens[$commentStrPtr]['content']));
$file->fixer->endChangeset();
}
}
}

0 comments on commit cb7f279

Please sign in to comment.