From a500e454a6fbc5f536409100f64a62f99d663bd7 Mon Sep 17 00:00:00 2001 From: "Rafalko, Maksim" Date: Fri, 24 May 2024 00:05:19 +0200 Subject: [PATCH 1/3] Add AST explorer --- app/assets/js/app.js | 7 +- app/assets/js/app/editor.js | 82 +- app/assets/js/app/main.js | 5 - app/assets/js/ast.js | 3 + app/composer.json | 1 + app/composer.lock | 94 +- app/config/bundles.php | 34 +- app/migrations/Version20240521220725.php | 39 + app/src/Controller/AstController.php | 211 ++ app/src/Entity/AstRun.php | 94 + app/src/Form/CreateAstRunType.php | 72 + app/src/PhpParser/AttributeKey.php | 13 + app/src/PhpParser/ClickablePrinter.php | 2229 +++++++++++++++++ .../NodeResolver/FocusedNodeResolver.php | 27 + .../NodeVisior/NodeMarkerNodeVisitor.php | 22 + app/src/PhpParser/PrinterHelper.php | 19 + app/src/PhpParser/SimpleNodeDumper.php | 172 ++ app/src/PhpParser/SimplePhpParser.php | 79 + app/src/Repository/AstRunRepository.php | 58 + app/src/Request/CreateAstRunRequest.php | 56 + app/symfony.lock | 9 + app/templates/ast/_form.html.twig | 19 + app/templates/ast/create.html.twig | 5 + app/templates/ast/index.html.twig | 25 + app/templates/base.html.twig | 7 +- app/templates/playground/index.html.twig | 4 + app/webpack.config.js | 3 +- 27 files changed, 3336 insertions(+), 53 deletions(-) delete mode 100644 app/assets/js/app/main.js create mode 100644 app/assets/js/ast.js create mode 100644 app/migrations/Version20240521220725.php create mode 100644 app/src/Controller/AstController.php create mode 100644 app/src/Entity/AstRun.php create mode 100644 app/src/Form/CreateAstRunType.php create mode 100644 app/src/PhpParser/AttributeKey.php create mode 100644 app/src/PhpParser/ClickablePrinter.php create mode 100644 app/src/PhpParser/NodeResolver/FocusedNodeResolver.php create mode 100644 app/src/PhpParser/NodeVisior/NodeMarkerNodeVisitor.php create mode 100644 app/src/PhpParser/PrinterHelper.php create mode 100644 app/src/PhpParser/SimpleNodeDumper.php create mode 100644 app/src/PhpParser/SimplePhpParser.php create mode 100644 app/src/Repository/AstRunRepository.php create mode 100644 app/src/Request/CreateAstRunRequest.php create mode 100644 app/templates/ast/_form.html.twig create mode 100644 app/templates/ast/create.html.twig create mode 100644 app/templates/ast/index.html.twig diff --git a/app/assets/js/app.js b/app/assets/js/app.js index 4b34826..3cc7d2d 100644 --- a/app/assets/js/app.js +++ b/app/assets/js/app.js @@ -7,8 +7,7 @@ // any CSS you import will output into a single css file (app.css in this case) import '../css/app.css'; -import initApp from './app/main'; -// Need jQuery? Install it with "yarn add jquery", then uncomment to import it. -// import $ from 'jquery'; -initApp(); +import {initMutationEditors} from './app/editor'; + +initMutationEditors(); diff --git a/app/assets/js/app/editor.js b/app/assets/js/app/editor.js index 884b4c0..2d54192 100644 --- a/app/assets/js/app/editor.js +++ b/app/assets/js/app/editor.js @@ -2,7 +2,7 @@ import * as monaco from 'monaco-editor'; let diffEditor; -export function initEditors() { +export function initMutationEditors() { const codeEditor = initCodeEditor(); const testEditor = initTestEditor(); const configEditor = initConfigEditor(); @@ -226,6 +226,60 @@ function showDiffEditor(mutator) { }); } +export function initAstEditor() { + const loadedCodeElement = document.getElementById('loaded-code'); + const code = loadedCodeElement !== null + ? loadedCodeElement.dataset.code + : [ + '=8.1", + "symfony/config": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/deprecation-contracts": "^2.2|^3", + "symfony/filesystem": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0" + }, + "conflict": { + "doctrine/doctrine-bundle": "<2.10", + "doctrine/orm": "<2.15" + }, + "require-dev": { + "composer/semver": "^3.0", + "doctrine/doctrine-bundle": "^2.5.0", + "doctrine/orm": "^2.15|^3", + "symfony/http-client": "^6.4|^7.0", + "symfony/phpunit-bridge": "^6.4.1|^7.0", + "symfony/security-core": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0", + "twig/twig": "^3.0|^4.x-dev" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\MakerBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.", + "homepage": "https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html", + "keywords": [ + "code generator", + "dev", + "generator", + "scaffold", + "scaffolding" + ], + "support": { + "issues": "https://github.com/symfony/maker-bundle/issues", + "source": "https://github.com/symfony/maker-bundle/tree/v1.59.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-06T03:59:59+00:00" + }, { "name": "symfony/options-resolver", "version": "v7.0.0", diff --git a/app/config/bundles.php b/app/config/bundles.php index 8dfe5d6..918e34e 100644 --- a/app/config/bundles.php +++ b/app/config/bundles.php @@ -1,37 +1,4 @@ ['all' => true], @@ -41,4 +8,5 @@ Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], ]; diff --git a/app/migrations/Version20240521220725.php b/app/migrations/Version20240521220725.php new file mode 100644 index 0000000..3c672af --- /dev/null +++ b/app/migrations/Version20240521220725.php @@ -0,0 +1,39 @@ +addSql('CREATE TABLE ast_run ( + id INT AUTO_INCREMENT NOT NULL, + code LONGTEXT NOT NULL, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', + id_hash VARCHAR(10) DEFAULT NULL, + input_hash VARCHAR(32) NOT NULL, + UNIQUE INDEX UNIQ_D10C36992D5D98F (input_hash), + PRIMARY KEY(id) + ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE ast_run'); + } +} diff --git a/app/src/Controller/AstController.php b/app/src/Controller/AstController.php new file mode 100644 index 0000000..126d3c6 --- /dev/null +++ b/app/src/Controller/AstController.php @@ -0,0 +1,211 @@ +createForm(CreateAstRunType::class, $createExampleRequest); + + return $this->render('ast/index.html.twig', [ + 'form' => $form->createView(), + ]); + } + + #[Route('/r', name: 'app_ast_create', methods: ['POST'])] + public function createExample(Request $request, EntityManagerInterface $em): Response + { + $createAstRunRequest = new CreateAstRunRequest(); + + $form = $this->createForm(CreateAstRunType::class, $createAstRunRequest); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $existingAstRun = $this->astRunRepository->findContentByHash( + AstRun::hashInput($createAstRunRequest->code) + ); + + if ($existingAstRun instanceof AstRun) { + return $this->redirectToRoute('app_ast_display', ['astRunIdHash' => $this->hashids->encode($existingAstRun->getId())]); + } + + $astRun = new AstRun($createAstRunRequest->code); + + $em->persist($astRun); + $em->flush(); + + $idHash = $this->hashids->encode($astRun->getId()); + + $astRun->setIdHash($idHash); + $em->flush(); + + return $this->redirectToRoute('app_ast_display', ['astRunIdHash' => $idHash]); + } + + return $this->render('ast/create.html.twig', [ + 'form' => $form->createView(), + 'example' => $createAstRunRequest, + ]); + } + + #[Route('/ast/{astRunIdHash}/{activeNodeId}', name: 'app_ast_display', defaults: ['activeNodeId' => null], methods: ['GET'])] + public function displayExample(EntityManagerInterface $em, string $astRunIdHash, int|null $activeNodeId = null): Response + { + /** @var AstRun|null $astRun */ + $astRun = $em->find(AstRun::class, $this->hashids->decode($astRunIdHash)[0]); + + if (!$astRun instanceof AstRun) { + throw $this->createNotFoundException(); + } + + $createAstRequest = CreateAstRunRequest::fromEntity($astRun); + + $nodes = $this->simplePhpParser->parseString($astRun->getCode()); + + $focusedNode = is_int($activeNodeId) && $activeNodeId > 0 + ? $this->focusedNodeResolver->focus($nodes, $activeNodeId) + : null; + + if ($focusedNode instanceof Node) { + $simpleNodeDump = SimpleNodeDumper::dump($focusedNode); + $targetNodeClass = $this->resolveTargetNodeClass($focusedNode); + } else { + $simpleNodeDump = SimpleNodeDumper::dump($nodes); + $targetNodeClass = null; + } + + $form = $this->createForm(CreateAstRunType::class, $createAstRequest); + + return $this->render('ast/index.html.twig', [ + 'form' => $form->createView(), + 'astRun' => $createAstRequest, + 'clickableNodesDump' => $this->makeNodeClickable($nodes, $astRunIdHash, $activeNodeId), + 'simpleNodeDump' => $simpleNodeDump, + ]); + } + + /** + * @param Node[] $nodes + */ + private function makeNodeClickable(array $nodes, string $uuid, ?int $activeNodeId): string + { + $clickablePrinter = new ClickablePrinter($uuid, $activeNodeId); + + return $clickablePrinter->prettyPrint($nodes); + } + + private function resolveTargetNodeClass(Node $node): string + { + if ($node instanceof UseUse || $node instanceof AttributeGroup) { + $parentNode = $node->getAttribute('parent'); + return $parentNode::class; + } + + if ($node instanceof Attribute) { + $attributeGroup = $node->getAttribute('parent'); + $stmt = $attributeGroup->getAttribute('parent'); + return $stmt::class; + } + + if ($node instanceof Stmt) { + return $node::class; + } + + if ($node instanceof Variable) { + $parentNode = $node->getAttribute('parent'); + + // special case + if ($parentNode instanceof Param) { + return $parentNode::class; + } + } + + // target one level up + if ($node instanceof Identifier || $node instanceof Name || $node instanceof Variable) { + $parentNode = $node->getAttribute('parent'); + return $this->resolveTargetNodeClass($parentNode); + } + + return $node::class; + } +} diff --git a/app/src/Entity/AstRun.php b/app/src/Entity/AstRun.php new file mode 100644 index 0000000..d88eec3 --- /dev/null +++ b/app/src/Entity/AstRun.php @@ -0,0 +1,94 @@ + 'CURRENT_TIMESTAMP'])] + private DateTimeImmutable $createdAt; + + #[ORM\Column(type: 'string', length: 10, nullable: true)] + private ?string $idHash = null; + + #[ORM\Column(type: 'string', length: 32, unique: true)] + private string $inputHash; + + public function __construct(string $code) + { + $this->code = $code; + $this->inputHash = self::hashInput($code); + } + + public function getId(): int + { + return $this->id; + } + + public function getCode(): string + { + return $this->code; + } + + public function setIdHash(string $idHash): void + { + $this->idHash = $idHash; + } + + #[ORM\PrePersist] + public function setCreatedAtToCurrentDateTime(): void + { + $this->createdAt = new DateTimeImmutable(); + } + + public static function hashInput(string $code): string + { + return md5($code); + } +} diff --git a/app/src/Form/CreateAstRunType.php b/app/src/Form/CreateAstRunType.php new file mode 100644 index 0000000..6cc8c6f --- /dev/null +++ b/app/src/Form/CreateAstRunType.php @@ -0,0 +1,72 @@ +urlGenerator = $urlGenerator; + } + + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('code', TextareaType::class) + ->add('buildAst', SubmitType::class, ['label' => 'Build AST']); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => CreateAstRunRequest::class, + 'action' => $this->urlGenerator->generate('app_ast_create'), + ]); + } +} diff --git a/app/src/PhpParser/AttributeKey.php b/app/src/PhpParser/AttributeKey.php new file mode 100644 index 0000000..b126513 --- /dev/null +++ b/app/src/PhpParser/AttributeKey.php @@ -0,0 +1,13 @@ +getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pParam($param) + ); + } + + protected function pArg(Arg $arg): string + { + $nodeId = $arg->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pArg($arg) + ); + } + + protected function pVariadicPlaceholder(VariadicPlaceholder $variadicPlaceholder): string + { + $nodeId = $variadicPlaceholder->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pVariadicPlaceholder($variadicPlaceholder) + ); + } + + protected function pConst(Const_ $const): string + { + $nodeId = $const->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pConst($const) + ); + } + + protected function pNullableType(NullableType $nullableType): string + { + $nodeId = $nullableType->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pNullableType($nullableType) + ); + } + + protected function pUnionType(UnionType $unionType): string + { + $nodeId = $unionType->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pUnionType($unionType) + ); + } + + protected function pIntersectionType(IntersectionType $intersectionType): string + { + $nodeId = $intersectionType->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pIntersectionType($intersectionType) + ); + } + + protected function pIdentifier(Identifier $identifier): string + { + $nodeId = $identifier->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pIdentifier($identifier) + ); + } + + protected function pVarLikeIdentifier(VarLikeIdentifier $varLikeIdentifier): string + { + $nodeId = $varLikeIdentifier->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pVarLikeIdentifier($varLikeIdentifier) + ); + } + + protected function pAttribute(Attribute $attribute): string + { + $nodeId = $attribute->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pAttribute($attribute) + ); + } + + protected function pAttributeGroup(AttributeGroup $attributeGroup): string + { + $nodeId = $attributeGroup->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pAttributeGroup($attributeGroup) + ); + } + + protected function pName(Name $name): string + { + $nodeId = $name->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pName($name) + ); + } + + protected function pName_FullyQualified(FullyQualified $fullyQualified): string + { + $nodeId = $fullyQualified->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pName_FullyQualified($fullyQualified) + ); + } + + protected function pName_Relative(Relative $relative): string + { + $nodeId = $relative->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pName_Relative($relative) + ); + } + + protected function pScalar_MagicConst_Class(Class_ $class): string + { + $nodeId = $class->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Class($class) + ); + } + + protected function pScalar_MagicConst_Dir(Dir $dir): string + { + $nodeId = $dir->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Dir($dir) + ); + } + + protected function pScalar_MagicConst_File(File $file): string + { + $nodeId = $file->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_File($file) + ); + } + + protected function pScalar_MagicConst_Function(Function_ $function): string + { + $nodeId = $function->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Function($function) + ); + } + + protected function pScalar_MagicConst_Line(Line $line): string + { + $nodeId = $line->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Line($line) + ); + } + + protected function pScalar_MagicConst_Method(Method $method): string + { + $nodeId = $method->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Method($method) + ); + } + + protected function pScalar_MagicConst_Namespace(Namespace_ $namespace): string + { + $nodeId = $namespace->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Namespace($namespace) + ); + } + + protected function pScalar_MagicConst_Trait(Trait_ $trait): string + { + $nodeId = $trait->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_MagicConst_Trait($trait) + ); + } + + protected function pScalar_String(String_ $string): string + { + $nodeId = $string->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_String($string) + ); + } + + protected function pScalar_Encapsed(Encapsed $encapsed): string + { + $nodeId = $encapsed->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_Encapsed($encapsed) + ); + } + + protected function pScalar_LNumber(LNumber $lNumber): string + { + $nodeId = $lNumber->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_LNumber($lNumber) + ); + } + + protected function pScalar_DNumber(DNumber $dNumber): string + { + $nodeId = $dNumber->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_DNumber($dNumber) + ); + } + + protected function pScalar_EncapsedStringPart(EncapsedStringPart $encapsedStringPart): string + { + $nodeId = $encapsedStringPart->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pScalar_EncapsedStringPart($encapsedStringPart) + ); + } + + protected function pExpr_Assign(Assign $assign): string + { + $nodeId = $assign->getAttribute(AttributeKey::NODE_ID); + $link = PrinterHelper::printLink(' = ', $this->idHash, $nodeId, $this->activeNodeId); + + return $this->pInfixOp(Assign::class, $assign->var, $link, $assign->expr); + } + + protected function pExpr_AssignRef(AssignRef $assignRef): string + { + $nodeId = $assignRef->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignRef($assignRef) + ); + } + + protected function pExpr_AssignOp_Plus(Plus $plus): string + { + $nodeId = $plus->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Plus($plus) + ); + } + + protected function pExpr_AssignOp_Minus(Minus $minus): string + { + $nodeId = $minus->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Minus($minus) + ); + } + + protected function pExpr_AssignOp_Mul(Mul $mul): string + { + $nodeId = $mul->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Mul($mul) + ); + } + + protected function pExpr_AssignOp_Div(Div $div): string + { + $nodeId = $div->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Div($div) + ); + } + + protected function pExpr_AssignOp_Concat(Concat $concat): string + { + $nodeId = $concat->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Concat($concat) + ); + } + + protected function pExpr_AssignOp_Mod(Mod $mod): string + { + $nodeId = $mod->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Mod($mod) + ); + } + + protected function pExpr_AssignOp_BitwiseAnd(BitwiseAnd $bitwiseAnd): string + { + $nodeId = $bitwiseAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_BitwiseAnd($bitwiseAnd) + ); + } + + protected function pExpr_AssignOp_BitwiseOr(BitwiseOr $bitwiseOr): string + { + $nodeId = $bitwiseOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_BitwiseOr($bitwiseOr) + ); + } + + protected function pExpr_AssignOp_BitwiseXor(BitwiseXor $bitwiseXor): string + { + $nodeId = $bitwiseXor->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_BitwiseXor($bitwiseXor) + ); + } + + protected function pExpr_AssignOp_ShiftLeft(ShiftLeft $shiftLeft): string + { + $nodeId = $shiftLeft->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_ShiftLeft($shiftLeft) + ); + } + + protected function pExpr_AssignOp_ShiftRight(ShiftRight $shiftRight): string + { + $nodeId = $shiftRight->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_ShiftRight($shiftRight) + ); + } + + protected function pExpr_AssignOp_Pow(Pow $pow): string + { + $nodeId = $pow->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Pow($pow) + ); + } + + protected function pExpr_AssignOp_Coalesce(Coalesce $coalesce): string + { + $nodeId = $coalesce->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_AssignOp_Coalesce($coalesce) + ); + } + + protected function pExpr_BinaryOp_Plus(\PhpParser\Node\Expr\BinaryOp\Plus $plus): string + { + $nodeId = $plus->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Plus($plus) + ); + } + + protected function pExpr_BinaryOp_Minus(\PhpParser\Node\Expr\BinaryOp\Minus $minus): string + { + $nodeId = $minus->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Minus($minus) + ); + } + + protected function pExpr_BinaryOp_Mul(\PhpParser\Node\Expr\BinaryOp\Mul $mul): string + { + $nodeId = $mul->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Mul($mul) + ); + } + + protected function pExpr_BinaryOp_Div(\PhpParser\Node\Expr\BinaryOp\Div $div): string + { + $nodeId = $div->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Div($div) + ); + } + + protected function pExpr_BinaryOp_Concat(\PhpParser\Node\Expr\BinaryOp\Concat $concat): string + { + $nodeId = $concat->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Concat($concat) + ); + } + + protected function pExpr_BinaryOp_Mod(\PhpParser\Node\Expr\BinaryOp\Mod $mod): string + { + $nodeId = $mod->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Mod($mod) + ); + } + + protected function pExpr_BinaryOp_BooleanAnd(BooleanAnd $booleanAnd): string + { + $nodeId = $booleanAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_BooleanAnd($booleanAnd) + ); + } + + protected function pExpr_BinaryOp_BooleanOr(BooleanOr $booleanOr): string + { + $nodeId = $booleanOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_BooleanOr($booleanOr) + ); + } + + protected function pExpr_BinaryOp_BitwiseAnd(\PhpParser\Node\Expr\BinaryOp\BitwiseAnd $bitwiseAnd): string + { + $nodeId = $bitwiseAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_BitwiseAnd($bitwiseAnd) + ); + } + + protected function pExpr_BinaryOp_BitwiseOr(\PhpParser\Node\Expr\BinaryOp\BitwiseOr $bitwiseOr): string + { + $nodeId = $bitwiseOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_BitwiseOr($bitwiseOr) + ); + } + + protected function pExpr_BinaryOp_BitwiseXor(\PhpParser\Node\Expr\BinaryOp\BitwiseXor $bitwiseXor): string + { + $nodeId = $bitwiseXor->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_BitwiseXor($bitwiseXor) + ); + } + + protected function pExpr_BinaryOp_ShiftLeft(\PhpParser\Node\Expr\BinaryOp\ShiftLeft $shiftLeft): string + { + $nodeId = $shiftLeft->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_ShiftLeft($shiftLeft) + ); + } + + protected function pExpr_BinaryOp_ShiftRight(\PhpParser\Node\Expr\BinaryOp\ShiftRight $shiftRight): string + { + $nodeId = $shiftRight->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_ShiftRight($shiftRight) + ); + } + + protected function pExpr_BinaryOp_Pow(\PhpParser\Node\Expr\BinaryOp\Pow $pow): string + { + $nodeId = $pow->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_Pow($pow) + ); + } + + protected function pExpr_BinaryOp_LogicalAnd(LogicalAnd $logicalAnd): string + { + $nodeId = $logicalAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_LogicalAnd($logicalAnd) + ); + } + + protected function pExpr_BinaryOp_LogicalOr(LogicalOr $logicalOr): string + { + $nodeId = $logicalOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BinaryOp_LogicalOr($logicalOr) + ); + } + + protected function pExpr_BinaryOp_LogicalXor(LogicalXor $logicalXor): string + { + $nodeId = $logicalXor->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $logicalXor->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(LogicalXor::class, $logicalXor->left, $link, $logicalXor->right); + } + + protected function pExpr_BinaryOp_Equal(Equal $equal): string + { + $nodeId = $equal->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $equal->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(Equal::class, $equal->left, $link, $equal->right); + } + + protected function pExpr_BinaryOp_NotEqual(NotEqual $notEqual): string + { + $nodeId = $notEqual->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $notEqual->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(NotEqual::class, $notEqual->left, $link, $notEqual->right); + } + + /** + * @override + */ + protected function pExpr_BinaryOp_Identical(Identical $identical): string + { + $nodeId = $identical->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $identical->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(Identical::class, $identical->left, $link, $identical->right); + } + + protected function pExpr_BinaryOp_NotIdentical(NotIdentical $notIdentical): string + { + $nodeId = $notIdentical->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $notIdentical->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(NotIdentical::class, $notIdentical->left, $link, $notIdentical->right); + } + + protected function pExpr_BinaryOp_Spaceship(Spaceship $spaceship): string + { + $nodeId = $spaceship->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $spaceship->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(Spaceship::class, $spaceship->left, $link, $spaceship->right); + } + + protected function pExpr_BinaryOp_Greater(Greater $greater): string + { + $nodeId = $greater->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $greater->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(Greater::class, $greater->left, $link, $greater->right); + } + + protected function pExpr_BinaryOp_GreaterOrEqual(GreaterOrEqual $greaterOrEqual): string + { + $nodeId = $greaterOrEqual->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $greaterOrEqual->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(GreaterOrEqual::class, $greaterOrEqual->left, $link, $greaterOrEqual->right); + } + + protected function pExpr_BinaryOp_Smaller(Smaller $smaller): string + { + $nodeId = $smaller->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $smaller->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(Smaller::class, $smaller->left, $link, $smaller->right); + } + + protected function pExpr_BinaryOp_SmallerOrEqual(SmallerOrEqual $smallerOrEqual): string + { + $nodeId = $smallerOrEqual->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $smallerOrEqual->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(SmallerOrEqual::class, $smallerOrEqual->left, $link, $smallerOrEqual->right); + } + + protected function pExpr_BinaryOp_Coalesce(\PhpParser\Node\Expr\BinaryOp\Coalesce $coalesce): string + { + $nodeId = $coalesce->getAttribute(AttributeKey::NODE_ID); + + $link = PrinterHelper::printLink( + ' ' . $coalesce->getOperatorSigil() . ' ', + $this->idHash, + $nodeId, + $this->activeNodeId + ); + + return $this->pInfixOp(\PhpParser\Node\Expr\BinaryOp\Coalesce::class, $coalesce->left, $link, $coalesce->right); + } + + protected function pExpr_Instanceof(Instanceof_ $instanceof): string + { + $nodeId = $instanceof->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Instanceof($instanceof) + ); + } + + protected function pExpr_BooleanNot(BooleanNot $booleanNot): string + { + $nodeId = $booleanNot->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BooleanNot($booleanNot) + ); + } + + protected function pExpr_BitwiseNot(BitwiseNot $bitwiseNot): string + { + $nodeId = $bitwiseNot->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_BitwiseNot($bitwiseNot) + ); + } + + protected function pExpr_UnaryMinus(UnaryMinus $unaryMinus): string + { + $nodeId = $unaryMinus->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_UnaryMinus($unaryMinus) + ); + } + + protected function pExpr_UnaryPlus(UnaryPlus $unaryPlus): string + { + $nodeId = $unaryPlus->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_UnaryPlus($unaryPlus) + ); + } + + protected function pExpr_PreInc(PreInc $preInc): string + { + $nodeId = $preInc->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_PreInc($preInc) + ); + } + + protected function pExpr_PreDec(PreDec $preDec): string + { + $nodeId = $preDec->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_PreDec($preDec) + ); + } + + protected function pExpr_PostInc(PostInc $postInc): string + { + $nodeId = $postInc->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_PostInc($postInc) + ); + } + + protected function pExpr_PostDec(PostDec $postDec): string + { + $nodeId = $postDec->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_PostDec($postDec) + ); + } + + protected function pExpr_ErrorSuppress(ErrorSuppress $errorSuppress): string + { + $nodeId = $errorSuppress->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ErrorSuppress($errorSuppress) + ); + } + + protected function pExpr_YieldFrom(YieldFrom $yieldFrom): string + { + $nodeId = $yieldFrom->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_YieldFrom($yieldFrom) + ); + } + + protected function pExpr_Print(Print_ $print): string + { + $nodeId = $print->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Print($print) + ); + } + + protected function pExpr_Cast_Int(Int_ $int): string + { + $nodeId = $int->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_Int($int) + ); + } + + protected function pExpr_Cast_Double(Double $double): string + { + $nodeId = $double->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_Double($double) + ); + } + + protected function pExpr_Cast_String(\PhpParser\Node\Expr\Cast\String_ $string): string + { + $nodeId = $string->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_String($string) + ); + } + + protected function pExpr_Cast_Array(Array_ $array): string + { + $nodeId = $array->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_Array($array) + ); + } + + protected function pExpr_Cast_Object(Object_ $object): string + { + $nodeId = $object->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_Object($object) + ); + } + + protected function pExpr_Cast_Bool(Bool_ $bool): string + { + $nodeId = $bool->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_Bool($bool) + ); + } + + protected function pExpr_Cast_Unset(Unset_ $unset): string + { + $nodeId = $unset->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Cast_Unset($unset) + ); + } + + protected function pExpr_FuncCall(FuncCall $funcCall): string + { + $nodeId = $funcCall->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_FuncCall($funcCall) + ); + } + + /** + * @overloaded + */ + protected function pExpr_MethodCall(MethodCall $methodCall): string + { + $nodeId = $methodCall->getAttribute(AttributeKey::NODE_ID); + + $link = sprintf( + '->', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + ); + + return $this->pDereferenceLhs($methodCall->var) . $link . $this->pObjectProperty($methodCall->name) + . '(' . $this->pMaybeMultiline($methodCall->args) . ')'; + } + + protected function pExpr_NullsafeMethodCall(NullsafeMethodCall $nullsafeMethodCall): string + { + $nodeId = $nullsafeMethodCall->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_NullsafeMethodCall($nullsafeMethodCall) + ); + } + + protected function pExpr_StaticCall(StaticCall $staticCall): string + { + $nodeId = $staticCall->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_StaticCall($staticCall) + ); + } + + protected function pExpr_Empty(Empty_ $empty): string + { + $nodeId = $empty->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Empty($empty) + ); + } + + protected function pExpr_Isset(Isset_ $isset): string + { + $nodeId = $isset->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Isset($isset) + ); + } + + protected function pExpr_Eval(Eval_ $eval): string + { + $nodeId = $eval->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Eval($eval) + ); + } + + protected function pExpr_Include(Include_ $include): string + { + $nodeId = $include->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Include($include) + ); + } + + protected function pExpr_List(List_ $list): string + { + $nodeId = $list->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_List($list) + ); + } + + protected function pExpr_Error(Error $error): string + { + $nodeId = $error->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Error($error) + ); + } + + protected function pExpr_Variable(Variable $variable): string + { + $nodeId = $variable->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Variable($variable) + ); + } + + protected function pExpr_Array(\PhpParser\Node\Expr\Array_ $array): string + { + $nodeId = $array->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Array($array) + ); + } + + protected function pExpr_ArrayItem(ArrayItem $arrayItem): string + { + $nodeId = $arrayItem->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ArrayItem($arrayItem) + ); + } + + protected function pExpr_ArrayDimFetch(ArrayDimFetch $arrayDimFetch): string + { + $nodeId = $arrayDimFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ArrayDimFetch($arrayDimFetch) + ); + } + + protected function pExpr_ConstFetch(ConstFetch $constFetch): string + { + $nodeId = $constFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ConstFetch($constFetch) + ); + } + + protected function pExpr_ClassConstFetch(ClassConstFetch $classConstFetch): string + { + $nodeId = $classConstFetch->getAttribute(AttributeKey::NODE_ID); + + $link = sprintf( + '::', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + ); + + return $this->pStaticDereferenceLhs($classConstFetch->class) . $link . $this->pObjectProperty( + $classConstFetch->name + ); + } + + protected function pExpr_PropertyFetch(PropertyFetch $propertyFetch): string + { + $nodeId = $propertyFetch->getAttribute(AttributeKey::NODE_ID); + $link = PrinterHelper::printLink('->', $this->idHash, $nodeId, $this->activeNodeId); + + return $this->pDereferenceLhs($propertyFetch->var) . $link . $this->pObjectProperty($propertyFetch->name); + } + + protected function pExpr_NullsafePropertyFetch(NullsafePropertyFetch $nullsafePropertyFetch): string + { + $nodeId = $nullsafePropertyFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_NullsafePropertyFetch($nullsafePropertyFetch) + ); + } + + protected function pExpr_StaticPropertyFetch(StaticPropertyFetch $staticPropertyFetch): string + { + $nodeId = $staticPropertyFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_StaticPropertyFetch($staticPropertyFetch) + ); + } + + protected function pExpr_ShellExec(ShellExec $shellExec): string + { + $nodeId = $shellExec->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ShellExec($shellExec) + ); + } + + protected function pExpr_Closure(Closure $node): string + { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Closure($node) + ); + } + + protected function pExpr_Match(Match_ $match): string + { + $nodeId = $match->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Match($match) + ); + } + + protected function pMatchArm(MatchArm $matchArm): string + { + $nodeId = $matchArm->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pMatchArm($matchArm) + ); + } + + protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction): string + { + $nodeId = $arrowFunction->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ArrowFunction($arrowFunction) + ); + } + + protected function pExpr_ClosureUse(ClosureUse $node): string + { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_ClosureUse($node) + ); + } + + protected function pExpr_New(New_ $new): string + { + $nodeId = $new->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_New($new) + ); + } + + protected function pExpr_Clone(Clone_ $clone): string + { + $nodeId = $clone->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Clone($clone) + ); + } + + protected function pExpr_Ternary(Ternary $ternary): string + { + $nodeId = $ternary->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Ternary($ternary) + ); + } + + protected function pExpr_Exit(Exit_ $exit): string + { + $nodeId = $exit->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Exit($exit) + ); + } + + protected function pExpr_Throw(Throw_ $throw): string + { + $nodeId = $throw->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Throw($throw) + ); + } + + protected function pExpr_Yield(Yield_ $yield): string + { + $nodeId = $yield->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pExpr_Yield($yield) + ); + } + + protected function pStmt_Namespace(\PhpParser\Node\Stmt\Namespace_ $namespace): string + { + $nodeId = $namespace->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Namespace($namespace) + ); + } + + protected function pStmt_Use(Use_ $use): string + { + $nodeId = $use->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Use($use) + ); + } + + protected function pStmt_GroupUse(GroupUse $groupUse): string + { + $nodeId = $groupUse->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_GroupUse($groupUse) + ); + } + + protected function pStmt_UseUse(UseUse $useUse): string + { + $nodeId = $useUse->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_UseUse($useUse) + ); + } + + protected function pStmt_Interface(Interface_ $interface): string + { + $nodeId = $interface->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Interface($interface) + ); + } + + protected function pStmt_Enum(Enum_ $enum): string + { + $nodeId = $enum->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Enum($enum) + ); + } + + protected function pStmt_Class(\PhpParser\Node\Stmt\Class_ $class): string + { + $nodeId = $class->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Class($class) + ); + } + + protected function pStmt_Trait(\PhpParser\Node\Stmt\Trait_ $trait): string + { + $nodeId = $trait->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Trait($trait) + ); + } + + protected function pStmt_EnumCase(EnumCase $enumCase): string + { + $nodeId = $enumCase->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_EnumCase($enumCase) + ); + } + + protected function pStmt_TraitUse(TraitUse $traitUse): string + { + $nodeId = $traitUse->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_TraitUse($traitUse) + ); + } + + protected function pStmt_TraitUseAdaptation_Precedence(Precedence $precedence): string + { + $nodeId = $precedence->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_TraitUseAdaptation_Precedence($precedence) + ); + } + + protected function pStmt_TraitUseAdaptation_Alias(Alias $alias): string + { + $nodeId = $alias->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_TraitUseAdaptation_Alias($alias) + ); + } + + protected function pStmt_Property(Property $property): string + { + $nodeId = $property->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Property($property) + ); + } + + protected function pStmt_PropertyProperty(PropertyProperty $propertyProperty): string + { + $nodeId = $propertyProperty->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_PropertyProperty($propertyProperty) + ); + } + + protected function pStmt_ClassMethod(ClassMethod $classMethod): string + { + $nodeId = $classMethod->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_ClassMethod($classMethod) + ); + } + + protected function pStmt_ClassConst(ClassConst $classConst): string + { + $nodeId = $classConst->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_ClassConst($classConst) + ); + } + + protected function pStmt_Function(\PhpParser\Node\Stmt\Function_ $function): string + { + $nodeId = $function->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Function($function) + ); + } + + protected function pStmt_Const(\PhpParser\Node\Stmt\Const_ $const): string + { + $nodeId = $const->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Const($const) + ); + } + + protected function pStmt_Declare(Declare_ $declare): string + { + $nodeId = $declare->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Declare($declare) + ); + } + + protected function pStmt_DeclareDeclare(DeclareDeclare $declareDeclare): string + { + $nodeId = $declareDeclare->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_DeclareDeclare($declareDeclare) + ); + } + + protected function pStmt_If(If_ $if): string + { + $nodeId = $if->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_If($if) + ); + } + + protected function pStmt_ElseIf(ElseIf_ $elseIf): string + { + $nodeId = $elseIf->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_ElseIf($elseIf) + ); + } + + protected function pStmt_Else(Else_ $else): string + { + $nodeId = $else->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Else($else) + ); + } + + protected function pStmt_For(For_ $for): string + { + $nodeId = $for->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_For($for) + ); + } + + protected function pStmt_Foreach(Foreach_ $foreach): string + { + $nodeId = $foreach->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Foreach($foreach) + ); + } + + protected function pStmt_While(While_ $while): string + { + $nodeId = $while->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_While($while) + ); + } + + protected function pStmt_Do(Do_ $do): string + { + $nodeId = $do->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Do($do) + ); + } + + protected function pStmt_Switch(Switch_ $switch): string + { + $nodeId = $switch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Switch($switch) + ); + } + + protected function pStmt_Case(Case_ $case): string + { + $nodeId = $case->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Case($case) + ); + } + + protected function pStmt_TryCatch(TryCatch $tryCatch): string + { + $nodeId = $tryCatch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_TryCatch($tryCatch) + ); + } + + protected function pStmt_Catch(Catch_ $catch): string + { + $nodeId = $catch->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Catch($catch) + ); + } + + protected function pStmt_Finally(Finally_ $finally): string + { + $nodeId = $finally->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Finally($finally) + ); + } + + protected function pStmt_Break(Break_ $break): string + { + $nodeId = $break->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Break($break) + ); + } + + protected function pStmt_Continue(Continue_ $continue): string + { + $nodeId = $continue->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Continue($continue) + ); + } + + protected function pStmt_Return(Return_ $return): string + { + $nodeId = $return->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Return($return) + ); + } + + protected function pStmt_Throw(\PhpParser\Node\Stmt\Throw_ $throw): string + { + $nodeId = $throw->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Throw($throw) + ); + } + + protected function pStmt_Label(Label $label): string + { + $nodeId = $label->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Label($label) + ); + } + + protected function pStmt_Goto(Goto_ $goto): string + { + $nodeId = $goto->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Goto($goto) + ); + } + + protected function pStmt_Expression(Expression $expression): string + { + $nodeId = $expression->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Expression($expression) + ); + } + + protected function pStmt_Echo(Echo_ $echo): string + { + $nodeId = $echo->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Echo($echo) + ); + } + + protected function pStmt_Static(Static_ $static): string + { + $nodeId = $static->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Static($static) + ); + } + + protected function pStmt_Global(Global_ $global): string + { + $nodeId = $global->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Global($global) + ); + } + + protected function pStmt_StaticVar(StaticVar $staticVar): string + { + $nodeId = $staticVar->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_StaticVar($staticVar) + ); + } + + protected function pStmt_Unset(\PhpParser\Node\Stmt\Unset_ $unset): string + { + $nodeId = $unset->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Unset($unset) + ); + } + + protected function pStmt_InlineHTML(InlineHTML $inlineHTML): string + { + $nodeId = $inlineHTML->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_InlineHTML($inlineHTML) + ); + } + + protected function pStmt_HaltCompiler(HaltCompiler $haltCompiler): string + { + $nodeId = $haltCompiler->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_HaltCompiler($haltCompiler) + ); + } + + protected function pStmt_Nop(Nop $nop): string + { + $nodeId = $nop->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pStmt_Nop($nop) + ); + } + + protected function pObjectProperty($node): string + { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pObjectProperty($node) + ); + } + + protected function pDereferenceLhs(Node $node): string + { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pDereferenceLhs($node) + ); + } + + protected function pCallLhs(Node $node): string + { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pCallLhs($node) + ); + } + + protected function pNewVariable(Node $node): string + { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( + '%s', + $this->idHash, + $nodeId, + $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + parent::pNewVariable($node) + ); + } +} diff --git a/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php b/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php new file mode 100644 index 0000000..4c2f8ad --- /dev/null +++ b/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php @@ -0,0 +1,27 @@ +findFirst($nodes, static function (Node $node) use ($activeNodeId): bool { + $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + + return $activeNodeId === $nodeId; + }); + } +} diff --git a/app/src/PhpParser/NodeVisior/NodeMarkerNodeVisitor.php b/app/src/PhpParser/NodeVisior/NodeMarkerNodeVisitor.php new file mode 100644 index 0000000..96ea80f --- /dev/null +++ b/app/src/PhpParser/NodeVisior/NodeMarkerNodeVisitor.php @@ -0,0 +1,22 @@ +setAttribute(AttributeKey::NODE_ID, $this->counter); + ++$this->counter; + + return null; + } +} diff --git a/app/src/PhpParser/PrinterHelper.php b/app/src/PhpParser/PrinterHelper.php new file mode 100644 index 0000000..5557865 --- /dev/null +++ b/app/src/PhpParser/PrinterHelper.php @@ -0,0 +1,19 @@ +%s', + $uuid, + $nodeId, + $activeNodeId == $nodeId ? 'class="active-node"' : '', + $contents + ); + } +} diff --git a/app/src/PhpParser/SimpleNodeDumper.php b/app/src/PhpParser/SimpleNodeDumper.php new file mode 100644 index 0000000..25b8406 --- /dev/null +++ b/app/src/PhpParser/SimpleNodeDumper.php @@ -0,0 +1,172 @@ + $value) { + $result .= "\n " . $key . ': '; + if ($value === null) { + $result .= 'null'; + } elseif ($value === \false) { + $result .= 'false'; + } elseif ($value === \true) { + $result .= 'true'; + } elseif (\is_string($value)) { + $result .= '"' . $value . '"'; + } elseif (\is_scalar($value)) { + $result .= $value; + } else { + $result .= \str_replace("\n", "\n ", self::dump($value, \false)); + } + } + if (\count($node) === 0) { + $result .= ']'; + } else { + $result .= "\n]"; + } + return $result; + } + /** + * @param mixed[] $items + */ + private static function isStringList(array $items) : bool + { + foreach ($items as $item) { + if (!\is_string($item)) { + return \false; + } + } + return \true; + } + /** + * @param mixed $flags + */ + private static function dumpFlags($flags) : string + { + $strs = []; + if (($flags & Class_::MODIFIER_PUBLIC) !== 0) { + $strs[] = 'MODIFIER_PUBLIC'; + } + if (($flags & Class_::MODIFIER_PROTECTED) !== 0) { + $strs[] = 'MODIFIER_PROTECTED'; + } + if (($flags & Class_::MODIFIER_PRIVATE) !== 0) { + $strs[] = 'MODIFIER_PRIVATE'; + } + if (($flags & Class_::MODIFIER_ABSTRACT) !== 0) { + $strs[] = 'MODIFIER_ABSTRACT'; + } + if (($flags & Class_::MODIFIER_STATIC) !== 0) { + $strs[] = 'MODIFIER_STATIC'; + } + if (($flags & Class_::MODIFIER_FINAL) !== 0) { + $strs[] = 'MODIFIER_FINAL'; + } + if (($flags & Class_::MODIFIER_READONLY) !== 0) { + $strs[] = 'MODIFIER_READONLY'; + } + if ($strs !== []) { + return \implode(' | ', $strs) . ' (' . $flags . ')'; + } + return (string) $flags; + } + /** + * @param int|float|string $type + */ + private static function dumpIncludeType($type) : string + { + $map = [Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', Include_::TYPE_REQUIRE => 'TYPE_REQUIRE', Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE']; + if (!isset($map[$type])) { + return (string) $type; + } + return $map[$type] . ' (' . $type . ')'; + } + /** + * @param mixed $type + */ + private static function dumpUseType($type) : string + { + $map = [Use_::TYPE_UNKNOWN => 'TYPE_UNKNOWN', Use_::TYPE_NORMAL => 'TYPE_NORMAL', Use_::TYPE_FUNCTION => 'TYPE_FUNCTION', Use_::TYPE_CONSTANT => 'TYPE_CONSTANT']; + if (!isset($map[$type])) { + return (string) $type; + } + return $map[$type] . ' (' . $type . ')'; + } + private static function dumpSingleNode(Node $node) : string + { + $result = \get_class($node); + // print simple nodes on same line, to make output more readable + if ($node instanceof Variable && \is_string($node->name)) { + $result .= '( name: "' . $node->name . '" )'; + } elseif ($node instanceof Identifier) { + $result .= '( name: "' . $node->name . '" )'; + } elseif ($node instanceof Name) { + $result .= '( parts: ' . \json_encode($node->getParts(), 0) . ' )'; + } elseif ($node instanceof Scalar && $node->getSubNodeNames() === ['value']) { + if (\is_string($node->value)) { + $result .= '( value: "' . $node->value . '" )'; + } else { + $result .= '( value: ' . $node->value . ' )'; + } + } else { + $result .= '('; + foreach ($node->getSubNodeNames() as $key) { + $result .= "\n " . $key . ': '; + $value = $node->{$key}; + if ($value === null) { + $result .= 'null'; + } elseif ($value === \false) { + $result .= 'false'; + } elseif ($value === \true) { + $result .= 'true'; + } elseif (\is_scalar($value)) { + if ($key === 'flags' || $key === 'newModifier') { + $result .= self::dumpFlags($value); + } elseif ($key === 'type' && $node instanceof Include_) { + $result .= self::dumpIncludeType($value); + } elseif ($key === 'type' && ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) { + $result .= self::dumpUseType($value); + } elseif (\is_string($value)) { + $result .= '"' . $value . '"'; + } else { + $result .= $value; + } + } else { + $result .= \str_replace("\n", "\n ", self::dump($value, \false)); + } + } + $result .= "\n)"; + } + return $result; + } +} diff --git a/app/src/PhpParser/SimplePhpParser.php b/app/src/PhpParser/SimplePhpParser.php new file mode 100644 index 0000000..8d3117d --- /dev/null +++ b/app/src/PhpParser/SimplePhpParser.php @@ -0,0 +1,79 @@ +phpParser = $parserFactory->create(ParserFactory::ONLY_PHP7); + + $this->nodeTraverser = new NodeTraverser(); + $this->nodeTraverser->addVisitor(new NameResolver()); + $this->nodeTraverser->addVisitor(new NodeMarkerNodeVisitor()); + $this->nodeTraverser->addVisitor(new ParentConnectingVisitor()); + + $this->nodeFinder = new NodeFinder(); + } + + /** + * @api tests + */ + public function parseFileToClass(string $filePath): Class_ + { + $fileContent = FileSystem::read($filePath); + $nodes = $this->parseString($fileContent); + + $foundClass = $this->nodeFinder->findFirstInstanceOf($nodes, Class_::class); + if (! $foundClass instanceof Class_) { + throw new ShouldNotHappenException(); + } + + return $foundClass; + } + + /** + * @return Node[] + */ + public function parseString(string $fileContent): array + { + $fileContent = $this->ensureFileContentsHasOpeningTag($fileContent); + + $nodes = $this->phpParser->parse($fileContent); + + if ($nodes === null) { + return []; + } + + return $this->nodeTraverser->traverse($nodes); + } + + private function ensureFileContentsHasOpeningTag(string $fileContent): string + { + if (! str_starts_with(trim($fileContent), ' + */ + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(AstRun::class); + } + + public function findContentByHash(string $inputHash): ?AstRun + { + return $this->repository->findOneBy(['inputHash' => $inputHash]); + } +} diff --git a/app/src/Request/CreateAstRunRequest.php b/app/src/Request/CreateAstRunRequest.php new file mode 100644 index 0000000..cf6895a --- /dev/null +++ b/app/src/Request/CreateAstRunRequest.php @@ -0,0 +1,56 @@ +code = $astRun->getCode(); + + return $self; + } +} diff --git a/app/symfony.lock b/app/symfony.lock index 36542be..fe759a1 100644 --- a/app/symfony.lock +++ b/app/symfony.lock @@ -107,6 +107,15 @@ "src/Kernel.php" ] }, + "symfony/maker-bundle": { + "version": "1.59", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "1.0", + "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" + } + }, "symfony/routing": { "version": "7.0", "recipe": { diff --git a/app/templates/ast/_form.html.twig b/app/templates/ast/_form.html.twig new file mode 100644 index 0000000..b12f71f --- /dev/null +++ b/app/templates/ast/_form.html.twig @@ -0,0 +1,19 @@ +{% if astRun is defined %} +
+{% endif %} + +{{ form_start(form) }} +
+
+
+ + {{ form_errors(form.code) }} +
+
+ + + +{{ form_end(form) }} diff --git a/app/templates/ast/create.html.twig b/app/templates/ast/create.html.twig new file mode 100644 index 0000000..b016b37 --- /dev/null +++ b/app/templates/ast/create.html.twig @@ -0,0 +1,5 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ include('ast/_form.html.twig') }} +{% endblock %} diff --git a/app/templates/ast/index.html.twig b/app/templates/ast/index.html.twig new file mode 100644 index 0000000..3bb96c4 --- /dev/null +++ b/app/templates/ast/index.html.twig @@ -0,0 +1,25 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello AstController!{% endblock %} + +{% block body %} + Fill in the PHP code you want to see the AST of: + + {{ include('ast/_form.html.twig') }} + + {% if astRun is defined %} +
<?php {{ clickableNodesDump|raw }}
+ +

