mamuz / PhpDependencyAnalysis

Static code analysis to find violations in a dependency graph
http://mamuz.github.io/PhpDependencyAnalysis/
MIT License
563 stars 45 forks source link

Array union types aren't handled properly #49

Open Daimona opened 4 years ago

Daimona commented 4 years ago

My Environment (version of the project, operating system, or hardware): Any environment will do. I'm using phpda 2.0.2 from composer.

My phpda.yml: Any config file, e.g. the default.

When I run this command: vendor/bin/phpda

If the project analyzed uses PSR5 array union types, e.g.

* @return (string|array)[]

You get:

Warning "\array)" is not a valid Fqsen. on line [line + file]

PSR5 array union types are already supported by TypeResolver/ReflectionDocBlock. The problem seems to be that, in order to parse the union type, TypeResolver splits the line at ( and )[] (ref). However, NameResolver strips every occurrence of [], hence TypeResolver will try to split (string|array), which in turn gives the following parts:

[ '(', 'string', '|', 'array)' ]

and the last one isn't recognised as a valid type.