1740 Commits

Author SHA1 Message Date
Nikita Popov
d24745ddbc Respect precedence during clone pretty printing
Clone is the prefix operator with the highest operator precedence,
but was not treated as an operator at all.
2023-02-26 14:58:17 +01:00
Nikita Popov
cd3c0c11e4 Remove __halt_compiler from semi reserved keyword list
Apparently PHP does not allow use of __halt_compiler as a
semi-reserved keyword.
2023-02-26 12:32:22 +01:00
Nikita Popov
f6ddde6428 Perform end label check on escaped string
Escaping might convert a label character into an escape sequence
if it is not valid UTF-8.
2023-02-26 12:27:05 +01:00
Nikita Popov
47626c74ec Handle interpolated variable after end label
Interpolated variables start with non-label characters, and as
such also count as end label terminators since PHP 7.3.
2023-02-26 12:20:32 +01:00
Nikita Popov
ce3337b0c2 Update allowed characters after doc string label
With the introduction of flexible doc strings, the ending label
is no longer required to be followed by a semicolon or newline.
We need to prevent doc string printing if the label is followed
by any non-label character.
2023-02-26 12:14:04 +01:00
Nikita Popov
d83562e6fe Print INF as 1.0E+1000
This makes pretty printing round trip to another Float literal,
rather than a constant lookup. The 1e1000 form in particular is
chosen because that seems to be the typical form used in various
tests.
2023-02-26 09:47:19 +01:00
Nikita Popov
55cc60c286 Add tools directory to export-ignore 2023-02-26 09:41:02 +01:00
Nikita Popov
2df8878f5d [PHP 8.3] Support dynamic class const fetch
RFC: https://wiki.php.net/rfc/dynamic_class_constant_fetch
2023-01-29 20:49:00 +01:00
Markus Staab
8ad4129442
Declare list types (#907)
Closes #905
2022-12-14 22:59:53 +01:00
Markus Staab
4c4af21df8
Rewrote overly magic code to make it readable (#906)
New code inspired by 950bf8f1d1/lib/PhpParser/Builder/Trait_.php (L43)
2022-12-14 22:58:37 +01:00
Nikita Popov
21a3e8cac5 Fix attrGroups/attributes confusion in EnumCase builder
Found by staabm in #907.
2022-12-14 21:50:11 +01:00
Nikita Popov
950bf8f1d1 Adjust tests to work on 32-bit
Fixes #662.
2022-11-12 16:19:15 +01:00
Nikita Popov
4ce9781260 Fix parsing of large hex floats containing "e"
These ended up taking the code path for normal floats and being
cast to zero.
2022-11-12 16:15:32 +01:00
Nikita Popov
f077f76557 Add some unit tests for PhpVersion 2022-10-30 18:00:30 +01:00
Nikita Popov
b0edd4c411 Bail out on PHP tags in removed code
If dropping a node would drop PHP tags, bail out of formatting
preservation. This will lose formatting, but at least produce
legal code.

Closes GH-884.
2022-09-21 20:42:21 +02:00
Nikita Popov
bad10e1618 Add more tests for formatting preservation with InlineHTML
It's all broken...
2022-09-21 20:28:52 +02:00
Nikita Popov
4bcdf74b8b Add support for perserving formatting for static modifier change
Closes GH-891.
2022-09-21 18:56:58 +02:00
Abdul Malik Ikhsan
46558ed9a5 Show missing format preservation when adding static modifier to closure 2022-09-21 18:49:23 +02:00
Nikita Popov
5573afc06e Test PHP 8.2 in CI 2022-09-18 15:33:40 +02:00
Nikita Popov
0dd85ebd34 Support readonly before DNF type
This makes us match the PHP 8.2 handling of readonly. Handling of
"readonly" functions is moved to the parser to allow distinguishing
them from readonly properties with DNF types. We have to uglify the
grammar to avoid some shift/reduce conflicts. Thank you WordPress.
2022-09-18 15:32:34 +02:00
Nikita Popov
132690f2f8 Slightly more precise type 2022-09-17 21:19:37 +02:00
Nikita Popov
f7b448fa15 Bail out on list insertion of non-Node
PhpStan correctly detected that this is not supported. We could
add support for it, but for now just make sure it doesn't crash.
2022-09-17 21:14:31 +02:00
Nikita Popov
b3ad14b938 Fix some types 2022-09-17 20:33:04 +02:00
Nikita Popov
9f9c2ea81b Use PhpStan level 6
New baseline errors are array types that I prefer to leave alone,
as well as one PhpStan bug:
https://github.com/phpstan/phpstan/issues/4526
2022-09-17 18:49:51 +02:00
Nikita Popov
f98341f688 Specify more types 2022-09-17 18:48:56 +02:00
Nikita Popov
fc6b4890ef Specify more types 2022-09-17 16:45:25 +02:00
Nikita Popov
032b102146 Remove deprecated Error constructor
And use this chance to provide accurate position information for
namespace errors.
2022-09-11 22:05:47 +02:00
Nikita Popov
40c89cf924 Specify some more types 2022-09-11 21:54:39 +02:00
Nikita Popov
a099803d01 Use array<string, mixed> type for $attributes
Slightly more accurate, and stops PHPStan from complaining about
the missing array type information.
2022-09-11 20:51:31 +02:00
Nikita Popov
c595989e4d Support adding class constants in trait builder
These are allowed as of PHP 8.2.
2022-09-11 19:34:27 +02:00
Nikita Popov
6af204467c Add some missing property types 2022-09-11 19:30:14 +02:00
Nikita Popov
48f470eac7 Add missing return types 2022-09-11 18:17:05 +02:00
Nikita Popov
43d6332dce Add return types to PrettyPrinter\Standard 2022-09-11 17:49:41 +02:00
Nikita Popov
9b46dffb12 Fix formatting preservation for alternative elseif/else syntax
Test taken from PR #797.
2022-09-11 16:58:35 +02:00
Nikita Popov
205bd75aa8 Add isPublic() etc methods on Param node
Also isPromoted() to check for any flags.
2022-09-11 16:11:32 +02:00
Nikita Popov
031c5e6ed0 Move verifyModifier/verifyClassModifier to Modifiers class
Now that the Modifiers are in a separate class, these *internal*
verification methods should also be moved there.
2022-09-11 16:05:21 +02:00
Christopher Hertel
36b2a996ca Add isReadonly on Param node 2022-09-11 16:05:10 +02:00
Nikita Popov
b9fe3449e8 Add missing parameter types 2022-09-11 15:22:23 +02:00
Nikita Popov
e9800cf7d3 Add tools/ directory
With php-cs-fixer and phpstan. Also reformat one file.
2022-09-11 13:17:17 +02:00
Nikita Popov
2070cb7cb2 Drop phpstan from composer.json
It does not support PHP 7.1, so we should not include it
unconditionally.
2022-09-11 12:45:59 +02:00
Nikita Popov
9b5a2c8991 Use PHPStan level 5 2022-09-11 12:40:08 +02:00
Nikita Popov
8dfce13d77 Add phpstan baseline 2022-09-11 12:31:50 +02:00
Nikita Popov
f59f226f65 Fix some phpstan warnings 2022-09-11 12:16:12 +02:00
Jaroslav Hanslík
468c0ef6bc Fixed type in UnionType
(cherry picked from commit 2f1fd784fe5560675722a1e5cbbcece5f43bf3a0)
2022-09-10 22:42:32 +02:00
Nikita Popov
b4b60c8460 Remove phpunit 6.5
With the minimum version raised to PHP 7.1, there should be no
more need for PHPUnit 6.
2022-09-06 20:29:27 +02:00
Nikita Popov
636f066b76 Use Node\ClosureUse instead of Expr\ClosureUse in parser
Fixes #883.
2022-09-05 18:35:39 +02:00
Ondřej Mirtes
7362f2b2d0 Fix pretty printing example 2022-09-05 10:32:21 +02:00
Nikita Popov
96037b3d33 Release PHP-Parser 5.0.0-alpha1 v5.0.0alpha1 2022-09-04 18:58:01 +02:00
Nikita Popov
8d02d37e42 More docs updates 2022-09-04 18:55:27 +02:00
Nikita Popov
e68b17cc3b Add --version flag to php-parse 2022-09-04 16:31:39 +02:00