From 3f3811ab212338c9dacddb6d43353c5fdb3ca011 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 24 Apr 2021 16:22:36 +0200 Subject: [PATCH] add dump_node() helper functoin (#6229) --- composer.json | 14 ++++++++------ config/services.php | 1 + src/functions/node_helper.php | 32 ++++++++++++++++++++++++++++++++ tests/debug_functions.php | 1 + 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/functions/node_helper.php diff --git a/composer.json b/composer.json index 404ae8a8430..4adef03a9d2 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,8 @@ "symplify/skipper": "^9.2.19", "symplify/smart-file-system": "^9.2.19", "symplify/symfony-php-config": "^9.2.19", - "webmozart/assert": "^1.10" + "webmozart/assert": "^1.10", + "tracy/tracy": "^2.8" }, "require-dev": { "symplify/rule-doc-generator": "^9.2.19", @@ -79,8 +80,7 @@ "symplify/easy-coding-standard": "^9.2.19", "symplify/easy-testing": "^9.2.19", "symplify/phpstan-extensions": "^9.2.19", - "symplify/phpstan-rules": "^9.2", - "tracy/tracy": "^2.8" + "symplify/phpstan-rules": "^9.2" }, "replace": { "rector/rector-prefixed": "self.version" @@ -90,7 +90,10 @@ "Rector\\": ["packages", "rules"], "Rector\\Core\\": "src", "Rector\\Compiler\\": "utils/compiler/src" - } + }, + "files": [ + "src/functions/node_helper.php" + ] }, "autoload-dev": { "psr-4": { @@ -118,8 +121,7 @@ "rules-tests/Restoration/Rector/Use_/RestoreFullyQualifiedNameRector/Source/ShortClassOnly.php", "rules-tests/Transform/Rector/FuncCall/FuncCallToMethodCallRector/Source/some_view_function.php", "rules-tests/TypeDeclaration/Rector/FunctionLike/ReturnTypeDeclarationRector/Source/MyBar.php", - "rules-tests/TypeDeclaration/Rector/Property/CompleteVarDocTypePropertyRector/Source/EventDispatcher.php", - "tests/debug_functions.php" + "rules-tests/TypeDeclaration/Rector/Property/CompleteVarDocTypePropertyRector/Source/EventDispatcher.php" ] }, "scripts": { diff --git a/config/services.php b/config/services.php index 4236296f47d..d898bc0c81d 100644 --- a/config/services.php +++ b/config/services.php @@ -66,6 +66,7 @@ return static function (ContainerConfigurator $containerConfigurator): void { __DIR__ . '/../src/ValueObject', __DIR__ . '/../src/Bootstrap', __DIR__ . '/../src/PhpParser/Node/CustomNode', + __DIR__ . '/../src/functions', ]); $services->alias(SymfonyApplication::class, ConsoleApplication::class); diff --git a/src/functions/node_helper.php b/src/functions/node_helper.php new file mode 100644 index 00000000000..0f0f14a7f02 --- /dev/null +++ b/src/functions/node_helper.php @@ -0,0 +1,32 @@ + $depth, + ]); +} + +/** + * @param Node|Node[] $node + */ +function print_node($node): void +{ + $standard = new Standard(); + + if (is_array($node)) { + foreach ($node as $singleNode) { + $printedContent = $standard->prettyPrint([$singleNode]); + Dumper::dump($printedContent); + } + } else { + $printedContent = $standard->prettyPrint([$node]); + Dumper::dump($printedContent); + } +} diff --git a/tests/debug_functions.php b/tests/debug_functions.php index b13e38a5c65..671cfa82af9 100644 --- a/tests/debug_functions.php +++ b/tests/debug_functions.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\PrettyPrinter\Standard; require __DIR__ . '/../vendor/autoload.php'; + /** * @param Node|Node[] $node */