diff --git a/compiler/composer.json b/compiler/composer.json index 61c3c5020c9..7fec8b6ea94 100644 --- a/compiler/composer.json +++ b/compiler/composer.json @@ -11,8 +11,9 @@ "symfony/process": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0", - "symplify/auto-bind-parameter": "^7.2", - "symplify/package-builder": "^7.2" + "symplify/console-color-diff": "^7.3", + "symplify/auto-bind-parameter": "^7.3", + "symplify/package-builder": "^7.3" }, "autoload": { "psr-4": { diff --git a/compiler/config/config.yaml b/compiler/config/config.yaml index 2ed6a4f11f8..95b2362f41d 100644 --- a/compiler/config/config.yaml +++ b/compiler/config/config.yaml @@ -13,10 +13,4 @@ services: - '../src/Exception/*' - '../src/HttpKernel/*' - Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory: null - Symfony\Component\Console\Style\SymfonyStyle: - factory: ['@Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory', 'create'] - - SebastianBergmann\Diff\Differ: null - Symfony\Component\Filesystem\Filesystem: null diff --git a/compiler/src/Composer/ComposerJsonManipulator.php b/compiler/src/Composer/ComposerJsonManipulator.php index 2bdfedc6a74..427e229c02d 100644 --- a/compiler/src/Composer/ComposerJsonManipulator.php +++ b/compiler/src/Composer/ComposerJsonManipulator.php @@ -6,8 +6,8 @@ namespace Rector\Compiler\Composer; use Nette\Utils\FileSystem as NetteFileSystem; use Nette\Utils\Json; -use Rector\Compiler\Differ\ConsoleDiffer; use Symfony\Component\Filesystem\Filesystem; +use Symplify\ConsoleColorDiff\Console\Output\ConsoleDiffer; final class ComposerJsonManipulator { diff --git a/compiler/src/Differ/ConsoleDiffer.php b/compiler/src/Differ/ConsoleDiffer.php deleted file mode 100644 index 041933c6422..00000000000 --- a/compiler/src/Differ/ConsoleDiffer.php +++ /dev/null @@ -1,43 +0,0 @@ -symfonyStyle = $symfonyStyle; - $this->differ = $differ; - $this->consoleDifferFormatter = $consoleDifferFormatter; - } - - public function diff(string $old, string $new): void - { - $diff = $this->differ->diff($old, $new); - $consoleFormatted = $this->consoleDifferFormatter->format($diff); - $this->symfonyStyle->writeln($consoleFormatted); - } -} diff --git a/compiler/src/Differ/ConsoleDifferFormatter.php b/compiler/src/Differ/ConsoleDifferFormatter.php deleted file mode 100644 index cef95390fa7..00000000000 --- a/compiler/src/Differ/ConsoleDifferFormatter.php +++ /dev/null @@ -1,51 +0,0 @@ -template = sprintf( - ' ---------- begin diff ----------%s%%s%s ----------- end diff -----------', - PHP_EOL, - PHP_EOL - ); - } - - public function format(string $diff): string - { - return $this->formatWithTemplate($diff, $this->template); - } - - private function formatWithTemplate(string $diff, string $template): string - { - return sprintf($template, implode(PHP_EOL, array_map(function (string $string): string { - // make "+" lines green - $string = Strings::replace($string, '#^(\+.*)#', '$1'); - // make "-" lines red - $string = Strings::replace($string, '#^(\-.*)#', '$1'); - // make "@ note" lines cyan - $string = Strings::replace($string, '#^(@.*)#', '$1'); - - if ($string === ' ') { - $string = rtrim($string); - } - - return $string; - }, Strings::split(OutputFormatter::escape(rtrim($diff)), "#\n\r|\n#")))); - } -} diff --git a/composer.json b/composer.json index ba10205ac59..99cf76b0d49 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "symplify/autowire-array-parameter": "^7.3.5", "symplify/package-builder": "^7.3.5", "symplify/set-config-resolver": "^7.3.5", + "symplify/console-color-diff": "^7.3.5", "tracy/tracy": "^2.7" }, "require-dev": { diff --git a/ecs.yaml b/ecs.yaml index c601ef82e5a..4c22dcc6d68 100644 --- a/ecs.yaml +++ b/ecs.yaml @@ -1,11 +1,3 @@ -services: - Symplify\CodingStandard\Fixer\Order\MethodOrderByTypeFixer: - method_order_by_type: - Rector\Contract\Rector\PhpRectorInterface: - - 'getDefinition' - - 'getNodeTypes' - - 'refactor' - parameters: paths: - "bin" diff --git a/packages/console-differ/config/config.yaml b/packages/console-differ/config/config.yaml index 664c5bb6587..9a545d36edb 100644 --- a/packages/console-differ/config/config.yaml +++ b/packages/console-differ/config/config.yaml @@ -25,7 +25,7 @@ services: arguments: - '@diffOutputBuilder' - # makrdown differ + # markdown differ markdownDiffOutputBuilder: class: SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder factory: ['@Rector\ConsoleDiffer\Diff\Output\CompleteUnifiedDiffOutputBuilderFactory', 'create'] diff --git a/packages/console-differ/src/Console/Formatter/DiffConsoleFormatter.php b/packages/console-differ/src/Console/Formatter/DiffConsoleFormatter.php deleted file mode 100644 index c3badb140af..00000000000 --- a/packages/console-differ/src/Console/Formatter/DiffConsoleFormatter.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ -final class DiffConsoleFormatter -{ - /** - * @var string - */ - private $template; - - public function __construct() - { - $this->template = sprintf( - ' ---------- begin diff ----------%s%%s%s ----------- end diff -----------', - PHP_EOL, - PHP_EOL - ); - } - - public function format(string $diff): string - { - return $this->formatWithTemplate($diff, $this->template); - } - - private function formatWithTemplate(string $diff, string $template): string - { - return sprintf($template, implode(PHP_EOL, array_map(function (string $string): string { - // make "+" lines green - $string = Strings::replace($string, '#^(\+.*)#', '$1'); - // make "-" lines red - $string = Strings::replace($string, '#^(\-.*)#', '$1'); - // make "@ note" lines cyan - $string = Strings::replace($string, '#^(@.*)#', '$1'); - - if ($string === ' ') { - $string = rtrim($string); - } - - return $string; - }, Strings::split(OutputFormatter::escape(rtrim($diff)), "#\n\r|\n#")))); - } -} diff --git a/packages/console-differ/src/DifferAndFormatter.php b/packages/console-differ/src/DifferAndFormatter.php index d2fde595843..7db0504bacf 100644 --- a/packages/console-differ/src/DifferAndFormatter.php +++ b/packages/console-differ/src/DifferAndFormatter.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Rector\ConsoleDiffer; -use Rector\ConsoleDiffer\Console\Formatter\DiffConsoleFormatter; use SebastianBergmann\Diff\Differ; +use Symplify\ConsoleColorDiff\Console\Formatter\ColorConsoleDiffFormatter; final class DifferAndFormatter { @@ -15,14 +15,14 @@ final class DifferAndFormatter private $differ; /** - * @var DiffConsoleFormatter + * @var ColorConsoleDiffFormatter */ - private $diffConsoleFormatter; + private $colorConsoleDiffFormatter; - public function __construct(Differ $differ, DiffConsoleFormatter $diffConsoleFormatter) + public function __construct(Differ $differ, ColorConsoleDiffFormatter $colorConsoleDiffFormatter) { $this->differ = $differ; - $this->diffConsoleFormatter = $diffConsoleFormatter; + $this->colorConsoleDiffFormatter = $colorConsoleDiffFormatter; } public function diff(string $old, string $new): string @@ -42,6 +42,6 @@ final class DifferAndFormatter $diff = $this->diff($old, $new); - return $this->diffConsoleFormatter->format($diff); + return $this->colorConsoleDiffFormatter->format($diff); } } diff --git a/src/HttpKernel/RectorKernel.php b/src/HttpKernel/RectorKernel.php index d76b827f5b8..7bb065e959a 100644 --- a/src/HttpKernel/RectorKernel.php +++ b/src/HttpKernel/RectorKernel.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\Kernel; use Symplify\AutoBindParameter\DependencyInjection\CompilerPass\AutoBindParameterCompilerPass; use Symplify\AutowireArrayParameter\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPass; +use Symplify\ConsoleColorDiff\ConsoleColorDiffBundle; use Symplify\PackageBuilder\Contract\HttpKernel\ExtraConfigAwareKernelInterface; use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutoReturnFactoryCompilerPass; use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass; @@ -77,7 +78,7 @@ final class RectorKernel extends Kernel implements ExtraConfigAwareKernelInterfa */ public function registerBundles(): array { - return []; + return [new ConsoleColorDiffBundle()]; } protected function build(ContainerBuilder $containerBuilder): void