Selected code is represented by following abstract syntax tree:

+ +
+
+
{{ simpleNodeDump }}
+
+
+ {% endif %} +{% endblock %} + +{% block javascripts %} + {{ encore_entry_script_tags('ast') }} +{% endblock %} \ No newline at end of file diff --git a/app/templates/base.html.twig b/app/templates/base.html.twig index d3f7079..c08d9ee 100644 --- a/app/templates/base.html.twig +++ b/app/templates/base.html.twig @@ -23,6 +23,9 @@ {% endif %} {% endblock %} + +{% block javascripts %} + {{ encore_entry_script_tags('app') }} +{% endblock %} diff --git a/app/webpack.config.js b/app/webpack.config.js index 32e0fca..8fed2ab 100644 --- a/app/webpack.config.js +++ b/app/webpack.config.js @@ -29,8 +29,7 @@ Encore * and one CSS file (e.g. app.css) if your JavaScript imports CSS. */ .addEntry('app', './assets/js/app.js') - //.addEntry('page1', './assets/js/page1.js') - //.addEntry('page2', './assets/js/page2.js') + .addEntry('ast', './assets/js/ast.js') // When enabled, Webpack "splits" your files into smaller pieces for greater optimization. .splitEntryChunks() From a58fa172a538a7ed7cdb40b15ed6ff4b3f90fa7e Mon Sep 17 00:00:00 2001 From: "Rafalko, Maksim" Date: Sun, 26 May 2024 16:24:22 +0200 Subject: [PATCH 2/3] Add nice UI --- app/assets/css/app.css | 10 +- app/assets/js/app/editor.js | 15 +- app/assets/js/ast.js | 2 + app/migrations/Version20240521220725.php | 31 + app/phpstan.dist.neon | 1 + app/src/Controller/AstController.php | 33 +- app/src/Entity/AstRun.php | 15 + app/src/PhpParser/AttributeKey.php | 55 ++ app/src/PhpParser/ClickablePrinter.php | 571 ++++++++++++------ .../NodeResolver/FocusedNodeResolver.php | 55 ++ .../NodeVisior/NodeMarkerNodeVisitor.php | 55 ++ app/src/PhpParser/PrinterHelper.php | 59 +- app/src/PhpParser/SimpleNodeDumper.php | 153 +++-- app/src/PhpParser/SimplePhpParser.php | 62 +- app/templates/ast/create.html.twig | 9 +- app/templates/ast/index.html.twig | 56 +- app/templates/playground/create.html.twig | 4 + 17 files changed, 929 insertions(+), 257 deletions(-) diff --git a/app/assets/css/app.css b/app/assets/css/app.css index bd6213e..2716238 100644 --- a/app/assets/css/app.css +++ b/app/assets/css/app.css @@ -1,3 +1,11 @@ @tailwind base; @tailwind components; -@tailwind utilities; \ No newline at end of file +@tailwind utilities; + +#clickable-nodes-code a.active-node { + color: forestgreen; +} + +pre code.hljs { + border-radius: .6em; +} \ No newline at end of file diff --git a/app/assets/js/app/editor.js b/app/assets/js/app/editor.js index 2d54192..a6877a3 100644 --- a/app/assets/js/app/editor.js +++ b/app/assets/js/app/editor.js @@ -233,17 +233,10 @@ export function initAstEditor() { : [ 'render('ast/create.html.twig', [ 'form' => $form->createView(), - 'example' => $createAstRunRequest, + 'astRun' => $createAstRunRequest, ]); } #[Route('/ast/{astRunIdHash}/{activeNodeId}', name: 'app_ast_display', defaults: ['activeNodeId' => null], methods: ['GET'])] - public function displayExample(EntityManagerInterface $em, string $astRunIdHash, int|null $activeNodeId = null): Response + public function displayExample(EntityManagerInterface $em, string $astRunIdHash, ?int $activeNodeId = null): Response { /** @var AstRun|null $astRun */ $astRun = $em->find(AstRun::class, $this->hashids->decode($astRunIdHash)[0]); @@ -161,6 +152,7 @@ public function displayExample(EntityManagerInterface $em, string $astRunIdHash, 'astRun' => $createAstRequest, 'clickableNodesDump' => $this->makeNodeClickable($nodes, $astRunIdHash, $activeNodeId), 'simpleNodeDump' => $simpleNodeDump, + 'targetNodeClass' => $targetNodeClass, ]); } @@ -177,13 +169,18 @@ private function makeNodeClickable(array $nodes, string $uuid, ?int $activeNodeI private function resolveTargetNodeClass(Node $node): string { if ($node instanceof UseUse || $node instanceof AttributeGroup) { + /** @var Node $parentNode */ $parentNode = $node->getAttribute('parent'); + return $parentNode::class; } if ($node instanceof Attribute) { + /** @var Node $attributeGroup */ $attributeGroup = $node->getAttribute('parent'); + /** @var Node $stmt */ $stmt = $attributeGroup->getAttribute('parent'); + return $stmt::class; } @@ -202,7 +199,9 @@ private function resolveTargetNodeClass(Node $node): string // target one level up if ($node instanceof Identifier || $node instanceof Name || $node instanceof Variable) { + /** @var Node $parentNode */ $parentNode = $node->getAttribute('parent'); + return $this->resolveTargetNodeClass($parentNode); } diff --git a/app/src/Entity/AstRun.php b/app/src/Entity/AstRun.php index d88eec3..0ad312d 100644 --- a/app/src/Entity/AstRun.php +++ b/app/src/Entity/AstRun.php @@ -91,4 +91,19 @@ public static function hashInput(string $code): string { return md5($code); } + + public function getCreatedAt(): DateTimeImmutable + { + return $this->createdAt; + } + + public function getIdHash(): ?string + { + return $this->idHash; + } + + public function getInputHash(): string + { + return $this->inputHash; + } } diff --git a/app/src/PhpParser/AttributeKey.php b/app/src/PhpParser/AttributeKey.php index b126513..7210d94 100644 --- a/app/src/PhpParser/AttributeKey.php +++ b/app/src/PhpParser/AttributeKey.php @@ -1,4 +1,59 @@ getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pParam($param) ); } @@ -175,11 +232,12 @@ protected function pParam(Param $param): string protected function pArg(Arg $arg): string { $nodeId = $arg->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pArg($arg) ); } @@ -187,11 +245,12 @@ protected function pArg(Arg $arg): string protected function pVariadicPlaceholder(VariadicPlaceholder $variadicPlaceholder): string { $nodeId = $variadicPlaceholder->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pVariadicPlaceholder($variadicPlaceholder) ); } @@ -199,11 +258,12 @@ protected function pVariadicPlaceholder(VariadicPlaceholder $variadicPlaceholder protected function pConst(Const_ $const): string { $nodeId = $const->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pConst($const) ); } @@ -211,11 +271,12 @@ protected function pConst(Const_ $const): string protected function pNullableType(NullableType $nullableType): string { $nodeId = $nullableType->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pNullableType($nullableType) ); } @@ -223,11 +284,12 @@ protected function pNullableType(NullableType $nullableType): string protected function pUnionType(UnionType $unionType): string { $nodeId = $unionType->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pUnionType($unionType) ); } @@ -235,11 +297,12 @@ protected function pUnionType(UnionType $unionType): string protected function pIntersectionType(IntersectionType $intersectionType): string { $nodeId = $intersectionType->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pIntersectionType($intersectionType) ); } @@ -247,11 +310,12 @@ protected function pIntersectionType(IntersectionType $intersectionType): string protected function pIdentifier(Identifier $identifier): string { $nodeId = $identifier->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pIdentifier($identifier) ); } @@ -259,11 +323,12 @@ protected function pIdentifier(Identifier $identifier): string protected function pVarLikeIdentifier(VarLikeIdentifier $varLikeIdentifier): string { $nodeId = $varLikeIdentifier->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pVarLikeIdentifier($varLikeIdentifier) ); } @@ -271,11 +336,12 @@ protected function pVarLikeIdentifier(VarLikeIdentifier $varLikeIdentifier): str protected function pAttribute(Attribute $attribute): string { $nodeId = $attribute->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pAttribute($attribute) ); } @@ -283,11 +349,12 @@ protected function pAttribute(Attribute $attribute): string protected function pAttributeGroup(AttributeGroup $attributeGroup): string { $nodeId = $attributeGroup->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pAttributeGroup($attributeGroup) ); } @@ -295,11 +362,12 @@ protected function pAttributeGroup(AttributeGroup $attributeGroup): string protected function pName(Name $name): string { $nodeId = $name->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pName($name) ); } @@ -307,11 +375,12 @@ protected function pName(Name $name): string protected function pName_FullyQualified(FullyQualified $fullyQualified): string { $nodeId = $fullyQualified->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pName_FullyQualified($fullyQualified) ); } @@ -319,11 +388,12 @@ protected function pName_FullyQualified(FullyQualified $fullyQualified): string protected function pName_Relative(Relative $relative): string { $nodeId = $relative->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pName_Relative($relative) ); } @@ -331,11 +401,12 @@ protected function pName_Relative(Relative $relative): string protected function pScalar_MagicConst_Class(Class_ $class): string { $nodeId = $class->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Class($class) ); } @@ -343,11 +414,12 @@ protected function pScalar_MagicConst_Class(Class_ $class): string protected function pScalar_MagicConst_Dir(Dir $dir): string { $nodeId = $dir->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Dir($dir) ); } @@ -355,11 +427,12 @@ protected function pScalar_MagicConst_Dir(Dir $dir): string protected function pScalar_MagicConst_File(File $file): string { $nodeId = $file->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_File($file) ); } @@ -367,11 +440,12 @@ protected function pScalar_MagicConst_File(File $file): string protected function pScalar_MagicConst_Function(Function_ $function): string { $nodeId = $function->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Function($function) ); } @@ -379,11 +453,12 @@ protected function pScalar_MagicConst_Function(Function_ $function): string protected function pScalar_MagicConst_Line(Line $line): string { $nodeId = $line->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Line($line) ); } @@ -391,11 +466,12 @@ protected function pScalar_MagicConst_Line(Line $line): string protected function pScalar_MagicConst_Method(Method $method): string { $nodeId = $method->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Method($method) ); } @@ -403,11 +479,12 @@ protected function pScalar_MagicConst_Method(Method $method): string protected function pScalar_MagicConst_Namespace(Namespace_ $namespace): string { $nodeId = $namespace->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Namespace($namespace) ); } @@ -415,11 +492,12 @@ protected function pScalar_MagicConst_Namespace(Namespace_ $namespace): string protected function pScalar_MagicConst_Trait(Trait_ $trait): string { $nodeId = $trait->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_MagicConst_Trait($trait) ); } @@ -427,11 +505,12 @@ protected function pScalar_MagicConst_Trait(Trait_ $trait): string protected function pScalar_String(String_ $string): string { $nodeId = $string->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_String($string) ); } @@ -439,11 +518,12 @@ protected function pScalar_String(String_ $string): string protected function pScalar_Encapsed(Encapsed $encapsed): string { $nodeId = $encapsed->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_Encapsed($encapsed) ); } @@ -451,11 +531,12 @@ protected function pScalar_Encapsed(Encapsed $encapsed): string protected function pScalar_LNumber(LNumber $lNumber): string { $nodeId = $lNumber->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_LNumber($lNumber) ); } @@ -463,11 +544,12 @@ protected function pScalar_LNumber(LNumber $lNumber): string protected function pScalar_DNumber(DNumber $dNumber): string { $nodeId = $dNumber->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_DNumber($dNumber) ); } @@ -475,11 +557,12 @@ protected function pScalar_DNumber(DNumber $dNumber): string protected function pScalar_EncapsedStringPart(EncapsedStringPart $encapsedStringPart): string { $nodeId = $encapsedStringPart->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pScalar_EncapsedStringPart($encapsedStringPart) ); } @@ -495,11 +578,12 @@ protected function pExpr_Assign(Assign $assign): string protected function pExpr_AssignRef(AssignRef $assignRef): string { $nodeId = $assignRef->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignRef($assignRef) ); } @@ -507,11 +591,12 @@ protected function pExpr_AssignRef(AssignRef $assignRef): string protected function pExpr_AssignOp_Plus(Plus $plus): string { $nodeId = $plus->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Plus($plus) ); } @@ -519,11 +604,12 @@ protected function pExpr_AssignOp_Plus(Plus $plus): string protected function pExpr_AssignOp_Minus(Minus $minus): string { $nodeId = $minus->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Minus($minus) ); } @@ -531,11 +617,12 @@ protected function pExpr_AssignOp_Minus(Minus $minus): string protected function pExpr_AssignOp_Mul(Mul $mul): string { $nodeId = $mul->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Mul($mul) ); } @@ -543,11 +630,12 @@ protected function pExpr_AssignOp_Mul(Mul $mul): string protected function pExpr_AssignOp_Div(Div $div): string { $nodeId = $div->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Div($div) ); } @@ -555,11 +643,12 @@ protected function pExpr_AssignOp_Div(Div $div): string protected function pExpr_AssignOp_Concat(Concat $concat): string { $nodeId = $concat->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Concat($concat) ); } @@ -567,11 +656,12 @@ protected function pExpr_AssignOp_Concat(Concat $concat): string protected function pExpr_AssignOp_Mod(Mod $mod): string { $nodeId = $mod->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Mod($mod) ); } @@ -579,11 +669,12 @@ protected function pExpr_AssignOp_Mod(Mod $mod): string protected function pExpr_AssignOp_BitwiseAnd(BitwiseAnd $bitwiseAnd): string { $nodeId = $bitwiseAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_BitwiseAnd($bitwiseAnd) ); } @@ -591,11 +682,12 @@ protected function pExpr_AssignOp_BitwiseAnd(BitwiseAnd $bitwiseAnd): string protected function pExpr_AssignOp_BitwiseOr(BitwiseOr $bitwiseOr): string { $nodeId = $bitwiseOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_BitwiseOr($bitwiseOr) ); } @@ -603,11 +695,12 @@ protected function pExpr_AssignOp_BitwiseOr(BitwiseOr $bitwiseOr): string protected function pExpr_AssignOp_BitwiseXor(BitwiseXor $bitwiseXor): string { $nodeId = $bitwiseXor->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_BitwiseXor($bitwiseXor) ); } @@ -615,11 +708,12 @@ protected function pExpr_AssignOp_BitwiseXor(BitwiseXor $bitwiseXor): string protected function pExpr_AssignOp_ShiftLeft(ShiftLeft $shiftLeft): string { $nodeId = $shiftLeft->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_ShiftLeft($shiftLeft) ); } @@ -627,11 +721,12 @@ protected function pExpr_AssignOp_ShiftLeft(ShiftLeft $shiftLeft): string protected function pExpr_AssignOp_ShiftRight(ShiftRight $shiftRight): string { $nodeId = $shiftRight->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_ShiftRight($shiftRight) ); } @@ -639,11 +734,12 @@ protected function pExpr_AssignOp_ShiftRight(ShiftRight $shiftRight): string protected function pExpr_AssignOp_Pow(Pow $pow): string { $nodeId = $pow->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Pow($pow) ); } @@ -651,83 +747,90 @@ protected function pExpr_AssignOp_Pow(Pow $pow): string protected function pExpr_AssignOp_Coalesce(Coalesce $coalesce): string { $nodeId = $coalesce->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_AssignOp_Coalesce($coalesce) ); } - protected function pExpr_BinaryOp_Plus(\PhpParser\Node\Expr\BinaryOp\Plus $plus): string + protected function pExpr_BinaryOp_Plus(Node\Expr\BinaryOp\Plus $plus): string { $nodeId = $plus->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Plus($plus) ); } - protected function pExpr_BinaryOp_Minus(\PhpParser\Node\Expr\BinaryOp\Minus $minus): string + protected function pExpr_BinaryOp_Minus(Node\Expr\BinaryOp\Minus $minus): string { $nodeId = $minus->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Minus($minus) ); } - protected function pExpr_BinaryOp_Mul(\PhpParser\Node\Expr\BinaryOp\Mul $mul): string + protected function pExpr_BinaryOp_Mul(Node\Expr\BinaryOp\Mul $mul): string { $nodeId = $mul->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Mul($mul) ); } - protected function pExpr_BinaryOp_Div(\PhpParser\Node\Expr\BinaryOp\Div $div): string + protected function pExpr_BinaryOp_Div(Node\Expr\BinaryOp\Div $div): string { $nodeId = $div->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Div($div) ); } - protected function pExpr_BinaryOp_Concat(\PhpParser\Node\Expr\BinaryOp\Concat $concat): string + protected function pExpr_BinaryOp_Concat(Node\Expr\BinaryOp\Concat $concat): string { $nodeId = $concat->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Concat($concat) ); } - protected function pExpr_BinaryOp_Mod(\PhpParser\Node\Expr\BinaryOp\Mod $mod): string + protected function pExpr_BinaryOp_Mod(Node\Expr\BinaryOp\Mod $mod): string { $nodeId = $mod->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Mod($mod) ); } @@ -735,11 +838,12 @@ protected function pExpr_BinaryOp_Mod(\PhpParser\Node\Expr\BinaryOp\Mod $mod): s protected function pExpr_BinaryOp_BooleanAnd(BooleanAnd $booleanAnd): string { $nodeId = $booleanAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_BooleanAnd($booleanAnd) ); } @@ -747,83 +851,90 @@ protected function pExpr_BinaryOp_BooleanAnd(BooleanAnd $booleanAnd): string protected function pExpr_BinaryOp_BooleanOr(BooleanOr $booleanOr): string { $nodeId = $booleanOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_BooleanOr($booleanOr) ); } - protected function pExpr_BinaryOp_BitwiseAnd(\PhpParser\Node\Expr\BinaryOp\BitwiseAnd $bitwiseAnd): string + protected function pExpr_BinaryOp_BitwiseAnd(Node\Expr\BinaryOp\BitwiseAnd $bitwiseAnd): string { $nodeId = $bitwiseAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_BitwiseAnd($bitwiseAnd) ); } - protected function pExpr_BinaryOp_BitwiseOr(\PhpParser\Node\Expr\BinaryOp\BitwiseOr $bitwiseOr): string + protected function pExpr_BinaryOp_BitwiseOr(Node\Expr\BinaryOp\BitwiseOr $bitwiseOr): string { $nodeId = $bitwiseOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_BitwiseOr($bitwiseOr) ); } - protected function pExpr_BinaryOp_BitwiseXor(\PhpParser\Node\Expr\BinaryOp\BitwiseXor $bitwiseXor): string + protected function pExpr_BinaryOp_BitwiseXor(Node\Expr\BinaryOp\BitwiseXor $bitwiseXor): string { $nodeId = $bitwiseXor->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_BitwiseXor($bitwiseXor) ); } - protected function pExpr_BinaryOp_ShiftLeft(\PhpParser\Node\Expr\BinaryOp\ShiftLeft $shiftLeft): string + protected function pExpr_BinaryOp_ShiftLeft(Node\Expr\BinaryOp\ShiftLeft $shiftLeft): string { $nodeId = $shiftLeft->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_ShiftLeft($shiftLeft) ); } - protected function pExpr_BinaryOp_ShiftRight(\PhpParser\Node\Expr\BinaryOp\ShiftRight $shiftRight): string + protected function pExpr_BinaryOp_ShiftRight(Node\Expr\BinaryOp\ShiftRight $shiftRight): string { $nodeId = $shiftRight->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_ShiftRight($shiftRight) ); } - protected function pExpr_BinaryOp_Pow(\PhpParser\Node\Expr\BinaryOp\Pow $pow): string + protected function pExpr_BinaryOp_Pow(Node\Expr\BinaryOp\Pow $pow): string { $nodeId = $pow->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_Pow($pow) ); } @@ -831,11 +942,12 @@ protected function pExpr_BinaryOp_Pow(\PhpParser\Node\Expr\BinaryOp\Pow $pow): s protected function pExpr_BinaryOp_LogicalAnd(LogicalAnd $logicalAnd): string { $nodeId = $logicalAnd->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_LogicalAnd($logicalAnd) ); } @@ -843,11 +955,12 @@ protected function pExpr_BinaryOp_LogicalAnd(LogicalAnd $logicalAnd): string protected function pExpr_BinaryOp_LogicalOr(LogicalOr $logicalOr): string { $nodeId = $logicalOr->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BinaryOp_LogicalOr($logicalOr) ); } @@ -995,7 +1108,7 @@ protected function pExpr_BinaryOp_SmallerOrEqual(SmallerOrEqual $smallerOrEqual) return $this->pInfixOp(SmallerOrEqual::class, $smallerOrEqual->left, $link, $smallerOrEqual->right); } - protected function pExpr_BinaryOp_Coalesce(\PhpParser\Node\Expr\BinaryOp\Coalesce $coalesce): string + protected function pExpr_BinaryOp_Coalesce(Node\Expr\BinaryOp\Coalesce $coalesce): string { $nodeId = $coalesce->getAttribute(AttributeKey::NODE_ID); @@ -1006,17 +1119,18 @@ protected function pExpr_BinaryOp_Coalesce(\PhpParser\Node\Expr\BinaryOp\Coalesc $this->activeNodeId ); - return $this->pInfixOp(\PhpParser\Node\Expr\BinaryOp\Coalesce::class, $coalesce->left, $link, $coalesce->right); + return $this->pInfixOp(Node\Expr\BinaryOp\Coalesce::class, $coalesce->left, $link, $coalesce->right); } protected function pExpr_Instanceof(Instanceof_ $instanceof): string { $nodeId = $instanceof->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Instanceof($instanceof) ); } @@ -1024,11 +1138,12 @@ protected function pExpr_Instanceof(Instanceof_ $instanceof): string protected function pExpr_BooleanNot(BooleanNot $booleanNot): string { $nodeId = $booleanNot->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BooleanNot($booleanNot) ); } @@ -1036,11 +1151,12 @@ protected function pExpr_BooleanNot(BooleanNot $booleanNot): string protected function pExpr_BitwiseNot(BitwiseNot $bitwiseNot): string { $nodeId = $bitwiseNot->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_BitwiseNot($bitwiseNot) ); } @@ -1048,11 +1164,12 @@ protected function pExpr_BitwiseNot(BitwiseNot $bitwiseNot): string protected function pExpr_UnaryMinus(UnaryMinus $unaryMinus): string { $nodeId = $unaryMinus->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_UnaryMinus($unaryMinus) ); } @@ -1060,11 +1177,12 @@ protected function pExpr_UnaryMinus(UnaryMinus $unaryMinus): string protected function pExpr_UnaryPlus(UnaryPlus $unaryPlus): string { $nodeId = $unaryPlus->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_UnaryPlus($unaryPlus) ); } @@ -1072,11 +1190,12 @@ protected function pExpr_UnaryPlus(UnaryPlus $unaryPlus): string protected function pExpr_PreInc(PreInc $preInc): string { $nodeId = $preInc->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_PreInc($preInc) ); } @@ -1084,11 +1203,12 @@ protected function pExpr_PreInc(PreInc $preInc): string protected function pExpr_PreDec(PreDec $preDec): string { $nodeId = $preDec->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_PreDec($preDec) ); } @@ -1096,11 +1216,12 @@ protected function pExpr_PreDec(PreDec $preDec): string protected function pExpr_PostInc(PostInc $postInc): string { $nodeId = $postInc->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_PostInc($postInc) ); } @@ -1108,11 +1229,12 @@ protected function pExpr_PostInc(PostInc $postInc): string protected function pExpr_PostDec(PostDec $postDec): string { $nodeId = $postDec->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_PostDec($postDec) ); } @@ -1120,11 +1242,12 @@ protected function pExpr_PostDec(PostDec $postDec): string protected function pExpr_ErrorSuppress(ErrorSuppress $errorSuppress): string { $nodeId = $errorSuppress->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ErrorSuppress($errorSuppress) ); } @@ -1132,11 +1255,12 @@ protected function pExpr_ErrorSuppress(ErrorSuppress $errorSuppress): string protected function pExpr_YieldFrom(YieldFrom $yieldFrom): string { $nodeId = $yieldFrom->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_YieldFrom($yieldFrom) ); } @@ -1144,11 +1268,12 @@ protected function pExpr_YieldFrom(YieldFrom $yieldFrom): string protected function pExpr_Print(Print_ $print): string { $nodeId = $print->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Print($print) ); } @@ -1156,11 +1281,12 @@ protected function pExpr_Print(Print_ $print): string protected function pExpr_Cast_Int(Int_ $int): string { $nodeId = $int->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_Int($int) ); } @@ -1168,23 +1294,25 @@ protected function pExpr_Cast_Int(Int_ $int): string protected function pExpr_Cast_Double(Double $double): string { $nodeId = $double->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_Double($double) ); } - protected function pExpr_Cast_String(\PhpParser\Node\Expr\Cast\String_ $string): string + protected function pExpr_Cast_String(Node\Expr\Cast\String_ $string): string { $nodeId = $string->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_String($string) ); } @@ -1192,11 +1320,12 @@ protected function pExpr_Cast_String(\PhpParser\Node\Expr\Cast\String_ $string): protected function pExpr_Cast_Array(Array_ $array): string { $nodeId = $array->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_Array($array) ); } @@ -1204,11 +1333,12 @@ protected function pExpr_Cast_Array(Array_ $array): string protected function pExpr_Cast_Object(Object_ $object): string { $nodeId = $object->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_Object($object) ); } @@ -1216,11 +1346,12 @@ protected function pExpr_Cast_Object(Object_ $object): string protected function pExpr_Cast_Bool(Bool_ $bool): string { $nodeId = $bool->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_Bool($bool) ); } @@ -1228,11 +1359,12 @@ protected function pExpr_Cast_Bool(Bool_ $bool): string protected function pExpr_Cast_Unset(Unset_ $unset): string { $nodeId = $unset->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Cast_Unset($unset) ); } @@ -1240,11 +1372,12 @@ protected function pExpr_Cast_Unset(Unset_ $unset): string protected function pExpr_FuncCall(FuncCall $funcCall): string { $nodeId = $funcCall->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_FuncCall($funcCall) ); } @@ -1260,7 +1393,7 @@ protected function pExpr_MethodCall(MethodCall $methodCall): string '->', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', ); return $this->pDereferenceLhs($methodCall->var) . $link . $this->pObjectProperty($methodCall->name) @@ -1270,11 +1403,12 @@ protected function pExpr_MethodCall(MethodCall $methodCall): string protected function pExpr_NullsafeMethodCall(NullsafeMethodCall $nullsafeMethodCall): string { $nodeId = $nullsafeMethodCall->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_NullsafeMethodCall($nullsafeMethodCall) ); } @@ -1282,11 +1416,12 @@ protected function pExpr_NullsafeMethodCall(NullsafeMethodCall $nullsafeMethodCa protected function pExpr_StaticCall(StaticCall $staticCall): string { $nodeId = $staticCall->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_StaticCall($staticCall) ); } @@ -1294,11 +1429,12 @@ protected function pExpr_StaticCall(StaticCall $staticCall): string protected function pExpr_Empty(Empty_ $empty): string { $nodeId = $empty->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Empty($empty) ); } @@ -1306,11 +1442,12 @@ protected function pExpr_Empty(Empty_ $empty): string protected function pExpr_Isset(Isset_ $isset): string { $nodeId = $isset->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Isset($isset) ); } @@ -1318,11 +1455,12 @@ protected function pExpr_Isset(Isset_ $isset): string protected function pExpr_Eval(Eval_ $eval): string { $nodeId = $eval->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Eval($eval) ); } @@ -1330,11 +1468,12 @@ protected function pExpr_Eval(Eval_ $eval): string protected function pExpr_Include(Include_ $include): string { $nodeId = $include->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Include($include) ); } @@ -1342,11 +1481,12 @@ protected function pExpr_Include(Include_ $include): string protected function pExpr_List(List_ $list): string { $nodeId = $list->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_List($list) ); } @@ -1354,11 +1494,12 @@ protected function pExpr_List(List_ $list): string protected function pExpr_Error(Error $error): string { $nodeId = $error->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Error($error) ); } @@ -1366,23 +1507,25 @@ protected function pExpr_Error(Error $error): string protected function pExpr_Variable(Variable $variable): string { $nodeId = $variable->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Variable($variable) ); } - protected function pExpr_Array(\PhpParser\Node\Expr\Array_ $array): string + protected function pExpr_Array(Node\Expr\Array_ $array): string { $nodeId = $array->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Array($array) ); } @@ -1390,11 +1533,12 @@ protected function pExpr_Array(\PhpParser\Node\Expr\Array_ $array): string protected function pExpr_ArrayItem(ArrayItem $arrayItem): string { $nodeId = $arrayItem->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ArrayItem($arrayItem) ); } @@ -1402,11 +1546,12 @@ protected function pExpr_ArrayItem(ArrayItem $arrayItem): string protected function pExpr_ArrayDimFetch(ArrayDimFetch $arrayDimFetch): string { $nodeId = $arrayDimFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ArrayDimFetch($arrayDimFetch) ); } @@ -1414,11 +1559,12 @@ protected function pExpr_ArrayDimFetch(ArrayDimFetch $arrayDimFetch): string protected function pExpr_ConstFetch(ConstFetch $constFetch): string { $nodeId = $constFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ConstFetch($constFetch) ); } @@ -1431,7 +1577,7 @@ protected function pExpr_ClassConstFetch(ClassConstFetch $classConstFetch): stri '::', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', ); return $this->pStaticDereferenceLhs($classConstFetch->class) . $link . $this->pObjectProperty( @@ -1450,11 +1596,12 @@ protected function pExpr_PropertyFetch(PropertyFetch $propertyFetch): string protected function pExpr_NullsafePropertyFetch(NullsafePropertyFetch $nullsafePropertyFetch): string { $nodeId = $nullsafePropertyFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_NullsafePropertyFetch($nullsafePropertyFetch) ); } @@ -1462,11 +1609,12 @@ protected function pExpr_NullsafePropertyFetch(NullsafePropertyFetch $nullsafePr protected function pExpr_StaticPropertyFetch(StaticPropertyFetch $staticPropertyFetch): string { $nodeId = $staticPropertyFetch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_StaticPropertyFetch($staticPropertyFetch) ); } @@ -1474,11 +1622,12 @@ protected function pExpr_StaticPropertyFetch(StaticPropertyFetch $staticProperty protected function pExpr_ShellExec(ShellExec $shellExec): string { $nodeId = $shellExec->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ShellExec($shellExec) ); } @@ -1486,11 +1635,12 @@ protected function pExpr_ShellExec(ShellExec $shellExec): string protected function pExpr_Closure(Closure $node): string { $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Closure($node) ); } @@ -1498,11 +1648,12 @@ protected function pExpr_Closure(Closure $node): string protected function pExpr_Match(Match_ $match): string { $nodeId = $match->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Match($match) ); } @@ -1510,11 +1661,12 @@ protected function pExpr_Match(Match_ $match): string protected function pMatchArm(MatchArm $matchArm): string { $nodeId = $matchArm->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pMatchArm($matchArm) ); } @@ -1522,11 +1674,12 @@ protected function pMatchArm(MatchArm $matchArm): string protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction): string { $nodeId = $arrowFunction->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ArrowFunction($arrowFunction) ); } @@ -1534,11 +1687,12 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction): string protected function pExpr_ClosureUse(ClosureUse $node): string { $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_ClosureUse($node) ); } @@ -1546,11 +1700,12 @@ protected function pExpr_ClosureUse(ClosureUse $node): string protected function pExpr_New(New_ $new): string { $nodeId = $new->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_New($new) ); } @@ -1558,11 +1713,12 @@ protected function pExpr_New(New_ $new): string protected function pExpr_Clone(Clone_ $clone): string { $nodeId = $clone->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Clone($clone) ); } @@ -1570,11 +1726,12 @@ protected function pExpr_Clone(Clone_ $clone): string protected function pExpr_Ternary(Ternary $ternary): string { $nodeId = $ternary->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Ternary($ternary) ); } @@ -1582,11 +1739,12 @@ protected function pExpr_Ternary(Ternary $ternary): string protected function pExpr_Exit(Exit_ $exit): string { $nodeId = $exit->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Exit($exit) ); } @@ -1594,11 +1752,12 @@ protected function pExpr_Exit(Exit_ $exit): string protected function pExpr_Throw(Throw_ $throw): string { $nodeId = $throw->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Throw($throw) ); } @@ -1606,23 +1765,25 @@ protected function pExpr_Throw(Throw_ $throw): string protected function pExpr_Yield(Yield_ $yield): string { $nodeId = $yield->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pExpr_Yield($yield) ); } - protected function pStmt_Namespace(\PhpParser\Node\Stmt\Namespace_ $namespace): string + protected function pStmt_Namespace(Node\Stmt\Namespace_ $namespace): string { $nodeId = $namespace->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Namespace($namespace) ); } @@ -1630,11 +1791,12 @@ protected function pStmt_Namespace(\PhpParser\Node\Stmt\Namespace_ $namespace): protected function pStmt_Use(Use_ $use): string { $nodeId = $use->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Use($use) ); } @@ -1642,11 +1804,12 @@ protected function pStmt_Use(Use_ $use): string protected function pStmt_GroupUse(GroupUse $groupUse): string { $nodeId = $groupUse->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_GroupUse($groupUse) ); } @@ -1654,11 +1817,12 @@ protected function pStmt_GroupUse(GroupUse $groupUse): string protected function pStmt_UseUse(UseUse $useUse): string { $nodeId = $useUse->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_UseUse($useUse) ); } @@ -1666,11 +1830,12 @@ protected function pStmt_UseUse(UseUse $useUse): string protected function pStmt_Interface(Interface_ $interface): string { $nodeId = $interface->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Interface($interface) ); } @@ -1678,35 +1843,38 @@ protected function pStmt_Interface(Interface_ $interface): string protected function pStmt_Enum(Enum_ $enum): string { $nodeId = $enum->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Enum($enum) ); } - protected function pStmt_Class(\PhpParser\Node\Stmt\Class_ $class): string + protected function pStmt_Class(Node\Stmt\Class_ $class): string { $nodeId = $class->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Class($class) ); } - protected function pStmt_Trait(\PhpParser\Node\Stmt\Trait_ $trait): string + protected function pStmt_Trait(Node\Stmt\Trait_ $trait): string { $nodeId = $trait->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Trait($trait) ); } @@ -1714,11 +1882,12 @@ protected function pStmt_Trait(\PhpParser\Node\Stmt\Trait_ $trait): string protected function pStmt_EnumCase(EnumCase $enumCase): string { $nodeId = $enumCase->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_EnumCase($enumCase) ); } @@ -1726,11 +1895,12 @@ protected function pStmt_EnumCase(EnumCase $enumCase): string protected function pStmt_TraitUse(TraitUse $traitUse): string { $nodeId = $traitUse->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_TraitUse($traitUse) ); } @@ -1738,11 +1908,12 @@ protected function pStmt_TraitUse(TraitUse $traitUse): string protected function pStmt_TraitUseAdaptation_Precedence(Precedence $precedence): string { $nodeId = $precedence->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_TraitUseAdaptation_Precedence($precedence) ); } @@ -1750,11 +1921,12 @@ protected function pStmt_TraitUseAdaptation_Precedence(Precedence $precedence): protected function pStmt_TraitUseAdaptation_Alias(Alias $alias): string { $nodeId = $alias->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_TraitUseAdaptation_Alias($alias) ); } @@ -1762,11 +1934,12 @@ protected function pStmt_TraitUseAdaptation_Alias(Alias $alias): string protected function pStmt_Property(Property $property): string { $nodeId = $property->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Property($property) ); } @@ -1774,11 +1947,12 @@ protected function pStmt_Property(Property $property): string protected function pStmt_PropertyProperty(PropertyProperty $propertyProperty): string { $nodeId = $propertyProperty->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_PropertyProperty($propertyProperty) ); } @@ -1786,11 +1960,12 @@ protected function pStmt_PropertyProperty(PropertyProperty $propertyProperty): s protected function pStmt_ClassMethod(ClassMethod $classMethod): string { $nodeId = $classMethod->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_ClassMethod($classMethod) ); } @@ -1798,35 +1973,38 @@ protected function pStmt_ClassMethod(ClassMethod $classMethod): string protected function pStmt_ClassConst(ClassConst $classConst): string { $nodeId = $classConst->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_ClassConst($classConst) ); } - protected function pStmt_Function(\PhpParser\Node\Stmt\Function_ $function): string + protected function pStmt_Function(Node\Stmt\Function_ $function): string { $nodeId = $function->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Function($function) ); } - protected function pStmt_Const(\PhpParser\Node\Stmt\Const_ $const): string + protected function pStmt_Const(Node\Stmt\Const_ $const): string { $nodeId = $const->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Const($const) ); } @@ -1834,11 +2012,12 @@ protected function pStmt_Const(\PhpParser\Node\Stmt\Const_ $const): string protected function pStmt_Declare(Declare_ $declare): string { $nodeId = $declare->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Declare($declare) ); } @@ -1846,11 +2025,12 @@ protected function pStmt_Declare(Declare_ $declare): string protected function pStmt_DeclareDeclare(DeclareDeclare $declareDeclare): string { $nodeId = $declareDeclare->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_DeclareDeclare($declareDeclare) ); } @@ -1858,11 +2038,12 @@ protected function pStmt_DeclareDeclare(DeclareDeclare $declareDeclare): string protected function pStmt_If(If_ $if): string { $nodeId = $if->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_If($if) ); } @@ -1870,11 +2051,12 @@ protected function pStmt_If(If_ $if): string protected function pStmt_ElseIf(ElseIf_ $elseIf): string { $nodeId = $elseIf->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_ElseIf($elseIf) ); } @@ -1882,11 +2064,12 @@ protected function pStmt_ElseIf(ElseIf_ $elseIf): string protected function pStmt_Else(Else_ $else): string { $nodeId = $else->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Else($else) ); } @@ -1894,11 +2077,12 @@ protected function pStmt_Else(Else_ $else): string protected function pStmt_For(For_ $for): string { $nodeId = $for->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_For($for) ); } @@ -1906,11 +2090,12 @@ protected function pStmt_For(For_ $for): string protected function pStmt_Foreach(Foreach_ $foreach): string { $nodeId = $foreach->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Foreach($foreach) ); } @@ -1918,11 +2103,12 @@ protected function pStmt_Foreach(Foreach_ $foreach): string protected function pStmt_While(While_ $while): string { $nodeId = $while->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_While($while) ); } @@ -1930,11 +2116,12 @@ protected function pStmt_While(While_ $while): string protected function pStmt_Do(Do_ $do): string { $nodeId = $do->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Do($do) ); } @@ -1942,11 +2129,12 @@ protected function pStmt_Do(Do_ $do): string protected function pStmt_Switch(Switch_ $switch): string { $nodeId = $switch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Switch($switch) ); } @@ -1954,11 +2142,12 @@ protected function pStmt_Switch(Switch_ $switch): string protected function pStmt_Case(Case_ $case): string { $nodeId = $case->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Case($case) ); } @@ -1966,11 +2155,12 @@ protected function pStmt_Case(Case_ $case): string protected function pStmt_TryCatch(TryCatch $tryCatch): string { $nodeId = $tryCatch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_TryCatch($tryCatch) ); } @@ -1978,11 +2168,12 @@ protected function pStmt_TryCatch(TryCatch $tryCatch): string protected function pStmt_Catch(Catch_ $catch): string { $nodeId = $catch->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Catch($catch) ); } @@ -1990,11 +2181,12 @@ protected function pStmt_Catch(Catch_ $catch): string protected function pStmt_Finally(Finally_ $finally): string { $nodeId = $finally->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Finally($finally) ); } @@ -2002,11 +2194,12 @@ protected function pStmt_Finally(Finally_ $finally): string protected function pStmt_Break(Break_ $break): string { $nodeId = $break->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Break($break) ); } @@ -2014,11 +2207,12 @@ protected function pStmt_Break(Break_ $break): string protected function pStmt_Continue(Continue_ $continue): string { $nodeId = $continue->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Continue($continue) ); } @@ -2026,23 +2220,25 @@ protected function pStmt_Continue(Continue_ $continue): string protected function pStmt_Return(Return_ $return): string { $nodeId = $return->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Return($return) ); } - protected function pStmt_Throw(\PhpParser\Node\Stmt\Throw_ $throw): string + protected function pStmt_Throw(Node\Stmt\Throw_ $throw): string { $nodeId = $throw->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Throw($throw) ); } @@ -2050,11 +2246,12 @@ protected function pStmt_Throw(\PhpParser\Node\Stmt\Throw_ $throw): string protected function pStmt_Label(Label $label): string { $nodeId = $label->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Label($label) ); } @@ -2062,11 +2259,12 @@ protected function pStmt_Label(Label $label): string protected function pStmt_Goto(Goto_ $goto): string { $nodeId = $goto->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Goto($goto) ); } @@ -2074,11 +2272,12 @@ protected function pStmt_Goto(Goto_ $goto): string protected function pStmt_Expression(Expression $expression): string { $nodeId = $expression->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Expression($expression) ); } @@ -2086,11 +2285,12 @@ protected function pStmt_Expression(Expression $expression): string protected function pStmt_Echo(Echo_ $echo): string { $nodeId = $echo->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Echo($echo) ); } @@ -2098,11 +2298,12 @@ protected function pStmt_Echo(Echo_ $echo): string protected function pStmt_Static(Static_ $static): string { $nodeId = $static->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Static($static) ); } @@ -2110,11 +2311,12 @@ protected function pStmt_Static(Static_ $static): string protected function pStmt_Global(Global_ $global): string { $nodeId = $global->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Global($global) ); } @@ -2122,23 +2324,25 @@ protected function pStmt_Global(Global_ $global): string protected function pStmt_StaticVar(StaticVar $staticVar): string { $nodeId = $staticVar->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_StaticVar($staticVar) ); } - protected function pStmt_Unset(\PhpParser\Node\Stmt\Unset_ $unset): string + protected function pStmt_Unset(Node\Stmt\Unset_ $unset): string { $nodeId = $unset->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Unset($unset) ); } @@ -2146,11 +2350,12 @@ protected function pStmt_Unset(\PhpParser\Node\Stmt\Unset_ $unset): string protected function pStmt_InlineHTML(InlineHTML $inlineHTML): string { $nodeId = $inlineHTML->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_InlineHTML($inlineHTML) ); } @@ -2158,11 +2363,12 @@ protected function pStmt_InlineHTML(InlineHTML $inlineHTML): string protected function pStmt_HaltCompiler(HaltCompiler $haltCompiler): string { $nodeId = $haltCompiler->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_HaltCompiler($haltCompiler) ); } @@ -2170,11 +2376,12 @@ protected function pStmt_HaltCompiler(HaltCompiler $haltCompiler): string protected function pStmt_Nop(Nop $nop): string { $nodeId = $nop->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pStmt_Nop($nop) ); } @@ -2182,11 +2389,12 @@ protected function pStmt_Nop(Nop $nop): string protected function pObjectProperty($node): string { $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pObjectProperty($node) ); } @@ -2194,11 +2402,12 @@ protected function pObjectProperty($node): string protected function pDereferenceLhs(Node $node): string { $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pDereferenceLhs($node) ); } @@ -2206,11 +2415,12 @@ protected function pDereferenceLhs(Node $node): string protected function pCallLhs(Node $node): string { $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pCallLhs($node) ); } @@ -2218,11 +2428,12 @@ protected function pCallLhs(Node $node): string protected function pNewVariable(Node $node): string { $nodeId = $node->getAttribute(AttributeKey::NODE_ID); + return sprintf( '%s', $this->idHash, $nodeId, - $this->activeNodeId == $nodeId ? 'class="active-node"' : '', + $this->activeNodeId === $nodeId ? 'class="active-node"' : '', parent::pNewVariable($node) ); } diff --git a/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php b/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php index 4c2f8ad..1bdb835 100644 --- a/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php +++ b/app/src/PhpParser/NodeResolver/FocusedNodeResolver.php @@ -1,4 +1,59 @@ %s', $uuid, $nodeId, - $activeNodeId == $nodeId ? 'class="active-node"' : '', + $activeNodeId === $nodeId ? 'class="active-node"' : '', $contents ); } diff --git a/app/src/PhpParser/SimpleNodeDumper.php b/app/src/PhpParser/SimpleNodeDumper.php index 25b8406..45d0675 100644 --- a/app/src/PhpParser/SimpleNodeDumper.php +++ b/app/src/PhpParser/SimpleNodeDumper.php @@ -1,9 +1,70 @@ $value) { $result .= "\n " . $key . ': '; + if ($value === null) { $result .= 'null'; - } elseif ($value === \false) { + } elseif ($value === false) { $result .= 'false'; - } elseif ($value === \true) { + } elseif ($value === true) { $result .= 'true'; - } elseif (\is_string($value)) { + } elseif (is_string($value)) { $result .= '"' . $value . '"'; - } elseif (\is_scalar($value)) { + } elseif (is_scalar($value)) { $result .= $value; } else { - $result .= \str_replace("\n", "\n ", self::dump($value, \false)); + $result .= str_replace("\n", "\n ", self::dump($value, false)); } } - if (\count($node) === 0) { + + if (count($node) === 0) { $result .= ']'; } else { $result .= "\n]"; } + return $result; } + /** * @param mixed[] $items */ - private static function isStringList(array $items) : bool + private static function isStringList(array $items): bool { foreach ($items as $item) { - if (!\is_string($item)) { - return \false; + if (!is_string($item)) { + return false; } } - return \true; + + return true; } - /** - * @param mixed $flags - */ - private static function dumpFlags($flags) : string + + private static function dumpFlags($flags): string { $strs = []; + if (($flags & Class_::MODIFIER_PUBLIC) !== 0) { $strs[] = 'MODIFIER_PUBLIC'; } + if (($flags & Class_::MODIFIER_PROTECTED) !== 0) { $strs[] = 'MODIFIER_PROTECTED'; } + if (($flags & Class_::MODIFIER_PRIVATE) !== 0) { $strs[] = 'MODIFIER_PRIVATE'; } + if (($flags & Class_::MODIFIER_ABSTRACT) !== 0) { $strs[] = 'MODIFIER_ABSTRACT'; } + if (($flags & Class_::MODIFIER_STATIC) !== 0) { $strs[] = 'MODIFIER_STATIC'; } + if (($flags & Class_::MODIFIER_FINAL) !== 0) { $strs[] = 'MODIFIER_FINAL'; } + if (($flags & Class_::MODIFIER_READONLY) !== 0) { $strs[] = 'MODIFIER_READONLY'; } + if ($strs !== []) { - return \implode(' | ', $strs) . ' (' . $flags . ')'; + return implode(' | ', $strs) . ' (' . $flags . ')'; } + return (string) $flags; } + /** * @param int|float|string $type */ - private static function dumpIncludeType($type) : string + private static function dumpIncludeType($type): string { $map = [Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', Include_::TYPE_REQUIRE => 'TYPE_REQUIRE', Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE']; + if (!isset($map[$type])) { return (string) $type; } + return $map[$type] . ' (' . $type . ')'; } - /** - * @param mixed $type - */ - private static function dumpUseType($type) : string + + private static function dumpUseType($type): string { $map = [Use_::TYPE_UNKNOWN => 'TYPE_UNKNOWN', Use_::TYPE_NORMAL => 'TYPE_NORMAL', Use_::TYPE_FUNCTION => 'TYPE_FUNCTION', Use_::TYPE_CONSTANT => 'TYPE_CONSTANT']; + if (!isset($map[$type])) { return (string) $type; } + return $map[$type] . ' (' . $type . ')'; } - private static function dumpSingleNode(Node $node) : string + + private static function dumpSingleNode(Node $node): string { - $result = \get_class($node); + $result = $node::class; + // print simple nodes on same line, to make output more readable - if ($node instanceof Variable && \is_string($node->name)) { + if ($node instanceof Variable && is_string($node->name)) { $result .= '( name: "' . $node->name . '" )'; } elseif ($node instanceof Identifier) { $result .= '( name: "' . $node->name . '" )'; } elseif ($node instanceof Name) { - $result .= '( parts: ' . \json_encode($node->getParts(), 0) . ' )'; + $result .= '( parts: ' . json_encode($node->getParts(), 0) . ' )'; } elseif ($node instanceof Scalar && $node->getSubNodeNames() === ['value']) { - if (\is_string($node->value)) { + if (is_string($node->value)) { $result .= '( value: "' . $node->value . '" )'; } else { $result .= '( value: ' . $node->value . ' )'; } } else { $result .= '('; + foreach ($node->getSubNodeNames() as $key) { $result .= "\n " . $key . ': '; $value = $node->{$key}; + if ($value === null) { $result .= 'null'; - } elseif ($value === \false) { + } elseif ($value === false) { $result .= 'false'; - } elseif ($value === \true) { + } elseif ($value === true) { $result .= 'true'; - } elseif (\is_scalar($value)) { + } elseif (is_scalar($value)) { if ($key === 'flags' || $key === 'newModifier') { $result .= self::dumpFlags($value); } elseif ($key === 'type' && $node instanceof Include_) { $result .= self::dumpIncludeType($value); } elseif ($key === 'type' && ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) { $result .= self::dumpUseType($value); - } elseif (\is_string($value)) { + } elseif (is_string($value)) { $result .= '"' . $value . '"'; } else { $result .= $value; } } else { - $result .= \str_replace("\n", "\n ", self::dump($value, \false)); + $result .= str_replace("\n", "\n ", self::dump($value, false)); } } $result .= "\n)"; } + return $result; } } diff --git a/app/src/PhpParser/SimplePhpParser.php b/app/src/PhpParser/SimplePhpParser.php index 8d3117d..6d15350 100644 --- a/app/src/PhpParser/SimplePhpParser.php +++ b/app/src/PhpParser/SimplePhpParser.php @@ -1,4 +1,59 @@ parseString($fileContent); $foundClass = $this->nodeFinder->findFirstInstanceOf($nodes, Class_::class); - if (! $foundClass instanceof Class_) { + + if (!$foundClass instanceof Class_) { throw new ShouldNotHappenException(); } @@ -69,7 +127,7 @@ public function parseString(string $fileContent): array private function ensureFileContentsHasOpeningTag(string $fileContent): string { - if (! str_starts_with(trim($fileContent), ' + {{ include('ast/_form.html.twig') }} + {% endblock %} + +{% block javascripts %} + {{ encore_entry_script_tags('ast') }} +{% endblock %} \ No newline at end of file diff --git a/app/templates/ast/index.html.twig b/app/templates/ast/index.html.twig index 3bb96c4..fd0d769 100644 --- a/app/templates/ast/index.html.twig +++ b/app/templates/ast/index.html.twig @@ -1,25 +1,61 @@ {% extends 'base.html.twig' %} -{% block title %}Hello AstController!{% endblock %} +{% block title %}AST Explorer{% endblock %} {% block body %} - Fill in the PHP code you want to see the AST of: +
+ {% if astRun is defined %} +

