Nikita Popov
03ccfa3dd4
Rename Stmt\DeclareDeclare to DeclareItem
2022-09-03 18:45:28 +02:00
Nikita Popov
a3b0541c71
Support array return from enterNode()
...
This uses the same semantics as arrays from leaveNode(), i.e. the
returned nodes will not be visited by other visitors. This is open
to change though (but probably should change for both enterNode()
and leaveNode() if it does change?)
2022-09-03 18:38:22 +02:00
Nikita Popov
c42290ae42
Support REMOVE_NODE from enterNode()
2022-09-03 18:15:36 +02:00
Nikita Popov
a44faa6328
Rename Scalar\Encapsed to Scalar\InterpolatedString
2022-09-03 15:14:04 +02:00
Nikita Popov
11caa3b9cc
Add compat shim for EncapsedStringPart
2022-09-03 15:08:39 +02:00
Nikita Popov
f4ec6a1e53
Rename Scalar\EncapsedStringPart to InterpolatedStringPart
...
It is no longer an expression node, which unfortunately does
require a more awkward type for the Encaps node.
2022-09-03 13:25:23 +02:00
Nikita Popov
23835d20ef
Rename Scalar\LNumber to Scalar\Int_
2022-09-03 12:07:38 +02:00
Nikita Popov
66b20bd6bc
Rename Scalar\DNumber to Scalar\Float_
2022-09-03 11:56:06 +02:00
Nikita Popov
2b562b72a8
Update default of ClassMethod::$flags in docs
...
This defaults to 0, not Modifiers::PUBLIC.
2022-09-03 11:02:16 +02:00
Nikita Popov
f5b56a5c4c
Remove MODIFIER_ prefix from node dumps
...
These constants are now called Modifiers::PUBLIC rather than
Class_::MODIFIER_PUBLIC etc, so update the dumped name as well.
2022-09-03 11:00:13 +02:00
Nikita Popov
a2608f0b74
Support empty list insertion for attributes
2022-09-03 10:52:01 +02:00
Nikita Popov
035c1c7cd2
Rename Stmt\StaticVar to StaticVar
...
This is part of a statement, not a statement by itself.
2022-09-02 22:51:13 +02:00
Nikita Popov
8be56afd2d
Rename Expr\ArrayItem to ArrayItem
...
Array items are not expressions by themselves.
2022-09-02 22:41:10 +02:00
Nikita Popov
0933986293
Make sure Array nodes can not contain null
...
Now that destructuring is always represented using List nodes,
make sure that Array nodes can no longer contain null elements,
so well-typed code doesn't have to deal with them unnecessarily.
If an array does contain empty elements, these are now result in
an error and are represented as a ArrayItem with Error value if
error recovery is used.
The implementation is a bit tricky because at the time the Array
node is created, we cannot tell whether it will be used in a
creation or destructuring context. For this reason the error
reporting is delayed parsing has finished.
Closes #876 .
2022-09-01 22:12:58 +02:00
Anton
9857581ee8
Add array/callable to BUILTIN_TYPE_VERSIONS
...
Listing these is not strictly necessary, in that array/callable
are keywords, and as such don't use the relevant code path. We
can still include them for the sake of completeness.
Closes #872 .
2022-08-29 22:09:29 +02:00
Nikita Popov
a2753c8218
Require strict_types in php-cs-fixer config
2022-08-28 23:02:46 +02:00
Nikita Popov
dd63ddbc24
Add php-cs-fixer config and reformat
...
The formatting in this project has become something of a mess,
because it changed over time. Add a CS fixer config and reformat
to the desired style, which is PSR-12, but with sane brace placement.
2022-08-28 22:57:06 +02:00
Nikita Popov
f62b2bfdec
Introduce separate Modifiers class
...
Use PhpParser\Modifiers::PUBLIC instead of
PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC, etc. Old constants
of course remain available.
Fixes #476 .
2022-08-28 21:20:26 +02:00
Nikita Popov
68fc1ba4cb
Always use List_ node for array destructuring
...
Fixes #471 .
2022-08-28 18:48:26 +02:00
Nikita Popov
53b907d405
Fix length bounds check in Name::slice()
...
The length check did not take into account that there may be a
non-zero offset at this point.
Fixes #875 .
2022-08-28 14:55:57 +02:00
Tomas Votruba
0201a7ee3f
[docs] Add generic types to NodeFinder to allow returning exact type in static analysis ( #869 )
2022-08-08 21:53:49 +02:00
George Peter Banyard
9b2a01aa0c
Add support for DNF types ( #862 )
2022-08-07 17:10:11 +02:00
Nikita Popov
652fb0c6c1
Print trailing comma in param list if supported
2022-08-07 16:43:53 +02:00
Anton
ea9d6b2238
Always use pMaybeMultiline() for function parameters
...
Closes GH-861.
2022-08-07 16:34:26 +02:00
Nikita Popov
34d8681488
Mark NodeVisitorAbstract as abstract class
...
It doesn't actually have any abstract methods, but doesn't do
anything by itself and is intended for extension only.
Fixes #865 .
2022-08-07 16:30:12 +02:00
Nikita Popov
1f504d2c7d
Don't trim in Comment::getReformattedText()
...
In the past, single-line comments were stored together with the
trailing newline. Later we switched to the PHP8 comment
representation, where the trailing newline is not part of the
comment anymore. As such, there is also no need to trim here.
This is split out from GH-867.
2022-08-07 16:19:39 +02:00
Anton
9ef528f3f5
ParserAbstract: remove undefined class in use
...
Class `PhpParser\Parser\Tokens` not exists in current version
2022-08-07 15:59:06 +02:00
Nikita Popov
cf0cd6003e
Improve heuristic for escaping in single quoted strings
...
It is idiomatic to not escape backslashes if they are followed by
a non-special character.
2022-07-24 22:56:44 +02:00
Nikita Popov
646b490735
Don't force newline after doc string when targeting PHP >= 7.3
2022-07-24 22:15:42 +02:00
Nikita Popov
59145a4443
Treat assignments as unary operators
...
Assignment expressions can be viewed as unary operators where
the whole "$x =" part is the operator.
2022-07-23 21:53:48 +02:00
Nikita Popov
7bf6348240
Remove inc/dec from precedence map
...
Inc/dec are primitive expressions that only accept a variable
operand, rather than a general expression operand.
2022-07-23 21:48:10 +02:00
Nikita Popov
a73c8ee03b
Add a phpVersion option to the pretty printer
...
This is currently just used to initialize the default for short
array syntax.
The default target version in 7.0, which also means that the
default for short arrays is flipped to on.
2022-07-23 18:23:39 +02:00
Nikita Popov
1e89658cae
Add PhpVersion class
2022-07-23 17:52:59 +02:00
MathiasReker
050342b5df
Add visibility modifiers to constants
...
Closes GH-848.
2022-07-23 16:04:21 +02:00
Anton
a3f2bb634d
Add __serialize/__unserialize to ClassMethod::$magicNames
2022-07-23 12:58:49 +02:00
MathiasReker
de4ac93023
Single blank line at eof
...
A PHP file without end tag must always end with a single empty line feed.
2022-07-04 20:38:51 +02:00
MathiasReker
4021a63cef
No superfluous elseif
...
Replaces superfluous elseif with if.
2022-07-04 20:36:22 +02:00
MathiasReker
653757bec6
Nullable type declaration for default null value
...
Adds ? before type declarations for parameters with a default null value
2022-07-04 20:34:31 +02:00
MathiasReker
572af7fff2
No unused imports
...
Unused use statements must be removed.
2022-07-04 17:53:10 +02:00
MathiasReker
0086a261d0
Short scalar cast
...
Cast (boolean) and (integer) should be written as (bool) and (int), (double) and (real) as (float), (binary) as (string).
2022-07-04 17:50:40 +02:00
Nikita Popov
5aae65e627
Add Parser::getLexer() method
...
Not sure if this is going to stick, but for now this makes it
easier to obtain the Lexer instance when creating the parser via
ParserFactory.
2022-06-19 21:05:31 +02:00
Nikita Popov
0ea134a507
Add PHP 8 parser with correct concatenation precedence
...
The PHP 7 and PHP 8 parsers use the same grammar file and only
differ in token precedence.
2022-06-19 20:07:17 +02:00
Nikita Popov
a38a60b7dd
Move Tokens::T_* to Php7::T_*
...
Drop the separate tokens class, move them into the parser.
2022-06-19 18:12:20 +02:00
Nikita Popov
c878d7195d
Move token mapping from lexer to parser
...
This allows a different token mapping per parser.
2022-06-19 18:05:52 +02:00
Nikita Popov
6e0eec807e
Move definition of compatibility tokens into separate file
2022-06-19 17:29:24 +02:00
Nikita Popov
71ed641cd4
Handle true/false/null types in builder APIs
2022-06-19 11:10:43 +02:00
Nikita Popov
e3ff8cf035
Add support for true type
...
The null/false types were alread accepted previously, even though
they are only legal as standalone types since PHP 8.2.
2022-06-19 11:06:39 +02:00
Nikita Popov
b0469d127e
Rename Expr\ClosureUse -> ClosureUse
...
This is not a real expression, treat it similarly to Node\Arg
or Node\Param.
The old name is retained as an alias for compatibility.
2022-06-12 21:55:56 +02:00
Nikita Popov
3fd30f64bc
Remove deprecated param builder method
2022-06-12 21:14:22 +02:00
Nikita Popov
55f29b152c
Improve ParserFactory version targeting
...
Most users will want to pick createForNewestSupportedVersion()
or getForHostVersion(). The currently default is the former,
which can lead to unwanted surprised due to PHP BC breaks for
users that actually want the latter. Make this choice more
explicit.
2022-06-12 18:56:18 +02:00