Skip to content

Commit

Permalink
YodaComparisonSniff fix should not reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Jul 24, 2017
1 parent 2c6ae6f commit 2775628
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Expand Up @@ -114,7 +114,6 @@ public function process(\PHP_CodeSniffer\Files\File $phpcsFile, $comparisonToken
if (count($leftSideTokens) > 0 & count($rightSideTokens) > 0) {
$phpcsFile->fixer->beginChangeset();
$this->write($phpcsFile, $leftSideTokens, $rightSideTokens);
$phpcsFile->fixer->addContent(key($leftSideTokens), ' ');
$this->write($phpcsFile, $rightSideTokens, $leftSideTokens);
$phpcsFile->fixer->endChangeset();
}
Expand All @@ -138,9 +137,9 @@ private function write(\PHP_CodeSniffer\Files\File $phpcsFile, array $leftSideTo
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->addContent($firstLeftPointer, trim(implode('', array_map(function (array $token): string {
$phpcsFile->fixer->addContent($firstLeftPointer, implode('', array_map(function (array $token): string {
return $token['content'];
}, $rightSideTokens))));
}, $rightSideTokens)));
}

/**
Expand Down Expand Up @@ -297,7 +296,7 @@ private function trimWhitespaceTokens(array $tokens): array
}
}

foreach (array_reverse($tokens) as $pointer => $token) {
foreach (array_reverse($tokens, true) as $pointer => $token) {
if ($token['code'] === T_WHITESPACE) {
unset($tokens[$pointer]);
} else {
Expand Down
Expand Up @@ -17,10 +17,14 @@
$this->foo() === Foo::BAR;
$foo === -1;
$foo === +1;
(foo() === BAR|| (
Foo::BAR === ['test'])) ? Foo::BAR === 123.0: $foo === null;
(foo() === BAR|| (
Foo::BAR === array('test'))) ? Foo::BAR === 123.0: $foo === null;
(foo() === BAR || (
Foo::BAR === ['test']
)) ? Foo::BAR === 123.0
: $foo === null;
(foo() === BAR || (
Foo::BAR === array('test')
)) ? Foo::BAR === 123.0
: $foo === null;

if (
$foo($bar) === [Foo::BAR, Foo::BAZ] && (
Expand Down Expand Up @@ -48,11 +52,11 @@
(int) $bar === FOO;

$x = [$username === self::ADMIN_EMAIL ? self::ROLE_ADMIN : self::ROLE_CUSTOMER];
$x = [$username === self::ADMIN_EMAIL? self::ROLE_ADMIN : self::ROLE_CUSTOMER];
$x = [$username === self::ADMIN_EMAIL ? self::ROLE_ADMIN : self::ROLE_CUSTOMER];
$x = array($username === self::ADMIN_EMAIL ? self::ROLE_ADMIN : self::ROLE_CUSTOMER);
$x = array($username === self::ADMIN_EMAIL ? self::ROLE_ADMIN : self::ROLE_CUSTOMER);
$x = array($username === self::ADMIN_EMAIL? self::ROLE_ADMIN : self::ROLE_CUSTOMER);

$x = array($username === array()? true : false);
$x = array($username === []? true : false);
$x = [$username === array()? true : false];
$x = [$username === []? true : false];
$x = array($username === array() ? true : false);
$x = array($username === [] ? true : false);
$x = [$username === array() ? true : false];
$x = [$username === [] ? true : false];

0 comments on commit 2775628

Please sign in to comment.