Skip to content

Commit

Permalink
Verbose diff report output has slightly changed to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Oct 8, 2019
1 parent c328457 commit 515caec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
</stability>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- Verbose diff report output has slightly changed to improve readability
-- Fully qualified class names are now replaced with sniff codes
-- Tokens being changed now display the line number they are on
- PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statement
- PSR12.Files.FileHeader now allows a hashbang line at the top of the file
- Fixed bug #2615 : Constant visibility false positive on non-class constants
Expand Down
24 changes: 17 additions & 7 deletions src/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ public function beginChangeset()
$sniff = $bt[1]['class'];
$line = $bt[0]['line'];

$sniff = Util\Common::getSniffCode($sniff);

@ob_end_clean();
echo "\t=> Changeset started by $sniff (line $line)".PHP_EOL;
echo "\t=> Changeset started by $sniff:$line".PHP_EOL;
ob_start();
}

Expand Down Expand Up @@ -434,10 +436,12 @@ public function rollbackChangeset()
$line = $bt[0]['line'];
}

$sniff = Util\Common::getSniffCode($sniff);

$numChanges = count($this->changeset);

@ob_end_clean();
echo "\t\tR: $sniff (line $line) rolled back the changeset ($numChanges changes)".PHP_EOL;
echo "\t\tR: $sniff:$line rolled back the changeset ($numChanges changes)".PHP_EOL;
echo "\t=> Changeset rolled back".PHP_EOL;
ob_start();
}
Expand Down Expand Up @@ -489,8 +493,11 @@ public function replaceToken($stackPtr, $content)
$line = $bt[0]['line'];
}

$sniff = Util\Common::getSniffCode($sniff);

$tokens = $this->currentFile->getTokens();
$type = $tokens[$stackPtr]['type'];
$tokenLine = $tokens[$stackPtr]['line'];
$oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
$newContent = Common::prepareForOutput($content);
if (trim($this->tokens[$stackPtr]) === '' && isset($this->tokens[($stackPtr + 1)]) === true) {
Expand All @@ -506,7 +513,7 @@ public function replaceToken($stackPtr, $content)

if (PHP_CODESNIFFER_VERBOSITY > 1) {
@ob_end_clean();
echo "\t\tQ: $sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
echo "\t\tQ: $sniff:$line replaced token $stackPtr ($type on line $tokenLine) \"$oldContent\" => \"$newContent\"".PHP_EOL;
ob_start();
}

Expand All @@ -532,8 +539,8 @@ public function replaceToken($stackPtr, $content)
$loop = $this->oldTokenValues[$stackPtr]['loop'];

@ob_end_clean();
echo "$indent**** $sniff (line $line) has possible conflict with another sniff on loop $loop; caused by the following change ****".PHP_EOL;
echo "$indent**** replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\" ****".PHP_EOL;
echo "$indent**** $sniff:$line has possible conflict with another sniff on loop $loop; caused by the following change ****".PHP_EOL;
echo "$indent**** replaced token $stackPtr ($type on line $tokenLine) \"$oldContent\" => \"$newContent\" ****".PHP_EOL;
}

if ($this->oldTokenValues[$stackPtr]['loop'] >= ($this->loops - 1)) {
Expand Down Expand Up @@ -569,7 +576,7 @@ public function replaceToken($stackPtr, $content)
ob_end_clean();
}

echo "$indent$sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
echo "$indent$sniff:$line replaced token $stackPtr ($type on line $tokenLine) \"$oldContent\" => \"$newContent\"".PHP_EOL;
ob_start();
}

Expand Down Expand Up @@ -601,8 +608,11 @@ public function revertToken($stackPtr)
$line = $bt[0]['line'];
}

$sniff = Util\Common::getSniffCode($sniff);

$tokens = $this->currentFile->getTokens();
$type = $tokens[$stackPtr]['type'];
$tokenLine = $tokens[$stackPtr]['line'];
$oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
$newContent = Common::prepareForOutput($this->fixedTokens[$stackPtr]);
if (trim($this->tokens[$stackPtr]) === '' && isset($tokens[($stackPtr + 1)]) === true) {
Expand All @@ -624,7 +634,7 @@ public function revertToken($stackPtr)
}

@ob_end_clean();
echo "$indent$sniff (line $line) reverted token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
echo "$indent$sniff:$line reverted token $stackPtr ($type on line $tokenLine) \"$oldContent\" => \"$newContent\"".PHP_EOL;
ob_start();
}

Expand Down

0 comments on commit 515caec

Please sign in to comment.