Click on code part to see its AST

+
<?php
+{{ clickableNodesDump|raw }}
- {{ include('ast/_form.html.twig') }} +

Selected code is represented by following abstract syntax tree:

- {% if astRun is defined %} -
<?php {{ clickableNodesDump|raw }}
+
+
+
{{ simpleNodeDump }}
+
+
+ + {% if targetNodeClass %} +

In Mutator::canMutate() method you can use the following node to mutate it:

+
{{ targetNodeClass }}
+ {% endif %} + {% endif %} + +

+ {% if astRun is defined %} + Update the code and generate new AST: + {% else %} + Add PHP code to convert it to AST: + {% endif %} +

+ + {{ include('ast/_form.html.twig') }} -

Selected code is represented by following abstract syntax tree:

-
-
-
{{ simpleNodeDump }}
+
+
+

This AST explorer is highly insired by and uses Rector PHP's code (MIT license)

- {% endif %} +
+{% endblock %} + +{% block stylesheets %} + {{ parent() }} + {% endblock %} {% block javascripts %} + + + + + {{ encore_entry_script_tags('ast') }} {% endblock %} \ No newline at end of file diff --git a/app/templates/playground/create.html.twig b/app/templates/playground/create.html.twig index fcb0ad4..e4c2033 100644 --- a/app/templates/playground/create.html.twig +++ b/app/templates/playground/create.html.twig @@ -3,3 +3,7 @@ {% block body %} {{ include('playground/_form.html.twig') }} {% endblock %} + +{% block javascripts %} + {{ encore_entry_script_tags('app') }} +{% endblock %} \ No newline at end of file From 495a624be68093de1fc5fc6792e21279ef2b1ad5 Mon Sep 17 00:00:00 2001 From: "Rafalko, Maksim" Date: Mon, 27 May 2024 00:44:13 +0200 Subject: [PATCH 3/3] Add tests --- app/src/Controller/AstController.php | 3 + app/src/Form/CreateAstRunType.php | 5 +- app/src/Request/CreateAstRunRequest.php | 2 +- .../Controller/AstControllerTest.php | 89 +++++++++++++++++++ 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 app/tests/Functional/Controller/AstControllerTest.php diff --git a/app/src/Controller/AstController.php b/app/src/Controller/AstController.php index 40431be..0bb6d58 100644 --- a/app/src/Controller/AstController.php +++ b/app/src/Controller/AstController.php @@ -59,6 +59,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; +use Webmozart\Assert\Assert; class AstController extends AbstractController { @@ -92,6 +93,8 @@ public function createExample(Request $request, EntityManagerInterface $em): Res $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + Assert::notNull($createAstRunRequest->code); + $existingAstRun = $this->astRunRepository->findContentByHash( AstRun::hashInput($createAstRunRequest->code) ); diff --git a/app/src/Form/CreateAstRunType.php b/app/src/Form/CreateAstRunType.php index 6cc8c6f..fc78e00 100644 --- a/app/src/Form/CreateAstRunType.php +++ b/app/src/Form/CreateAstRunType.php @@ -45,10 +45,7 @@ class CreateAstRunType extends AbstractType { - /** - * @var UrlGeneratorInterface - */ - private $urlGenerator; + private UrlGeneratorInterface $urlGenerator; public function __construct(UrlGeneratorInterface $urlGenerator) { diff --git a/app/src/Request/CreateAstRunRequest.php b/app/src/Request/CreateAstRunRequest.php index cf6895a..0c8f1c3 100644 --- a/app/src/Request/CreateAstRunRequest.php +++ b/app/src/Request/CreateAstRunRequest.php @@ -43,7 +43,7 @@ class CreateAstRunRequest { #[AppAssert\ValidPhpCode] #[Assert\NotBlank] - public string $code; + public ?string $code = null; public static function fromEntity(AstRun $astRun): self { diff --git a/app/tests/Functional/Controller/AstControllerTest.php b/app/tests/Functional/Controller/AstControllerTest.php new file mode 100644 index 0000000..5cc236c --- /dev/null +++ b/app/tests/Functional/Controller/AstControllerTest.php @@ -0,0 +1,89 @@ +catchExceptions(false); + + $client->request('GET', '/ast'); + static::assertSame(200, $client->getResponse()->getStatusCode()); + + $client->submitForm('create_ast_run[buildAst]', [ + 'create_ast_run[code]' => 'code', + ]); + + static::assertSame(302, $client->getResponse()->getStatusCode()); + static::assertStringNotContainsString('This value should not be blank', (string) $client->getResponse()->getContent()); + } + + public function test_it_fails_with_when_code_is_blank(): void + { + $client = static::createClient(); + $client->followRedirects(); + $client->catchExceptions(false); + + $client->request('GET', '/ast'); + + $client->submitForm('create_ast_run[buildAst]', [ + 'create_ast_run[code]' => '', + ]); + + static::assertSame(200, $client->getResponse()->getStatusCode()); + static::assertStringContainsString('This value should not be blank', (string) $client->getResponse()->getContent()); + } + + public function test_it_fails_with_when_code_is_invalid(): void + { + $client = static::createClient(); + $client->followRedirects(); + $client->catchExceptions(false); + + $client->request('GET', '/ast'); + + $client->submitForm('create_ast_run[buildAst]', [ + 'create_ast_run[code]' => 'getResponse()->getStatusCode()); + static::assertStringContainsString('This is not a valid PHP code. Errors: Syntax error, unexpected', (string) $client->getResponse()->getContent()); + } +}