205 Commits

Author SHA1 Message Date
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
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
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
George Peter Banyard
9b2a01aa0c
Add support for DNF types (#862) 2022-08-07 17:10:11 +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
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
9c5eb3ccba Add some missing type annotations 2022-06-04 12:48:12 +02:00
Tomas Votruba
678ccbe072
[PHP 8.2] Add readonly class support (#834)
RFC: https://wiki.php.net/rfc/readonly_classes

PHP implementation: php/php-src#7305
2022-05-15 23:19:31 +02:00
Tomas Votruba
5d83adcc0e
[String_] Add rawValue attribute (#831) 2022-05-15 23:04:59 +02:00
Tomas Votruba
3bf0082455
[DNumber] Add rawValue attribute to hold the original value (#833) 2022-05-15 18:12:28 +02:00
Tomas Votruba
d3eb10aca1
[LNumber] Add rawValue attribute to LNumber to allow numeric separator etc. (#832) 2022-05-15 18:09:05 +02:00
Ondrej Mirtes
f4b835f7d8 Fix PHPDoc type of namespacedName properties 2021-12-06 21:33:02 +01:00
Nikita Popov
f09f22760e Declare namespacedName property
For historical reasons, this property is used by the NameResolver
(in default mode). Declare it explicitly, rather than using a doc
comment.
2021-11-27 21:02:58 +01:00
Nikita Popov
4122ff3a91 Make NullsafeMethodCall extend from CallLike 2021-11-14 17:43:29 +01:00
Jaroslav Hanslík
8da6d7ac62 Fixed ArrowFunction::$expr 2021-10-09 11:26:27 +02:00
Nikita Popov
a45fb2a621 Add CallLike parent class
This provides a helper to determine whether a call is a first-class
callable, and a way to strip the args type to Arg[] if it isn't.
2021-09-12 22:29:08 +02:00
Nikita Popov
08501991d4 Don't make VariadicPlaceholder an expression
And don't store it in an Arg.
2021-09-12 21:59:26 +02:00
Nikita Popov
13549aa794 Add support for first-class callables
I'm somewhat unsure about the AST structure here.
VariadicPlaceholder is not a general expression. Maybe Arg->expr
should be Expr|VariadicPlaceholder? Or possibly the call arguments
should be an array of Arg|VariadicPlaceholder?
2021-09-03 17:18:40 +02:00
Nikita Popov
def24f2224 Add support for explicit octal literals 2021-09-03 16:29:30 +02:00
Nikita Popov
ace6c67a8a Add support for intersection types 2021-09-03 15:06:33 +02:00
Nikita Popov
0483391aca Introduce ComplexType base class
With the upcoming addition of intersection types, a type can
be Identifier|Name|NullableType|UnionType|IntersectionType, which
is quite the mouthful. Give NullableType and UnionType a common
base class ComplexType, which does not have any behavior, but
allows to write these types (and check them in instanceof) more
easily.
2021-09-02 18:35:05 +02:00
Máté Kocsis
55c4269232
Add support for new PHP 8.1 modifiers (#796)
Implement support for readonly properties (https://wiki.php.net/rfc/readonly_properties_v2) and
final class contstants (https://wiki.php.net/rfc/final_class_const).
2021-07-21 12:43:29 +02:00
Tomas Votruba
f68e1a43ff
[PHP 8.1] Add support for enums (#758)
RFC: https://wiki.php.net/rfc/enumerations

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-04-25 21:11:36 +02:00
Oskar Stark
8165cf69fa CS fix 2021-02-02 09:57:47 +01:00
Tomas Votruba
4c22c62783
[PHP 8.0] Add attributes support (#661)
Adds support for PHP 8 attributes, represented using `AttrGroup` nodes
containing `Attribute` nodes. The `attrGroup` subnode is added to all
nodes that can have attributes.

This is still missing FPPP support.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-09-13 21:01:17 +02:00
Ondřej Mirtes
4a40a84cf6 Fixed PHPDoc typo 2020-09-02 12:33:46 +02:00
Viktor Szépe
56356e4aec Remove repeated word from PHPDoc in Name 2020-08-23 08:59:38 +02:00
Nikita Popov
a98350581c Add support for throw expression 2020-08-09 20:52:55 +02:00
Nikita Popov
98f7f39d1c Add named argument support
Not adding any explicit FPPP support, as I don't think add/remove
of names can be handled any better than full reformatting.
2020-08-09 17:37:44 +02:00
Nikita Popov
23d9c17770 Add support for nullsafe operator 2020-08-09 12:08:05 +02:00
Alex
54fc023b25
Update Array_ annotations, items are nullable (#696)
When used to destructure, items are optional. E.g. `[$a, , $b] = [1, 2, 3];`.
2020-08-08 10:04:21 +02:00
Tomas Votruba
69c5d48afd
[PHP 8.0] Add match expressions (#672)
RFC:  https://wiki.php.net/rfc/match_expression_v2
Upstream implementation: php/php-src#5371

Closes #671.
2020-07-15 21:40:05 +02:00
TomasVotruba
b58b19ed1d Add constructor promotion support 2020-06-27 17:57:47 +02:00
TomasVotruba
b5f5313d73 [PHP 8.0] Add exception witout variable 2020-06-03 09:18:13 +02:00
Ruud Kamphuis
64f4d5b619 Add getProperty to ClassLike 2020-02-09 22:43:42 +01:00
Nikita Popov
664c10121e Add support for union types
We definitely need to introduce a general "Type" abstraction in
the next major version.
2019-11-08 14:45:32 +01:00
Tomas Votruba
006acba066 add getTraitUses() method to ClassLike 2019-08-31 09:26:51 +02:00