Skip to content

Commit c48e4d4

Browse files
committed
RequireTernaryOperatorSniff: Improved fixer
1 parent 5416644 commit c48e4d4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/RequireTernaryOperatorSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ private function checkIfWithReturns(File $phpcsFile, int $ifPointer, int $elsePo
116116

117117
$phpcsFile->fixer->beginChangeset();
118118
$phpcsFile->fixer->replaceToken($ifPointer, 'return');
119+
if ($ifPointer + 1 === $tokens[$ifPointer]['parenthesis_opener']) {
120+
$phpcsFile->fixer->addContent($ifPointer, ' ');
121+
}
119122
$phpcsFile->fixer->replaceToken($tokens[$ifPointer]['parenthesis_opener'], '');
120123
$phpcsFile->fixer->replaceToken($tokens[$ifPointer]['parenthesis_closer'], ' ? ');
121124

tests/Sniffs/ControlStructures/data/requireTernaryOperatorErrors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
function () {
4-
if (true) {
4+
if(true) {
55
return true;
66
} else {
77
return false;

0 commit comments

Comments
 (0)