mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-06 03:10:50 +00:00
Updated Rector to commit 750713625e27e07175e4c7144802fb623422c036
750713625e
Add dump_node() helper function (#5696)
This commit is contained in:
parent
5cc97f5690
commit
7da00fc128
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '643814dc92ceacb159adbac79c1ab6fb6e5cc2ee';
|
public const PACKAGE_VERSION = '750713625e27e07175e4c7144802fb623422c036';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2024-03-06 20:34:50';
|
public const RELEASE_DATE = '2024-03-06 20:53:31';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\Console\Command;
|
namespace Rector\Console\Command;
|
||||||
|
|
||||||
use RectorPrefix202403\Nette\Utils\Strings;
|
|
||||||
use Rector\CustomRules\SimpleNodeDumper;
|
|
||||||
use Rector\PhpParser\Parser\SimplePhpParser;
|
use Rector\PhpParser\Parser\SimplePhpParser;
|
||||||
|
use Rector\Util\NodePrinter;
|
||||||
use RectorPrefix202403\Symfony\Component\Console\Command\Command;
|
use RectorPrefix202403\Symfony\Component\Console\Command\Command;
|
||||||
use RectorPrefix202403\Symfony\Component\Console\Input\InputInterface;
|
use RectorPrefix202403\Symfony\Component\Console\Input\InputInterface;
|
||||||
use RectorPrefix202403\Symfony\Component\Console\Input\InputOption;
|
use RectorPrefix202403\Symfony\Component\Console\Input\InputOption;
|
||||||
|
@ -15,30 +14,26 @@ use RectorPrefix202403\Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
final class DetectNodeCommand extends Command
|
final class DetectNodeCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @readonly
|
|
||||||
* @var \Symfony\Component\Console\Style\SymfonyStyle
|
|
||||||
*/
|
|
||||||
private $symfonyStyle;
|
|
||||||
/**
|
/**
|
||||||
* @readonly
|
* @readonly
|
||||||
* @var \Rector\PhpParser\Parser\SimplePhpParser
|
* @var \Rector\PhpParser\Parser\SimplePhpParser
|
||||||
*/
|
*/
|
||||||
private $simplePhpParser;
|
private $simplePhpParser;
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @readonly
|
||||||
* @see https://regex101.com/r/Fe8n73/1
|
* @var \Rector\Util\NodePrinter
|
||||||
*/
|
*/
|
||||||
private const CLASS_NAME_REGEX = '#(?<class_name>PhpParser(.*?))\\(#ms';
|
private $nodePrinter;
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @readonly
|
||||||
* @see https://regex101.com/r/uQFuvL/1
|
* @var \Symfony\Component\Console\Style\SymfonyStyle
|
||||||
*/
|
*/
|
||||||
private const PROPERTY_KEY_REGEX = '#(?<key>[\\w\\d]+)\\:#';
|
private $symfonyStyle;
|
||||||
public function __construct(SymfonyStyle $symfonyStyle, SimplePhpParser $simplePhpParser)
|
public function __construct(SimplePhpParser $simplePhpParser, NodePrinter $nodePrinter, SymfonyStyle $symfonyStyle)
|
||||||
{
|
{
|
||||||
$this->symfonyStyle = $symfonyStyle;
|
|
||||||
$this->simplePhpParser = $simplePhpParser;
|
$this->simplePhpParser = $simplePhpParser;
|
||||||
|
$this->nodePrinter = $nodePrinter;
|
||||||
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
protected function configure() : void
|
protected function configure() : void
|
||||||
|
@ -60,17 +55,6 @@ final class DetectNodeCommand extends Command
|
||||||
$this->askQuestionAndDumpNode();
|
$this->askQuestionAndDumpNode();
|
||||||
return self::SUCCESS;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
private function addConsoleColors(string $contents) : string
|
|
||||||
{
|
|
||||||
// decorate class names
|
|
||||||
$colorContents = Strings::replace($contents, self::CLASS_NAME_REGEX, static function (array $match) : string {
|
|
||||||
return '<fg=green>' . $match['class_name'] . '</>(';
|
|
||||||
});
|
|
||||||
// decorate keys
|
|
||||||
return Strings::replace($colorContents, self::PROPERTY_KEY_REGEX, static function (array $match) : string {
|
|
||||||
return '<fg=yellow>' . $match['key'] . '</>:';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
private function askQuestionAndDumpNode() : void
|
private function askQuestionAndDumpNode() : void
|
||||||
{
|
{
|
||||||
$question = new Question('Write short PHP code snippet');
|
$question = new Question('Write short PHP code snippet');
|
||||||
|
@ -81,10 +65,6 @@ final class DetectNodeCommand extends Command
|
||||||
$this->symfonyStyle->warning('Provide valid PHP code');
|
$this->symfonyStyle->warning('Provide valid PHP code');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$dumpedNodesContents = SimpleNodeDumper::dump($nodes);
|
$this->nodePrinter->printNodes($nodes);
|
||||||
// colorize
|
|
||||||
$colorContents = $this->addConsoleColors($dumpedNodesContents);
|
|
||||||
$this->symfonyStyle->writeln($colorContents);
|
|
||||||
$this->symfonyStyle->newLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
53
src/Util/NodePrinter.php
Normal file
53
src/Util/NodePrinter.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare (strict_types=1);
|
||||||
|
namespace Rector\Util;
|
||||||
|
|
||||||
|
use RectorPrefix202403\Nette\Utils\Strings;
|
||||||
|
use PhpParser\Node;
|
||||||
|
use Rector\CustomRules\SimpleNodeDumper;
|
||||||
|
use RectorPrefix202403\Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
final class NodePrinter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @var \Symfony\Component\Console\Style\SymfonyStyle
|
||||||
|
*/
|
||||||
|
private $symfonyStyle;
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
* @see https://regex101.com/r/Fe8n73/1
|
||||||
|
*/
|
||||||
|
private const CLASS_NAME_REGEX = '#(?<class_name>PhpParser(.*?))\\(#ms';
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
* @see https://regex101.com/r/uQFuvL/1
|
||||||
|
*/
|
||||||
|
private const PROPERTY_KEY_REGEX = '#(?<key>[\\w\\d]+)\\:#';
|
||||||
|
public function __construct(SymfonyStyle $symfonyStyle)
|
||||||
|
{
|
||||||
|
$this->symfonyStyle = $symfonyStyle;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param Node|Node[] $nodes
|
||||||
|
*/
|
||||||
|
public function printNodes($nodes) : void
|
||||||
|
{
|
||||||
|
$dumpedNodesContents = SimpleNodeDumper::dump($nodes);
|
||||||
|
// colorize
|
||||||
|
$colorContents = $this->addConsoleColors($dumpedNodesContents);
|
||||||
|
$this->symfonyStyle->writeln($colorContents);
|
||||||
|
$this->symfonyStyle->newLine();
|
||||||
|
}
|
||||||
|
private function addConsoleColors(string $contents) : string
|
||||||
|
{
|
||||||
|
// decorate class names
|
||||||
|
$colorContents = Strings::replace($contents, self::CLASS_NAME_REGEX, static function (array $match) : string {
|
||||||
|
return '<fg=green>' . $match['class_name'] . '</>(';
|
||||||
|
});
|
||||||
|
// decorate keys
|
||||||
|
return Strings::replace($colorContents, self::PROPERTY_KEY_REGEX, static function (array $match) : string {
|
||||||
|
return '<fg=yellow>' . $match['key'] . '</>:';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,8 +3,12 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace RectorPrefix202403;
|
namespace RectorPrefix202403;
|
||||||
|
|
||||||
|
use RectorPrefix202403\Illuminate\Container\Container;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\PrettyPrinter\Standard;
|
use PhpParser\PrettyPrinter\Standard;
|
||||||
|
use Rector\Console\Style\SymfonyStyleFactory;
|
||||||
|
use Rector\Util\NodePrinter;
|
||||||
|
use RectorPrefix202403\Symfony\Component\Console\Output\OutputInterface;
|
||||||
if (!\function_exists('print_node')) {
|
if (!\function_exists('print_node')) {
|
||||||
/**
|
/**
|
||||||
* @param Node|Node[] $node
|
* @param Node|Node[] $node
|
||||||
|
@ -19,3 +23,18 @@ if (!\function_exists('print_node')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!\function_exists('dump_node')) {
|
||||||
|
/**
|
||||||
|
* @param Node|Node[] $node
|
||||||
|
*/
|
||||||
|
function dump_node($node) : void
|
||||||
|
{
|
||||||
|
$symfonyStyle = Container::getInstance()->make(SymfonyStyleFactory::class)->create();
|
||||||
|
// we turn up the verbosity so it's visible in tests overriding the
|
||||||
|
// default which is to be quite during tests
|
||||||
|
$symfonyStyle->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
|
||||||
|
$symfonyStyle->newLine();
|
||||||
|
$nodePrinter = new NodePrinter($symfonyStyle);
|
||||||
|
$nodePrinter->printNodes($node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2430,6 +2430,7 @@ return array(
|
||||||
'Rector\\Util\\FileHasher' => $baseDir . '/src/Util/FileHasher.php',
|
'Rector\\Util\\FileHasher' => $baseDir . '/src/Util/FileHasher.php',
|
||||||
'Rector\\Util\\MemoryLimiter' => $baseDir . '/src/Util/MemoryLimiter.php',
|
'Rector\\Util\\MemoryLimiter' => $baseDir . '/src/Util/MemoryLimiter.php',
|
||||||
'Rector\\Util\\NewLineSplitter' => $baseDir . '/src/Util/NewLineSplitter.php',
|
'Rector\\Util\\NewLineSplitter' => $baseDir . '/src/Util/NewLineSplitter.php',
|
||||||
|
'Rector\\Util\\NodePrinter' => $baseDir . '/src/Util/NodePrinter.php',
|
||||||
'Rector\\Util\\PhpVersionFactory' => $baseDir . '/src/Util/PhpVersionFactory.php',
|
'Rector\\Util\\PhpVersionFactory' => $baseDir . '/src/Util/PhpVersionFactory.php',
|
||||||
'Rector\\Util\\Reflection\\PrivatesAccessor' => $baseDir . '/src/Util/Reflection/PrivatesAccessor.php',
|
'Rector\\Util\\Reflection\\PrivatesAccessor' => $baseDir . '/src/Util/Reflection/PrivatesAccessor.php',
|
||||||
'Rector\\Util\\StringUtils' => $baseDir . '/src/Util/StringUtils.php',
|
'Rector\\Util\\StringUtils' => $baseDir . '/src/Util/StringUtils.php',
|
||||||
|
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
|
@ -2649,6 +2649,7 @@ class ComposerStaticInit2d887a2f87c676eb32b3e04612865e54
|
||||||
'Rector\\Util\\FileHasher' => __DIR__ . '/../..' . '/src/Util/FileHasher.php',
|
'Rector\\Util\\FileHasher' => __DIR__ . '/../..' . '/src/Util/FileHasher.php',
|
||||||
'Rector\\Util\\MemoryLimiter' => __DIR__ . '/../..' . '/src/Util/MemoryLimiter.php',
|
'Rector\\Util\\MemoryLimiter' => __DIR__ . '/../..' . '/src/Util/MemoryLimiter.php',
|
||||||
'Rector\\Util\\NewLineSplitter' => __DIR__ . '/../..' . '/src/Util/NewLineSplitter.php',
|
'Rector\\Util\\NewLineSplitter' => __DIR__ . '/../..' . '/src/Util/NewLineSplitter.php',
|
||||||
|
'Rector\\Util\\NodePrinter' => __DIR__ . '/../..' . '/src/Util/NodePrinter.php',
|
||||||
'Rector\\Util\\PhpVersionFactory' => __DIR__ . '/../..' . '/src/Util/PhpVersionFactory.php',
|
'Rector\\Util\\PhpVersionFactory' => __DIR__ . '/../..' . '/src/Util/PhpVersionFactory.php',
|
||||||
'Rector\\Util\\Reflection\\PrivatesAccessor' => __DIR__ . '/../..' . '/src/Util/Reflection/PrivatesAccessor.php',
|
'Rector\\Util\\Reflection\\PrivatesAccessor' => __DIR__ . '/../..' . '/src/Util/Reflection/PrivatesAccessor.php',
|
||||||
'Rector\\Util\\StringUtils' => __DIR__ . '/../..' . '/src/Util/StringUtils.php',
|
'Rector\\Util\\StringUtils' => __DIR__ . '/../..' . '/src/Util/StringUtils.php',
|
||||||
|
|
1
vendor/scoper-autoload.php
vendored
1
vendor/scoper-autoload.php
vendored
|
@ -35,6 +35,7 @@ humbug_phpscoper_expose_class('Product', 'RectorPrefix202403\Product');
|
||||||
|
|
||||||
// Function aliases. For more information see:
|
// Function aliases. For more information see:
|
||||||
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
|
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
|
||||||
|
if (!function_exists('dump_node')) { function dump_node() { return \RectorPrefix202403\dump_node(...func_get_args()); } }
|
||||||
if (!function_exists('formatErrorMessage')) { function formatErrorMessage() { return \RectorPrefix202403\formatErrorMessage(...func_get_args()); } }
|
if (!function_exists('formatErrorMessage')) { function formatErrorMessage() { return \RectorPrefix202403\formatErrorMessage(...func_get_args()); } }
|
||||||
if (!function_exists('includeIfExists')) { function includeIfExists() { return \RectorPrefix202403\includeIfExists(...func_get_args()); } }
|
if (!function_exists('includeIfExists')) { function includeIfExists() { return \RectorPrefix202403\includeIfExists(...func_get_args()); } }
|
||||||
if (!function_exists('mb_check_encoding')) { function mb_check_encoding() { return \RectorPrefix202403\mb_check_encoding(...func_get_args()); } }
|
if (!function_exists('mb_check_encoding')) { function mb_check_encoding() { return \RectorPrefix202403\mb_check_encoding(...func_get_args()); } }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user