Reclassify node types
Currently there are a number of nodes that extend Expr/Stmt but really aren't expressions or statements. Historically the reason is that they are a direct part of an expression or statement.
The following nodes currently extend Expr but aren't expressions:
- [ ]
Scalar\EncapsedStringPart - [ ]
Expr\ArrayItem - [x]
Expr\ClosureUse(https://github.com/nikic/PHP-Parser/commit/b0469d127e2c1bd3645fbc757ef5e10a5f920c29)
The following nodes currently extend Stmt but aren't statements:
- [ ]
Stmt\DeclareDeclare - [ ]
Stmt\PropertyProperty - [ ]
Stmt\StaticVar - [ ]
Stmt\UseUse
The following are a bit less clear-cut. They are not statements per se but could be considered close enough:
-
Stmt\TraitUseAdaptation\* -
Stmt\Case -
Stmt\Catch -
Stmt\Finally -
Stmt\ElseIf -
Stmt\Else
We might want to move some or all of these out of Expr/Stmt in a future version.
Also, while we're at it, Scalar\Encapsed is not a scalar either, it should be Expr. Scalar\MagicConst is borderline.
And it would probably be good to rename some node types to be more obvious to people not familiar with ext/tokenizer lingo. E.g. Encapsed should be InterpolatedString, DNumber should be Float and LNumber should be Int.
We can keep BC aliases for everything, of course.
Looking more and more on nodes, it would be great to correct categories so they have some added value and people can quickly understand the namespace pattern and rely on it.
All these changes can be easily migrated with https://github.com/rectorphp/rector/blob/master/docs/AllRectorsOverview.md#classreplacerrector So BC is not really a problem.
Planned renames are done. Though I also wonder whether it might make sense to drop the Scalar category and merge it into Expr. Not sure the distinction provides any real value.