Git Product home page Git Product logo

Comments (4)

ruudk avatar ruudk commented on August 25, 2024

I modified the namespace resolver with the following patch:

diff --git a/visitor/namespace_resolver.go b/visitor/namespace_resolver.go
index dc7f78f..31e8400 100644
--- a/visitor/namespace_resolver.go
+++ b/visitor/namespace_resolver.go
@@ -289,7 +289,7 @@ func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string,
                if aliasType == "const" && len(n.Parts) == 1 {
                        part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
                        if part == "true" || part == "false" || part == "null" {
-                               return part, nil
+                               return "", errors.New("ignore")
                        }
                }

@@ -316,7 +316,7 @@ func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string,
                        case "iterable":
                                fallthrough
                        case "object":
-                               return part, nil
+                               return "", errors.New("ignore")
                        }
                }

And now it outputs correctly

Checking ./test.php
Found *name.Name: App\Domain\Repository\CartRepository
Found *name.Name: SimpleBus\Message\Recorder\RecordsMessages
Found *name.Name: App\Domain\Command\ChangeCurrencyCommand
Found *name.Name: App\Domain\Event\CurrencyChangedEvent
Found *stmt.Class: App\Domain\Handler\Cart\ChangeCurrencyHandler

from php-parser.

z7zmey avatar z7zmey commented on August 25, 2024

The main idea is that all *name.Name must have an appropriate resolved name. It allows working with them in a similar way. So when we traverse AST there is no need to check is it a function name or is it a name of a reserved constant.

<?
namespace foo;

function true() {
    return true;
}

from php-parser.

ruudk avatar ruudk commented on August 25, 2024

But since they all are *name.Name there is no way to tell if it's a FQCN or something else?

from php-parser.

z7zmey avatar z7zmey commented on August 25, 2024

There are few ways to resolve only fully qualified class names

First(simple) - write the same visitor that resolves only FQCN.
It must be implemented in the client code. In this way, you can apply your logic how to process nodes.

Second - add in the all nodes link to their parent node so you will able filter FQN by their parent nodes.
It most flexible approach but It would create an additional load at the parsing level.

from php-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.