From c9421988724ab83bffc337c6a55283c953b6e73f Mon Sep 17 00:00:00 2001 From: chx Date: Sat, 19 Oct 2024 20:59:47 +0200 Subject: [PATCH] Document ClassLike/FunctionLike conversions --- doc/2_Usage_of_basic_components.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/2_Usage_of_basic_components.markdown b/doc/2_Usage_of_basic_components.markdown index 462c8adf3e..9d59a25fb1 100644 --- a/doc/2_Usage_of_basic_components.markdown +++ b/doc/2_Usage_of_basic_components.markdown @@ -206,6 +206,12 @@ without the `PhpParser\Node\` prefix and `\` replaced with `_`. It also does not It is possible to associate custom metadata with a node using the `setAttribute()` method. This data can then be retrieved using `hasAttribute()`, `getAttribute()` and `getAttributes()`. +`ClassLike` and `FunctionLike` statements can be converted between each other easily because their +constructor `__construct($name, array $subNodes = [], array $attributes = [])` takes subnodes and +attributes both of which are easy to retrieve, for example if `$node instanceof FunctionLike` then +`new ClassMethod($someName, get_object_vars($node), $node->getAttributes())` will convert it into a +`ClassMethod`. + By default, the parser adds the `startLine`, `endLine`, `startTokenPos`, `endTokenPos`, `startFilePos`, `endFilePos` and `comments` attributes. `comments` is an array of `PhpParser\Comment[\Doc]` instances.