Merge branch 'master' into refactoring

This commit is contained in:
Vadym Slizov
2020-07-29 22:23:44 +02:00
9 changed files with 5899 additions and 4548 deletions

View File

@@ -133,6 +133,12 @@ func (nsr *NamespaceResolver) ExprClosure(n *ast.ExprClosure) {
}
}
func (nsr *NamespaceResolver) StmtPropertyList(n *ast.StmtPropertyList) {
if n.Type != nil {
nsr.ResolveType(n.Type)
}
}
func (nsr *NamespaceResolver) StmtConstList(n *ast.StmtConstList) {
for _, constant := range n.Consts {
nsr.AddNamespacedName(constant, string(constant.(*ast.StmtConstant).ConstantName.(*ast.Identifier).Value))

View File

@@ -978,3 +978,55 @@ func TestDoNotResolveReservedSpecialNames(t *testing.T) {
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
}
func TestResolvePropertyTypeName(t *testing.T) {
nameSimple := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("A")}, &ast.NameNamePart{Value: []byte("B")}}}
nameRelative := &ast.NameRelative{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("A")}, &ast.NameNamePart{Value: []byte("B")}}}
nameFullyQualified := &ast.NameFullyQualified{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("A")}, &ast.NameNamePart{Value: []byte("B")}}}
propertyNodeSimple := &ast.StmtPropertyList{
Type: nameSimple,
}
propertyNodeRelative := &ast.StmtPropertyList{
Type: nameRelative,
}
propertyNodeFullyQualified := &ast.StmtPropertyList{
Type: nameFullyQualified,
}
classNode := &ast.StmtClass{
ClassName: &ast.Identifier{Value: []byte("Bar")},
Stmts: []ast.Vertex{
propertyNodeSimple,
propertyNodeRelative,
propertyNodeFullyQualified,
},
}
stmts := &ast.StmtStmtList{
Stmts: []ast.Vertex{
&ast.StmtNamespace{
NamespaceName: &ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{Value: []byte("Foo")},
},
},
},
classNode,
},
}
expected := map[ast.Vertex]string{
nameSimple: "Foo\\A\\B",
nameRelative: "Foo\\A\\B",
nameFullyQualified: "A\\B",
classNode: "Foo\\Bar",
}
nsResolver := visitor.NewNamespaceResolver()
dfsTraverser := traverser.NewDFS(nsResolver)
dfsTraverser.Traverse(stmts)
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
}