Skip to content

Commit

Permalink
Squiz/BlockComment: minor efficiency fixes
Browse files Browse the repository at this point in the history
Don't duplicate function calls already made.
  • Loading branch information
jrfnl committed Feb 27, 2018
1 parent c24f544 commit a15dd0a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function process(File $phpcsFile, $stackPtr)
$padding = str_repeat(' ', $expected);
}

$phpcsFile->fixer->replaceToken($commentLines[1], $padding.ltrim($content));
$phpcsFile->fixer->replaceToken($commentLines[1], $padding.$commentText);
}
}//end if

Expand Down Expand Up @@ -300,20 +300,19 @@ public function process(File $phpcsFile, $stackPtr)
$padding = str_repeat(' ', $expected);
}

$phpcsFile->fixer->replaceToken($line, $padding.ltrim($tokens[$line]['content']));
$phpcsFile->fixer->replaceToken($line, $padding.$commentText);
}
}//end if
}//end foreach

// Finally, test the last line is correct.
$lastIndex = (count($commentLines) - 1);
$content = trim($tokens[$commentLines[$lastIndex]]['content']);
if ($content !== '*/' && $content !== '**/') {
$lastIndex = (count($commentLines) - 1);
$content = $tokens[$commentLines[$lastIndex]]['content'];
$commentText = ltrim($content);
if ($commentText !== '*/' && $commentText !== '**/') {
$error = 'Comment closer must be on a new line';
$phpcsFile->addError($error, $commentLines[$lastIndex], 'CloserSameLine');
} else {
$content = $tokens[$commentLines[$lastIndex]]['content'];
$commentText = ltrim($content);
$leadingSpace = (strlen($content) - strlen($commentText));

$expected = ($starColumn - 1);
Expand Down

0 comments on commit a15dd0a

Please sign in to comment.