mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
add UnifiedDiffOutputBuilder with full context
This commit is contained in:
parent
f17aad4c1a
commit
3ef5021562
@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\ConsoleDiffer\Diff\Output;
|
||||
|
||||
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
|
||||
/**
|
||||
* Creates @see UnifiedDiffOutputBuilder with "$contextLines = 1000;"
|
||||
*/
|
||||
final class CompleteUnifiedDiffOutputBuilderFactory
|
||||
{
|
||||
/**
|
||||
* @var PrivatesAccessor
|
||||
*/
|
||||
private $privatesAccessor;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->privatesAccessor = new PrivatesAccessor();
|
||||
}
|
||||
|
||||
public function create(): UnifiedDiffOutputBuilder
|
||||
{
|
||||
$unifiedDiffOutputBuilder = new UnifiedDiffOutputBuilder('');
|
||||
|
||||
$this->privatesAccessor->setPrivateProperty($unifiedDiffOutputBuilder, 'contextLines', 1000);
|
||||
|
||||
return $unifiedDiffOutputBuilder;
|
||||
}
|
||||
}
|
@ -42,20 +42,21 @@ final class MarkdownDifferAndFormatter
|
||||
return '';
|
||||
}
|
||||
|
||||
// @todo here we need complete diff with all the code
|
||||
$diff = $this->markdownDiffer->diff($old, $new);
|
||||
|
||||
// remove first 3 lines, just meta info added by StrictUnifiedDiffOutputBuilder
|
||||
$diff = preg_replace("/^(.*\n){1}/", "", $diff);
|
||||
|
||||
$diff = $this->removeTrailingWhitespaces($diff);
|
||||
|
||||
// impossible to configure - removed manually
|
||||
return substr($diff, strlen('@@ @@ '));
|
||||
return $diff;
|
||||
}
|
||||
|
||||
private function removeTrailingWhitespaces(string $diff): string
|
||||
{
|
||||
$diff = preg_replace('#\n( )\n#', PHP_EOL . PHP_EOL, $diff);
|
||||
$diff = preg_replace('#\n( ){1,}\n#', PHP_EOL . PHP_EOL, $diff);
|
||||
|
||||
$diff = preg_replace('#( )\n#', PHP_EOL, $diff);
|
||||
$diff = preg_replace('#( ){1,}\n#', PHP_EOL, $diff);
|
||||
|
||||
return rtrim($diff);
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ services:
|
||||
# makrdown differ
|
||||
markdownDiffOutputBuilder:
|
||||
class: SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder
|
||||
arguments:
|
||||
$header: ''
|
||||
factory: ['@Rector\ConsoleDiffer\Diff\Output\CompleteUnifiedDiffOutputBuilderFactory', 'create']
|
||||
|
||||
markdownDiffer:
|
||||
class: SebastianBergmann\Diff\Differ
|
||||
|
Loading…
x
Reference in New Issue
Block a user