mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-06-16 21:00:19 +02:00
Compare commits
38 Commits
v5.0.0alph
...
v4.17.0
Author | SHA1 | Date | |
---|---|---|---|
844c228bf2 | |||
6d2584bdf1 | |||
21a61ece15 | |||
8f8e47b6c1 | |||
0aad06bce3 | |||
80a680bf59 | |||
cfc54e30a4 | |||
05e84f7201 | |||
73ccbabbe7 | |||
19526a33fb | |||
1d0748ad35 | |||
c9e5a13d68 | |||
ba788aa98b | |||
11e2663a5b | |||
11e2dcd96c | |||
0ffddce52d | |||
6bb5176bc4 | |||
cad49f8ed3 | |||
570e980a20 | |||
a50b4310f7 | |||
8863f92b58 | |||
3182d12b55 | |||
1df465cd90 | |||
f59bbe44bf | |||
2e11deec46 | |||
a4fe65bf60 | |||
e072fd2c30 | |||
7027899d7f | |||
2f1fd784fe | |||
0ef6c55a3f | |||
8216e878be | |||
617d0220b9 | |||
a951e9e24d | |||
b30e7e73d5 | |||
ff24d1d61a | |||
e55f8c6b30 | |||
3ee592b6aa | |||
3fe2422e34 |
12
.github/workflows/main.yml
vendored
12
.github/workflows/main.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
name: "PHP 7.0 Unit Tests"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2"
|
||||
uses: "actions/checkout@v3"
|
||||
- name: "Install PHP"
|
||||
uses: "shivammathur/setup-php@v2"
|
||||
with:
|
||||
@ -40,12 +40,10 @@ jobs:
|
||||
- "7.4"
|
||||
- "8.0"
|
||||
- "8.1"
|
||||
include:
|
||||
- php-version: "8.1"
|
||||
flags: "--ignore-platform-req=php"
|
||||
- "8.2"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2"
|
||||
uses: "actions/checkout@v3"
|
||||
- name: "Install PHP"
|
||||
uses: "shivammathur/setup-php@v2"
|
||||
with:
|
||||
@ -61,7 +59,7 @@ jobs:
|
||||
name: "PHP 7.3 Code on PHP 8.0 Integration Tests"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2"
|
||||
uses: "actions/checkout@v3"
|
||||
- name: "Install PHP"
|
||||
uses: "shivammathur/setup-php@v2"
|
||||
with:
|
||||
@ -77,7 +75,7 @@ jobs:
|
||||
name: "PHP 8.1 Code on PHP 7.0 Integration Tests"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2"
|
||||
uses: "actions/checkout@v3"
|
||||
- name: "Install PHP"
|
||||
uses: "shivammathur/setup-php@v2"
|
||||
with:
|
||||
|
82
CHANGELOG.md
82
CHANGELOG.md
@ -1,7 +1,83 @@
|
||||
Version 4.14.1-dev
|
||||
------------------
|
||||
Version 4.17.0 (2023-08-13)
|
||||
---------------------------
|
||||
|
||||
Nothing yet.
|
||||
### Added
|
||||
|
||||
* [PHP 8.3] Added support for typed class constants.
|
||||
* [PHP 8.3] Added supprot for dynamic class constant fetch.
|
||||
* [PHP 8.3] Added support for readonly anonymous classes.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed missing required parentheses when pretty printing new with an expression class name.
|
||||
* Fixed missing required parentheses when pretty printing `(CONST)::$x` and similar.
|
||||
|
||||
Version 4.16.0 (2023-06-25)
|
||||
---------------------------
|
||||
|
||||
### Added
|
||||
|
||||
* Added `Name::getParts()` method for forward-compatibility with PHP-Parser 5.
|
||||
|
||||
### Deprecated
|
||||
|
||||
* Deprecated direct access to `Name::$parts`, which will be removed in PHP-Parser 5.
|
||||
|
||||
Version 4.15.5 (2023-05-19)
|
||||
---------------------------
|
||||
|
||||
### Added
|
||||
|
||||
* Added `makePrivate()`, `makeProtected()`, `makePublic()` and `makeReadonly()` methods to
|
||||
`Builder\Param` to allow the creation of promoted parameters.
|
||||
|
||||
Version 4.15.4 (2023-03-05)
|
||||
---------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed formatting-preservation for alternative if syntax with trailing comments.
|
||||
|
||||
Version 4.15.3 (2023-01-16)
|
||||
---------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Support readonly property with PHP 8.2 DNF type.
|
||||
* Fixed PHP attribute group and PHP-Parser attribute mixup in EnumCase builder.
|
||||
|
||||
Version 4.15.2 (2022-11-12)
|
||||
---------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed parsing of large hex float literals that contain an "e" character.
|
||||
* Fixed tests to pass on 32-bit.
|
||||
* Fixed generation of invalid code when using formatting-preserving pretty printer with code that
|
||||
uses inline HTML.
|
||||
|
||||
Version 4.15.1 (2022-09-04)
|
||||
---------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed formatting preservation when adding *multiple* attributes to a class/method/etc that
|
||||
previously had none. This fixes a regression in the 4.15.0 release.
|
||||
|
||||
Version 4.15.0 (2022-09-03)
|
||||
---------------------------
|
||||
|
||||
### Added
|
||||
|
||||
* PHP 8.2: Added support for `true` type.
|
||||
* PHP 8.2: Added support for DNF types.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Support `readonly` as a function name.
|
||||
* Added `__serialize` and `__unserialize` to magic method list.
|
||||
* Fixed bounds check in `Name::slice()`.
|
||||
* Fixed formatting preservation when adding attributes to a class/method/etc that previously had none.
|
||||
|
||||
Version 4.14.0 (2022-05-31)
|
||||
---------------------------
|
||||
|
@ -3,10 +3,10 @@ PHP Parser
|
||||
|
||||
[](https://coveralls.io/github/nikic/PHP-Parser?branch=master)
|
||||
|
||||
This is a PHP 5.2 to PHP 8.1 parser written in PHP. Its purpose is to simplify static code analysis and
|
||||
This is a PHP 5.2 to PHP 8.2 parser written in PHP. Its purpose is to simplify static code analysis and
|
||||
manipulation.
|
||||
|
||||
[**Documentation for version 4.x**][doc_master] (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.1).
|
||||
[**Documentation for version 4.x**][doc_4_x] (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.2).
|
||||
|
||||
[Documentation for version 3.x][doc_3_x] (unsupported; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.2).
|
||||
|
||||
@ -222,4 +222,4 @@ Component documentation:
|
||||
* Parent and sibling references
|
||||
|
||||
[doc_3_x]: https://github.com/nikic/PHP-Parser/tree/3.x/doc
|
||||
[doc_master]: https://github.com/nikic/PHP-Parser/tree/master/doc
|
||||
[doc_4_x]: https://github.com/nikic/PHP-Parser/tree/4.x/doc
|
||||
|
@ -264,8 +264,13 @@ optional_ellipsis:
|
||||
| T_ELLIPSIS { $$ = true; }
|
||||
;
|
||||
|
||||
identifier_maybe_readonly:
|
||||
identifier { $$ = $1; }
|
||||
| T_READONLY { $$ = Node\Identifier[$1]; }
|
||||
;
|
||||
|
||||
function_declaration_statement:
|
||||
T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
|
||||
T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
|
||||
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
|
||||
;
|
||||
|
||||
@ -721,8 +726,13 @@ lexical_var:
|
||||
optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
|
||||
;
|
||||
|
||||
name_readonly:
|
||||
T_READONLY { $$ = Name[$1]; }
|
||||
;
|
||||
|
||||
function_call:
|
||||
name argument_list { $$ = Expr\FuncCall[$1, $2]; }
|
||||
| name_readonly argument_list { $$ = Expr\FuncCall[$1, $2]; }
|
||||
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list
|
||||
{ $$ = Expr\StaticCall[$1, $3, $4]; }
|
||||
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list
|
||||
@ -998,7 +1008,7 @@ array_pair:
|
||||
| expr { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| expr T_DOUBLE_ARROW ampersand variable { $$ = Expr\ArrayItem[$4, $1, true]; }
|
||||
| ampersand variable { $$ = Expr\ArrayItem[$2, null, true]; }
|
||||
| T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
|
||||
| T_ELLIPSIS expr { $$ = new Expr\ArrayItem($2, null, false, attributes(), true); }
|
||||
;
|
||||
|
||||
encaps_list:
|
||||
|
@ -221,7 +221,10 @@ non_empty_class_const_list:
|
||||
;
|
||||
|
||||
class_const:
|
||||
identifier_maybe_reserved '=' expr { $$ = Node\Const_[$1, $3]; }
|
||||
T_STRING '=' expr
|
||||
{ $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; }
|
||||
| semi_reserved '=' expr
|
||||
{ $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; }
|
||||
;
|
||||
|
||||
inner_statement_list_ex:
|
||||
@ -350,15 +353,23 @@ block_or_error:
|
||||
| error { $$ = []; }
|
||||
;
|
||||
|
||||
identifier_maybe_readonly:
|
||||
identifier_not_reserved { $$ = $1; }
|
||||
| T_READONLY { $$ = Node\Identifier[$1]; }
|
||||
;
|
||||
|
||||
function_declaration_statement:
|
||||
T_FUNCTION optional_ref identifier_not_reserved '(' parameter_list ')' optional_return_type block_or_error
|
||||
T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type block_or_error
|
||||
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $8, 'attrGroups' => []]]; }
|
||||
| attributes T_FUNCTION optional_ref identifier_not_reserved '(' parameter_list ')' optional_return_type block_or_error
|
||||
| attributes T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type block_or_error
|
||||
{ $$ = Stmt\Function_[$4, ['byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => $1]]; }
|
||||
;
|
||||
|
||||
class_declaration_statement:
|
||||
optional_attributes class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}'
|
||||
class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}'
|
||||
{ $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6, 'attrGroups' => []]];
|
||||
$this->checkClass($$, #2); }
|
||||
| attributes class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}'
|
||||
{ $$ = Stmt\Class_[$3, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]];
|
||||
$this->checkClass($$, #3); }
|
||||
| optional_attributes T_INTERFACE identifier_not_reserved interface_extends_list '{' class_statement_list '}'
|
||||
@ -510,7 +521,8 @@ new_elseif_list:
|
||||
;
|
||||
|
||||
new_elseif:
|
||||
T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt\ElseIf_[$3, $6]; }
|
||||
T_ELSEIF '(' expr ')' ':' inner_statement_list
|
||||
{ $$ = Stmt\ElseIf_[$3, $6]; $this->fixupAlternativeElse($$); }
|
||||
;
|
||||
|
||||
else_single:
|
||||
@ -520,7 +532,8 @@ else_single:
|
||||
|
||||
new_else_single:
|
||||
/* empty */ { $$ = null; }
|
||||
| T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; }
|
||||
| T_ELSE ':' inner_statement_list
|
||||
{ $$ = Stmt\Else_[$3]; $this->fixupAlternativeElse($$); }
|
||||
;
|
||||
|
||||
foreach_variable:
|
||||
@ -571,7 +584,7 @@ type_expr:
|
||||
type { $$ = $1; }
|
||||
| '?' type { $$ = Node\NullableType[$2]; }
|
||||
| union_type { $$ = Node\UnionType[$1]; }
|
||||
| intersection_type { $$ = Node\IntersectionType[$1]; }
|
||||
| intersection_type { $$ = $1; }
|
||||
;
|
||||
|
||||
type:
|
||||
@ -585,34 +598,52 @@ type_without_static:
|
||||
| T_CALLABLE { $$ = Node\Identifier['callable']; }
|
||||
;
|
||||
|
||||
union_type_element:
|
||||
type { $$ = $1; }
|
||||
| '(' intersection_type ')' { $$ = $2; }
|
||||
;
|
||||
|
||||
union_type:
|
||||
type '|' type { init($1, $3); }
|
||||
| union_type '|' type { push($1, $3); }
|
||||
union_type_element '|' union_type_element { init($1, $3); }
|
||||
| union_type '|' union_type_element { push($1, $3); }
|
||||
;
|
||||
|
||||
union_type_without_static_element:
|
||||
type_without_static { $$ = $1; }
|
||||
| '(' intersection_type_without_static ')' { $$ = $2; }
|
||||
;
|
||||
|
||||
union_type_without_static:
|
||||
type_without_static '|' type_without_static { init($1, $3); }
|
||||
| union_type_without_static '|' type_without_static { push($1, $3); }
|
||||
union_type_without_static_element '|' union_type_without_static_element { init($1, $3); }
|
||||
| union_type_without_static '|' union_type_without_static_element { push($1, $3); }
|
||||
;
|
||||
|
||||
intersection_type_list:
|
||||
type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { init($1, $3); }
|
||||
| intersection_type_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type
|
||||
{ push($1, $3); }
|
||||
;
|
||||
|
||||
intersection_type:
|
||||
type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { init($1, $3); }
|
||||
| intersection_type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type
|
||||
intersection_type_list { $$ = Node\IntersectionType[$1]; }
|
||||
;
|
||||
|
||||
intersection_type_without_static_list:
|
||||
type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
|
||||
{ init($1, $3); }
|
||||
| intersection_type_without_static_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
|
||||
{ push($1, $3); }
|
||||
;
|
||||
|
||||
intersection_type_without_static:
|
||||
type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
|
||||
{ init($1, $3); }
|
||||
| intersection_type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static
|
||||
{ push($1, $3); }
|
||||
intersection_type_without_static_list { $$ = Node\IntersectionType[$1]; }
|
||||
;
|
||||
|
||||
type_expr_without_static:
|
||||
type_without_static { $$ = $1; }
|
||||
| '?' type_without_static { $$ = Node\NullableType[$2]; }
|
||||
| union_type_without_static { $$ = Node\UnionType[$1]; }
|
||||
| intersection_type_without_static { $$ = Node\IntersectionType[$1]; }
|
||||
| intersection_type_without_static { $$ = $1; }
|
||||
;
|
||||
|
||||
optional_type_without_static:
|
||||
@ -694,6 +725,9 @@ class_statement:
|
||||
| optional_attributes method_modifiers T_CONST class_const_list semi
|
||||
{ $$ = new Stmt\ClassConst($4, $2, attributes(), $1);
|
||||
$this->checkClassConst($$, #2); }
|
||||
| optional_attributes method_modifiers T_CONST type_expr class_const_list semi
|
||||
{ $$ = new Stmt\ClassConst($5, $2, attributes(), $1, $4);
|
||||
$this->checkClassConst($$, #2); }
|
||||
| optional_attributes method_modifiers T_FUNCTION optional_ref identifier_maybe_reserved '(' parameter_list ')'
|
||||
optional_return_type method_body
|
||||
{ $$ = Stmt\ClassMethod[$5, ['type' => $2, 'byRef' => $4, 'params' => $7, 'returnType' => $9, 'stmts' => $10, 'attrGroups' => $1]];
|
||||
@ -915,8 +949,8 @@ expr:
|
||||
;
|
||||
|
||||
anonymous_class:
|
||||
optional_attributes T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
|
||||
{ $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3);
|
||||
optional_attributes class_entry_type ctor_arguments extends_from implements_list '{' class_statement_list '}'
|
||||
{ $$ = array(Stmt\Class_[null, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3);
|
||||
$this->checkClass($$[0], -1); }
|
||||
;
|
||||
|
||||
@ -944,8 +978,13 @@ lexical_var:
|
||||
optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
|
||||
;
|
||||
|
||||
name_readonly:
|
||||
T_READONLY { $$ = Name[$1]; }
|
||||
;
|
||||
|
||||
function_call:
|
||||
name argument_list { $$ = Expr\FuncCall[$1, $2]; }
|
||||
| name_readonly argument_list { $$ = Expr\FuncCall[$1, $2]; }
|
||||
| callable_expr argument_list { $$ = Expr\FuncCall[$1, $2]; }
|
||||
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
|
||||
{ $$ = Expr\StaticCall[$1, $3, $4]; }
|
||||
@ -1007,6 +1046,8 @@ constant:
|
||||
class_constant:
|
||||
class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_maybe_reserved
|
||||
{ $$ = Expr\ClassConstFetch[$1, $3]; }
|
||||
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}'
|
||||
{ $$ = Expr\ClassConstFetch[$1, $4]; }
|
||||
/* We interpret an isolated FOO:: as an unfinished class constant fetch. It could also be
|
||||
an unfinished static property fetch or unfinished scoped call. */
|
||||
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM error
|
||||
@ -1161,7 +1202,7 @@ array_pair:
|
||||
| expr T_DOUBLE_ARROW expr { $$ = Expr\ArrayItem[$3, $1, false]; }
|
||||
| expr T_DOUBLE_ARROW ampersand variable { $$ = Expr\ArrayItem[$4, $1, true]; }
|
||||
| expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; }
|
||||
| T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
|
||||
| T_ELLIPSIS expr { $$ = new Expr\ArrayItem($2, null, false, attributes(), true); }
|
||||
| /* empty */ { $$ = null; }
|
||||
;
|
||||
|
||||
|
@ -19,6 +19,8 @@ class ClassConst implements PhpParser\Builder
|
||||
|
||||
/** @var Node\AttributeGroup[] */
|
||||
protected $attributeGroups = [];
|
||||
/** @var Identifier|Node\Name|Node\ComplexType */
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Creates a class constant builder
|
||||
@ -116,6 +118,19 @@ class ClassConst implements PhpParser\Builder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the constant type.
|
||||
*
|
||||
* @param string|Node\Name|Identifier|Node\ComplexType $type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setType($type) {
|
||||
$this->type = BuilderHelpers::normalizeType($type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the built class node.
|
||||
*
|
||||
@ -126,7 +141,8 @@ class ClassConst implements PhpParser\Builder
|
||||
$this->constants,
|
||||
$this->flags,
|
||||
$this->attributes,
|
||||
$this->attributeGroups
|
||||
$this->attributeGroups,
|
||||
$this->type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ class EnumCase implements PhpParser\Builder
|
||||
return new Stmt\EnumCase(
|
||||
$this->name,
|
||||
$this->value,
|
||||
$this->attributes,
|
||||
$this->attributeGroups
|
||||
$this->attributeGroups,
|
||||
$this->attributes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ class Param implements PhpParser\Builder
|
||||
|
||||
protected $variadic = false;
|
||||
|
||||
protected $flags = 0;
|
||||
|
||||
/** @var Node\AttributeGroup[] */
|
||||
protected $attributeGroups = [];
|
||||
|
||||
@ -95,6 +97,50 @@ class Param implements PhpParser\Builder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the (promoted) parameter public.
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
public function makePublic() {
|
||||
$this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PUBLIC);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the (promoted) parameter protected.
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
public function makeProtected() {
|
||||
$this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PROTECTED);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the (promoted) parameter private.
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
public function makePrivate() {
|
||||
$this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PRIVATE);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the (promoted) parameter readonly.
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
public function makeReadonly() {
|
||||
$this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_READONLY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an attribute group.
|
||||
*
|
||||
@ -116,7 +162,7 @@ class Param implements PhpParser\Builder
|
||||
public function getNode() : Node {
|
||||
return new Node\Param(
|
||||
new Node\Expr\Variable($this->name),
|
||||
$this->default, $this->type, $this->byRef, $this->variadic, [], 0, $this->attributeGroups
|
||||
$this->default, $this->type, $this->byRef, $this->variadic, [], $this->flags, $this->attributeGroups
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -349,15 +349,15 @@ class BuilderFactory
|
||||
/**
|
||||
* Creates a class constant fetch node.
|
||||
*
|
||||
* @param string|Name|Expr $class Class name
|
||||
* @param string|Identifier $name Constant name
|
||||
* @param string|Name|Expr $class Class name
|
||||
* @param string|Identifier|Expr $name Constant name
|
||||
*
|
||||
* @return Expr\ClassConstFetch
|
||||
*/
|
||||
public function classConstFetch($class, $name): Expr\ClassConstFetch {
|
||||
return new Expr\ClassConstFetch(
|
||||
BuilderHelpers::normalizeNameOrExpr($class),
|
||||
BuilderHelpers::normalizeIdentifier($name)
|
||||
BuilderHelpers::normalizeIdentifierOrExpr($name)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,20 @@ final class BuilderHelpers
|
||||
}
|
||||
|
||||
$builtinTypes = [
|
||||
'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object', 'mixed', 'never',
|
||||
'array',
|
||||
'callable',
|
||||
'bool',
|
||||
'int',
|
||||
'float',
|
||||
'string',
|
||||
'iterable',
|
||||
'void',
|
||||
'object',
|
||||
'null',
|
||||
'false',
|
||||
'mixed',
|
||||
'never',
|
||||
'true',
|
||||
];
|
||||
|
||||
$lowerType = strtolower($type);
|
||||
|
@ -19,6 +19,8 @@ class PrintableNewAnonClassNode extends Expr
|
||||
{
|
||||
/** @var Node\AttributeGroup[] PHP attribute groups */
|
||||
public $attrGroups;
|
||||
/** @var int Modifiers */
|
||||
public $flags;
|
||||
/** @var Node\Arg[] Arguments */
|
||||
public $args;
|
||||
/** @var null|Node\Name Name of extended class */
|
||||
@ -29,11 +31,12 @@ class PrintableNewAnonClassNode extends Expr
|
||||
public $stmts;
|
||||
|
||||
public function __construct(
|
||||
array $attrGroups, array $args, Node\Name $extends = null, array $implements,
|
||||
array $attrGroups, int $flags, array $args, Node\Name $extends = null, array $implements,
|
||||
array $stmts, array $attributes
|
||||
) {
|
||||
parent::__construct($attributes);
|
||||
$this->attrGroups = $attrGroups;
|
||||
$this->flags = $flags;
|
||||
$this->args = $args;
|
||||
$this->extends = $extends;
|
||||
$this->implements = $implements;
|
||||
@ -46,7 +49,7 @@ class PrintableNewAnonClassNode extends Expr
|
||||
// We don't assert that $class->name is null here, to allow consumers to assign unique names
|
||||
// to anonymous classes for their own purposes. We simplify ignore the name here.
|
||||
return new self(
|
||||
$class->attrGroups, $newNode->args, $class->extends, $class->implements,
|
||||
$class->attrGroups, $class->flags, $newNode->args, $class->extends, $class->implements,
|
||||
$class->stmts, $newNode->getAttributes()
|
||||
);
|
||||
}
|
||||
@ -56,6 +59,6 @@ class PrintableNewAnonClassNode extends Expr
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
return ['attrGroups', 'args', 'extends', 'implements', 'stmts'];
|
||||
return ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts'];
|
||||
}
|
||||
}
|
||||
|
@ -206,6 +206,11 @@ class TokenStream
|
||||
|| $this->haveTokenInRange($startPos, $endPos, '}');
|
||||
}
|
||||
|
||||
public function haveTagInRange(int $startPos, int $endPos): bool {
|
||||
return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG)
|
||||
|| $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get indentation before token position.
|
||||
*
|
||||
|
@ -14,6 +14,7 @@ use PhpParser\Lexer\TokenEmulator\FnTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\MatchTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\NullsafeTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\NumericLiteralSeparatorEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\ReadonlyFunctionTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\ReadonlyTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\ReverseEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\TokenEmulator;
|
||||
@ -24,6 +25,7 @@ class Emulative extends Lexer
|
||||
const PHP_7_4 = '7.4dev';
|
||||
const PHP_8_0 = '8.0dev';
|
||||
const PHP_8_1 = '8.1dev';
|
||||
const PHP_8_2 = '8.2dev';
|
||||
|
||||
/** @var mixed[] Patches used to reverse changes introduced in the code */
|
||||
private $patches = [];
|
||||
@ -41,7 +43,7 @@ class Emulative extends Lexer
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->targetPhpVersion = $options['phpVersion'] ?? Emulative::PHP_8_1;
|
||||
$this->targetPhpVersion = $options['phpVersion'] ?? Emulative::PHP_8_2;
|
||||
unset($options['phpVersion']);
|
||||
|
||||
parent::__construct($options);
|
||||
@ -57,6 +59,7 @@ class Emulative extends Lexer
|
||||
new EnumTokenEmulator(),
|
||||
new ReadonlyTokenEmulator(),
|
||||
new ExplicitOctalEmulator(),
|
||||
new ReadonlyFunctionTokenEmulator(),
|
||||
];
|
||||
|
||||
// Collect emulators that are relevant for the PHP version we're running
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Lexer\TokenEmulator;
|
||||
|
||||
use PhpParser\Lexer\Emulative;
|
||||
|
||||
/*
|
||||
* In PHP 8.1, "readonly(" was special cased in the lexer in order to support functions with
|
||||
* name readonly. In PHP 8.2, this may conflict with readonly properties having a DNF type. For
|
||||
* this reason, PHP 8.2 instead treats this as T_READONLY and then handles it specially in the
|
||||
* parser. This emulator only exists to handle this special case, which is skipped by the
|
||||
* PHP 8.1 ReadonlyTokenEmulator.
|
||||
*/
|
||||
class ReadonlyFunctionTokenEmulator extends KeywordEmulator {
|
||||
public function getKeywordString(): string {
|
||||
return 'readonly';
|
||||
}
|
||||
|
||||
public function getKeywordToken(): int {
|
||||
return \T_READONLY;
|
||||
}
|
||||
|
||||
public function getPhpVersion(): string {
|
||||
return Emulative::PHP_8_2;
|
||||
}
|
||||
|
||||
public function reverseEmulate(string $code, array $tokens): array {
|
||||
// Don't bother
|
||||
return $tokens;
|
||||
}
|
||||
}
|
@ -10,15 +10,15 @@ class ClassConstFetch extends Expr
|
||||
{
|
||||
/** @var Name|Expr Class name */
|
||||
public $class;
|
||||
/** @var Identifier|Error Constant name */
|
||||
/** @var Identifier|Expr|Error Constant name */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructs a class const fetch node.
|
||||
*
|
||||
* @param Name|Expr $class Class name
|
||||
* @param string|Identifier|Error $name Constant name
|
||||
* @param array $attributes Additional attributes
|
||||
* @param Name|Expr $class Class name
|
||||
* @param string|Identifier|Expr|Error $name Constant name
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $attributes = []) {
|
||||
$this->attributes = $attributes;
|
||||
@ -29,7 +29,7 @@ class ClassConstFetch extends Expr
|
||||
public function getSubNodeNames() : array {
|
||||
return ['class', 'name'];
|
||||
}
|
||||
|
||||
|
||||
public function getType() : string {
|
||||
return 'Expr_ClassConstFetch';
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ use PhpParser\NodeAbstract;
|
||||
|
||||
class Name extends NodeAbstract
|
||||
{
|
||||
/** @var string[] Parts of the name */
|
||||
/**
|
||||
* @var string[] Parts of the name
|
||||
* @deprecated Use getParts() instead
|
||||
*/
|
||||
public $parts;
|
||||
|
||||
private static $specialClassNames = [
|
||||
@ -30,6 +33,15 @@ class Name extends NodeAbstract
|
||||
return ['parts'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parts of name (split by the namespace separator).
|
||||
*
|
||||
* @return string[] Parts of name
|
||||
*/
|
||||
public function getParts(): array {
|
||||
return $this->parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first part of the name, i.e. everything before the first namespace separator.
|
||||
*
|
||||
@ -162,7 +174,7 @@ class Name extends NodeAbstract
|
||||
$realLength = $numParts - $realOffset;
|
||||
} else {
|
||||
$realLength = $length < 0 ? $length + $numParts - $realOffset : $length;
|
||||
if ($realLength < 0 || $realLength > $numParts) {
|
||||
if ($realLength < 0 || $realLength > $numParts - $realOffset) {
|
||||
throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length));
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +47,7 @@ class DNumber extends Scalar
|
||||
public static function parse(string $str) : float {
|
||||
$str = str_replace('_', '', $str);
|
||||
|
||||
// if string contains any of .eE just cast it to float
|
||||
if (false !== strpbrk($str, '.eE')) {
|
||||
return (float) $str;
|
||||
}
|
||||
|
||||
// otherwise it's an integer notation that overflowed into a float
|
||||
// if it starts with 0 it's one of the special integer notations
|
||||
// Check whether this is one of the special integer notations.
|
||||
if ('0' === $str[0]) {
|
||||
// hex
|
||||
if ('x' === $str[1] || 'X' === $str[1]) {
|
||||
@ -65,10 +59,12 @@ class DNumber extends Scalar
|
||||
return bindec($str);
|
||||
}
|
||||
|
||||
// oct
|
||||
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
|
||||
// so that only the digits before that are used
|
||||
return octdec(substr($str, 0, strcspn($str, '89')));
|
||||
// oct, but only if the string does not contain any of '.eE'.
|
||||
if (false === strpbrk($str, '.eE')) {
|
||||
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
|
||||
// (8 or 9) so that only the digits before that are used.
|
||||
return octdec(substr($str, 0, strcspn($str, '89')));
|
||||
}
|
||||
}
|
||||
|
||||
// dec
|
||||
|
@ -10,31 +10,36 @@ class ClassConst extends Node\Stmt
|
||||
public $flags;
|
||||
/** @var Node\Const_[] Constant declarations */
|
||||
public $consts;
|
||||
/** @var Node\AttributeGroup[] */
|
||||
/** @var Node\AttributeGroup[] PHP attribute groups */
|
||||
public $attrGroups;
|
||||
/** @var Node\Identifier|Node\Name|Node\ComplexType Type declaration */
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* Constructs a class const list node.
|
||||
*
|
||||
* @param Node\Const_[] $consts Constant declarations
|
||||
* @param int $flags Modifiers
|
||||
* @param array $attributes Additional attributes
|
||||
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups
|
||||
* @param Node\Const_[] $consts Constant declarations
|
||||
* @param int $flags Modifiers
|
||||
* @param array $attributes Additional attributes
|
||||
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups
|
||||
* @param null|string|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration
|
||||
*/
|
||||
public function __construct(
|
||||
array $consts,
|
||||
int $flags = 0,
|
||||
array $attributes = [],
|
||||
array $attrGroups = []
|
||||
array $attrGroups = [],
|
||||
$type = null
|
||||
) {
|
||||
$this->attributes = $attributes;
|
||||
$this->flags = $flags;
|
||||
$this->consts = $consts;
|
||||
$this->attrGroups = $attrGroups;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
return ['attrGroups', 'flags', 'consts'];
|
||||
return ['attrGroups', 'flags', 'type', 'consts'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,21 +23,23 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
public $attrGroups;
|
||||
|
||||
private static $magicNames = [
|
||||
'__construct' => true,
|
||||
'__destruct' => true,
|
||||
'__call' => true,
|
||||
'__callstatic' => true,
|
||||
'__get' => true,
|
||||
'__set' => true,
|
||||
'__isset' => true,
|
||||
'__unset' => true,
|
||||
'__sleep' => true,
|
||||
'__wakeup' => true,
|
||||
'__tostring' => true,
|
||||
'__set_state' => true,
|
||||
'__clone' => true,
|
||||
'__invoke' => true,
|
||||
'__debuginfo' => true,
|
||||
'__construct' => true,
|
||||
'__destruct' => true,
|
||||
'__call' => true,
|
||||
'__callstatic' => true,
|
||||
'__get' => true,
|
||||
'__set' => true,
|
||||
'__isset' => true,
|
||||
'__unset' => true,
|
||||
'__sleep' => true,
|
||||
'__wakeup' => true,
|
||||
'__tostring' => true,
|
||||
'__set_state' => true,
|
||||
'__clone' => true,
|
||||
'__invoke' => true,
|
||||
'__debuginfo' => true,
|
||||
'__serialize' => true,
|
||||
'__unserialize' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -4,13 +4,13 @@ namespace PhpParser\Node;
|
||||
|
||||
class UnionType extends ComplexType
|
||||
{
|
||||
/** @var (Identifier|Name)[] Types */
|
||||
/** @var (Identifier|Name|IntersectionType)[] Types */
|
||||
public $types;
|
||||
|
||||
/**
|
||||
* Constructs a union type.
|
||||
*
|
||||
* @param (Identifier|Name)[] $types Types
|
||||
* @param (Identifier|Name|IntersectionType)[] $types Types
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $types, array $attributes = []) {
|
||||
|
@ -161,7 +161,7 @@ class NameResolver extends NodeVisitorAbstract
|
||||
return null;
|
||||
}
|
||||
|
||||
private function addAlias(Stmt\UseUse $use, $type, Name $prefix = null) {
|
||||
private function addAlias(Stmt\UseUse $use, int $type, Name $prefix = null) {
|
||||
// Add prefix for group uses
|
||||
$name = $prefix ? Name::concat($prefix, $use->name) : $use->name;
|
||||
// Type is determined either by individual element or whole use declaration
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -16,9 +16,12 @@ use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
use PhpParser\Node\Stmt\ElseIf_;
|
||||
use PhpParser\Node\Stmt\Enum_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Nop;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
@ -664,6 +667,7 @@ abstract class ParserAbstract implements Parser
|
||||
'false' => true,
|
||||
'mixed' => true,
|
||||
'never' => true,
|
||||
'true' => true,
|
||||
];
|
||||
|
||||
if (!$name->isUnqualified()) {
|
||||
@ -875,6 +879,24 @@ abstract class ParserAbstract implements Parser
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/** @param ElseIf_|Else_ $node */
|
||||
protected function fixupAlternativeElse($node) {
|
||||
// Make sure a trailing nop statement carrying comments is part of the node.
|
||||
$numStmts = \count($node->stmts);
|
||||
if ($numStmts !== 0 && $node->stmts[$numStmts - 1] instanceof Nop) {
|
||||
$nopAttrs = $node->stmts[$numStmts - 1]->getAttributes();
|
||||
if (isset($nopAttrs['endLine'])) {
|
||||
$node->setAttribute('endLine', $nopAttrs['endLine']);
|
||||
}
|
||||
if (isset($nopAttrs['endFilePos'])) {
|
||||
$node->setAttribute('endFilePos', $nopAttrs['endFilePos']);
|
||||
}
|
||||
if (isset($nopAttrs['endTokenPos'])) {
|
||||
$node->setAttribute('endTokenPos', $nopAttrs['endTokenPos']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkClassModifier($a, $b, $modifierPos) {
|
||||
try {
|
||||
Class_::verifyClassModifier($a, $b);
|
||||
|
@ -46,7 +46,15 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
protected function pUnionType(Node\UnionType $node) {
|
||||
return $this->pImplode($node->types, '|');
|
||||
$types = [];
|
||||
foreach ($node->types as $typeNode) {
|
||||
if ($typeNode instanceof Node\IntersectionType) {
|
||||
$types[] = '('. $this->p($typeNode) . ')';
|
||||
continue;
|
||||
}
|
||||
$types[] = $this->p($typeNode);
|
||||
}
|
||||
return implode('|', $types);
|
||||
}
|
||||
|
||||
protected function pIntersectionType(Node\IntersectionType $node) {
|
||||
@ -521,7 +529,7 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
protected function pExpr_StaticCall(Expr\StaticCall $node) {
|
||||
return $this->pDereferenceLhs($node->class) . '::'
|
||||
return $this->pStaticDereferenceLhs($node->class) . '::'
|
||||
. ($node->name instanceof Expr
|
||||
? ($node->name instanceof Expr\Variable
|
||||
? $this->p($node->name)
|
||||
@ -598,7 +606,7 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
|
||||
return $this->pDereferenceLhs($node->class) . '::' . $this->p($node->name);
|
||||
return $this->pStaticDereferenceLhs($node->class) . '::' . $this->pObjectProperty($node->name);
|
||||
}
|
||||
|
||||
protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) {
|
||||
@ -610,7 +618,7 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) {
|
||||
return $this->pDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name);
|
||||
return $this->pStaticDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name);
|
||||
}
|
||||
|
||||
protected function pExpr_ShellExec(Expr\ShellExec $node) {
|
||||
@ -806,7 +814,9 @@ class Standard extends PrettyPrinterAbstract
|
||||
protected function pStmt_ClassConst(Stmt\ClassConst $node) {
|
||||
return $this->pAttrGroups($node->attrGroups)
|
||||
. $this->pModifiers($node->flags)
|
||||
. 'const ' . $this->pCommaSeparated($node->consts) . ';';
|
||||
. 'const '
|
||||
. (null !== $node->type ? $this->p($node->type) . ' ' : '')
|
||||
. $this->pCommaSeparated($node->consts) . ';';
|
||||
}
|
||||
|
||||
protected function pStmt_Function(Stmt\Function_ $node) {
|
||||
@ -1059,6 +1069,14 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
}
|
||||
|
||||
protected function pStaticDereferenceLhs(Node $node) {
|
||||
if (!$this->staticDereferenceLhsRequiresParens($node)) {
|
||||
return $this->p($node);
|
||||
} else {
|
||||
return '(' . $this->p($node) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
protected function pCallLhs(Node $node) {
|
||||
if (!$this->callLhsRequiresParens($node)) {
|
||||
return $this->p($node);
|
||||
@ -1067,9 +1085,12 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
}
|
||||
|
||||
protected function pNewVariable(Node $node) {
|
||||
// TODO: This is not fully accurate.
|
||||
return $this->pDereferenceLhs($node);
|
||||
protected function pNewVariable(Node $node): string {
|
||||
if (!$this->newOperandRequiresParens($node)) {
|
||||
return $this->p($node);
|
||||
} else {
|
||||
return '(' . $this->p($node) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,6 +21,8 @@ abstract class PrettyPrinterAbstract
|
||||
const FIXUP_BRACED_NAME = 4; // Name operand that may require bracing
|
||||
const FIXUP_VAR_BRACED_NAME = 5; // Name operand that may require ${} bracing
|
||||
const FIXUP_ENCAPSED = 6; // Encapsed string part
|
||||
const FIXUP_NEW = 7; // New/instanceof operand
|
||||
const FIXUP_STATIC_DEREF_LHS = 8; // LHS of static dereferencing operation
|
||||
|
||||
protected $precedenceMap = [
|
||||
// [precedence, associativity]
|
||||
@ -774,7 +776,8 @@ abstract class PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
if ($skipRemovedNode) {
|
||||
if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) {
|
||||
if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
|
||||
$this->origTokens->haveTagInRange($pos, $itemStartPos))) {
|
||||
// We'd remove the brace of a code block.
|
||||
// TODO: Preserve formatting.
|
||||
$this->setIndentLevel($origIndentLevel);
|
||||
@ -877,7 +880,8 @@ abstract class PrettyPrinterAbstract
|
||||
$pos, $itemStartPos, $indentAdjustment);
|
||||
$skipRemovedNode = true;
|
||||
} else {
|
||||
if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) {
|
||||
if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
|
||||
$this->origTokens->haveTagInRange($pos, $itemStartPos))) {
|
||||
// We'd remove the brace of a code block.
|
||||
// TODO: Preserve formatting.
|
||||
return null;
|
||||
@ -923,11 +927,14 @@ abstract class PrettyPrinterAbstract
|
||||
foreach ($delayedAdd as $delayedAddNode) {
|
||||
if (!$first) {
|
||||
$result .= $insertStr;
|
||||
if ($insertNewline) {
|
||||
$result .= $this->nl;
|
||||
}
|
||||
}
|
||||
$result .= $this->p($delayedAddNode, true);
|
||||
$first = false;
|
||||
}
|
||||
$result .= $extraRight;
|
||||
$result .= $extraRight === "\n" ? $this->nl : $extraRight;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -972,6 +979,19 @@ abstract class PrettyPrinterAbstract
|
||||
return '(' . $this->p($subNode) . ')';
|
||||
}
|
||||
break;
|
||||
case self::FIXUP_STATIC_DEREF_LHS:
|
||||
if ($this->staticDereferenceLhsRequiresParens($subNode)
|
||||
&& !$this->origTokens->haveParens($subStartPos, $subEndPos)
|
||||
) {
|
||||
return '(' . $this->p($subNode) . ')';
|
||||
}
|
||||
break;
|
||||
case self::FIXUP_NEW:
|
||||
if ($this->newOperandRequiresParens($subNode)
|
||||
&& !$this->origTokens->haveParens($subStartPos, $subEndPos)) {
|
||||
return '(' . $this->p($subNode) . ')';
|
||||
}
|
||||
break;
|
||||
case self::FIXUP_BRACED_NAME:
|
||||
case self::FIXUP_VAR_BRACED_NAME:
|
||||
if ($subNode instanceof Expr
|
||||
@ -1042,13 +1062,26 @@ abstract class PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the LHS of a dereferencing operation must be wrapped in parenthesis.
|
||||
* Determines whether the LHS of an array/object operation must be wrapped in parentheses.
|
||||
*
|
||||
* @param Node $node LHS of dereferencing operation
|
||||
*
|
||||
* @return bool Whether parentheses are required
|
||||
*/
|
||||
protected function dereferenceLhsRequiresParens(Node $node) : bool {
|
||||
// A constant can occur on the LHS of an array/object deref, but not a static deref.
|
||||
return $this->staticDereferenceLhsRequiresParens($node)
|
||||
&& !$node instanceof Expr\ConstFetch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the LHS of a static operation must be wrapped in parentheses.
|
||||
*
|
||||
* @param Node $node LHS of dereferencing operation
|
||||
*
|
||||
* @return bool Whether parentheses are required
|
||||
*/
|
||||
protected function staticDereferenceLhsRequiresParens(Node $node): bool {
|
||||
return !($node instanceof Expr\Variable
|
||||
|| $node instanceof Node\Name
|
||||
|| $node instanceof Expr\ArrayDimFetch
|
||||
@ -1061,10 +1094,31 @@ abstract class PrettyPrinterAbstract
|
||||
|| $node instanceof Expr\StaticCall
|
||||
|| $node instanceof Expr\Array_
|
||||
|| $node instanceof Scalar\String_
|
||||
|| $node instanceof Expr\ConstFetch
|
||||
|| $node instanceof Expr\ClassConstFetch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an expression used in "new" or "instanceof" requires parentheses.
|
||||
*
|
||||
* @param Node $node New or instanceof operand
|
||||
*
|
||||
* @return bool Whether parentheses are required
|
||||
*/
|
||||
protected function newOperandRequiresParens(Node $node): bool {
|
||||
if ($node instanceof Node\Name || $node instanceof Expr\Variable) {
|
||||
return false;
|
||||
}
|
||||
if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch ||
|
||||
$node instanceof Expr\NullsafePropertyFetch
|
||||
) {
|
||||
return $this->newOperandRequiresParens($node->var);
|
||||
}
|
||||
if ($node instanceof Expr\StaticPropertyFetch) {
|
||||
return $this->newOperandRequiresParens($node->class);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print modifiers, including trailing whitespace.
|
||||
*
|
||||
@ -1166,7 +1220,7 @@ abstract class PrettyPrinterAbstract
|
||||
Expr\PostDec::class => ['var' => self::FIXUP_PREC_LEFT],
|
||||
Expr\Instanceof_::class => [
|
||||
'expr' => self::FIXUP_PREC_LEFT,
|
||||
'class' => self::FIXUP_PREC_RIGHT, // TODO: FIXUP_NEW_VARIABLE
|
||||
'class' => self::FIXUP_NEW,
|
||||
],
|
||||
Expr\Ternary::class => [
|
||||
'cond' => self::FIXUP_PREC_LEFT,
|
||||
@ -1174,10 +1228,13 @@ abstract class PrettyPrinterAbstract
|
||||
],
|
||||
|
||||
Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS],
|
||||
Expr\StaticCall::class => ['class' => self::FIXUP_DEREF_LHS],
|
||||
Expr\StaticCall::class => ['class' => self::FIXUP_STATIC_DEREF_LHS],
|
||||
Expr\ArrayDimFetch::class => ['var' => self::FIXUP_DEREF_LHS],
|
||||
Expr\ClassConstFetch::class => ['var' => self::FIXUP_DEREF_LHS],
|
||||
Expr\New_::class => ['class' => self::FIXUP_DEREF_LHS], // TODO: FIXUP_NEW_VARIABLE
|
||||
Expr\ClassConstFetch::class => [
|
||||
'class' => self::FIXUP_STATIC_DEREF_LHS,
|
||||
'name' => self::FIXUP_BRACED_NAME,
|
||||
],
|
||||
Expr\New_::class => ['class' => self::FIXUP_NEW],
|
||||
Expr\MethodCall::class => [
|
||||
'var' => self::FIXUP_DEREF_LHS,
|
||||
'name' => self::FIXUP_BRACED_NAME,
|
||||
@ -1187,7 +1244,7 @@ abstract class PrettyPrinterAbstract
|
||||
'name' => self::FIXUP_BRACED_NAME,
|
||||
],
|
||||
Expr\StaticPropertyFetch::class => [
|
||||
'class' => self::FIXUP_DEREF_LHS,
|
||||
'class' => self::FIXUP_STATIC_DEREF_LHS,
|
||||
'name' => self::FIXUP_VAR_BRACED_NAME,
|
||||
],
|
||||
Expr\PropertyFetch::class => [
|
||||
@ -1273,6 +1330,7 @@ abstract class PrettyPrinterAbstract
|
||||
'Param->default' => $stripEquals,
|
||||
'Stmt_Break->num' => $stripBoth,
|
||||
'Stmt_Catch->var' => $stripLeft,
|
||||
'Stmt_ClassConst->type' => $stripRight,
|
||||
'Stmt_ClassMethod->returnType' => $stripColon,
|
||||
'Stmt_Class->extends' => ['left' => \T_EXTENDS],
|
||||
'Stmt_Enum->scalarType' => $stripColon,
|
||||
@ -1314,6 +1372,7 @@ abstract class PrettyPrinterAbstract
|
||||
'Stmt_Break->num' => [\T_BREAK, false, ' ', null],
|
||||
'Stmt_Catch->var' => [null, false, ' ', null],
|
||||
'Stmt_ClassMethod->returnType' => [')', false, ' : ', null],
|
||||
'Stmt_ClassConst->type' => [\T_CONST, false, ' ', null],
|
||||
'Stmt_Class->extends' => [null, false, ' extends ', null],
|
||||
'Stmt_Enum->scalarType' => [null, false, ' : ', null],
|
||||
'Stmt_EnumCase->expr' => [null, false, ' = ', null],
|
||||
@ -1454,6 +1513,16 @@ abstract class PrettyPrinterAbstract
|
||||
'Stmt_ClassMethod->params' => ['(', '', ''],
|
||||
'Stmt_Interface->extends' => [null, ' extends ', ''],
|
||||
'Stmt_Function->params' => ['(', '', ''],
|
||||
'Stmt_Interface->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Class->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_ClassConst->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_ClassMethod->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Function->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Property->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Trait->attrGroups' => [null, '', "\n"],
|
||||
'Expr_ArrowFunction->attrGroups' => [null, '', ' '],
|
||||
'Expr_Closure->attrGroups' => [null, '', ' '],
|
||||
'Expr_PrintableNewAnonClass->attrGroups' => [\T_NEW, ' ', ''],
|
||||
|
||||
/* These cannot be empty to start with:
|
||||
* Expr_Isset->vars
|
||||
@ -1493,6 +1562,7 @@ abstract class PrettyPrinterAbstract
|
||||
'Stmt_ClassMethod->flags' => \T_FUNCTION,
|
||||
'Stmt_Class->flags' => \T_CLASS,
|
||||
'Stmt_Property->flags' => \T_VARIABLE,
|
||||
'Expr_PrintableNewAnonClass->flags' => \T_CLASS,
|
||||
'Param->flags' => \T_VARIABLE,
|
||||
//'Stmt_TraitUseAdaptation_Alias->newModifier' => 0, // TODO
|
||||
];
|
||||
|
@ -142,6 +142,18 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testType() {
|
||||
$node = $this->createClassConstBuilder('TYPE', 1)
|
||||
->setType('int')
|
||||
->getNode();
|
||||
$this->assertEquals(
|
||||
new Stmt\ClassConst(
|
||||
[new Const_('TYPE', new LNumber(1))],
|
||||
0, [], [], new Identifier('int')),
|
||||
$node
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestDefaultValues
|
||||
*/
|
||||
|
@ -27,6 +27,7 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase
|
||||
new Stmt\EnumCase(
|
||||
"TEST",
|
||||
null,
|
||||
[],
|
||||
[
|
||||
'comments' => [new Comment\Doc('/** Test */')]
|
||||
]
|
||||
@ -50,7 +51,6 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase
|
||||
new Stmt\EnumCase(
|
||||
"ATTR_GROUP",
|
||||
null,
|
||||
[],
|
||||
[$attributeGroup]
|
||||
),
|
||||
$node
|
||||
|
@ -205,6 +205,54 @@ class ParamTest extends \PHPUnit\Framework\TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testMakePublic() {
|
||||
$node = $this->createParamBuilder('test')
|
||||
->makePublic()
|
||||
->getNode()
|
||||
;
|
||||
|
||||
$this->assertEquals(
|
||||
new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Node\Stmt\Class_::MODIFIER_PUBLIC),
|
||||
$node
|
||||
);
|
||||
}
|
||||
|
||||
public function testMakeProtected() {
|
||||
$node = $this->createParamBuilder('test')
|
||||
->makeProtected()
|
||||
->getNode()
|
||||
;
|
||||
|
||||
$this->assertEquals(
|
||||
new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Node\Stmt\Class_::MODIFIER_PROTECTED),
|
||||
$node
|
||||
);
|
||||
}
|
||||
|
||||
public function testMakePrivate() {
|
||||
$node = $this->createParamBuilder('test')
|
||||
->makePrivate()
|
||||
->getNode()
|
||||
;
|
||||
|
||||
$this->assertEquals(
|
||||
new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Node\Stmt\Class_::MODIFIER_PRIVATE),
|
||||
$node
|
||||
);
|
||||
}
|
||||
|
||||
public function testMakeReadonly() {
|
||||
$node = $this->createParamBuilder('test')
|
||||
->makeReadonly()
|
||||
->getNode()
|
||||
;
|
||||
|
||||
$this->assertEquals(
|
||||
new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Node\Stmt\Class_::MODIFIER_READONLY),
|
||||
$node
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddAttribute() {
|
||||
$attribute = new Attribute(
|
||||
new Name('Attr'),
|
||||
|
@ -210,6 +210,10 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
new Expr\ClassConstFetch(new Expr\Variable('foo'), new Identifier('BAR')),
|
||||
$factory->classConstFetch(new Expr\Variable('foo'), 'BAR')
|
||||
);
|
||||
$this->assertEquals(
|
||||
new Expr\ClassConstFetch(new Name('Foo'), new Expr\Variable('foo')),
|
||||
$factory->classConstFetch('Foo', $factory->var('foo'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testVar() {
|
||||
@ -243,7 +247,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
public function testInvalidIdentifier() {
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage('Expected string or instance of Node\Identifier');
|
||||
(new BuilderFactory())->classConstFetch('Foo', new Expr\Variable('foo'));
|
||||
(new BuilderFactory())->classConstFetch('Foo', new Name('foo'));
|
||||
}
|
||||
|
||||
public function testInvalidIdentifierOrExpr() {
|
||||
|
@ -125,8 +125,11 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(new Node\Identifier('iterable'), BuilderHelpers::normalizeType('iterable'));
|
||||
$this->assertEquals(new Node\Identifier('void'), BuilderHelpers::normalizeType('void'));
|
||||
$this->assertEquals(new Node\Identifier('object'), BuilderHelpers::normalizeType('object'));
|
||||
$this->assertEquals(new Node\Identifier('null'), BuilderHelpers::normalizeType('null'));
|
||||
$this->assertEquals(new Node\Identifier('false'), BuilderHelpers::normalizeType('false'));
|
||||
$this->assertEquals(new Node\Identifier('mixed'), BuilderHelpers::normalizeType('mixed'));
|
||||
$this->assertEquals(new Node\Identifier('never'), BuilderHelpers::normalizeType('never'));
|
||||
$this->assertEquals(new Node\Identifier('true'), BuilderHelpers::normalizeType('true'));
|
||||
|
||||
$intIdentifier = new Node\Identifier('int');
|
||||
$this->assertSame($intIdentifier, BuilderHelpers::normalizeType($intIdentifier));
|
||||
|
@ -241,8 +241,8 @@ class EmulativeTest extends LexerTest
|
||||
['1_000', [
|
||||
[Tokens::T_LNUMBER, '1_000'],
|
||||
]],
|
||||
['0xCAFE_F00D', [
|
||||
[Tokens::T_LNUMBER, '0xCAFE_F00D'],
|
||||
['0x7AFE_F00D', [
|
||||
[Tokens::T_LNUMBER, '0x7AFE_F00D'],
|
||||
]],
|
||||
['0b0101_1111', [
|
||||
[Tokens::T_LNUMBER, '0b0101_1111'],
|
||||
@ -360,12 +360,12 @@ class EmulativeTest extends LexerTest
|
||||
]],
|
||||
['function readonly(', [
|
||||
[Tokens::T_FUNCTION, 'function'],
|
||||
[Tokens::T_STRING, 'readonly'],
|
||||
[Tokens::T_READONLY, 'readonly'],
|
||||
[ord('('), '('],
|
||||
]],
|
||||
['function readonly (', [
|
||||
[Tokens::T_FUNCTION, 'function'],
|
||||
[Tokens::T_STRING, 'readonly'],
|
||||
[Tokens::T_READONLY, 'readonly'],
|
||||
[ord('('), '('],
|
||||
]],
|
||||
];
|
||||
|
@ -19,10 +19,12 @@ class NameTest extends \PHPUnit\Framework\TestCase
|
||||
$name = new Name('foo');
|
||||
$this->assertSame('foo', $name->getFirst());
|
||||
$this->assertSame('foo', $name->getLast());
|
||||
$this->assertSame(['foo'], $name->getParts());
|
||||
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertSame('foo', $name->getFirst());
|
||||
$this->assertSame('bar', $name->getLast());
|
||||
$this->assertSame(['foo', 'bar'], $name->getParts());
|
||||
}
|
||||
|
||||
public function testToString() {
|
||||
@ -73,6 +75,12 @@ class NameTest extends \PHPUnit\Framework\TestCase
|
||||
(new Name('foo\bar\baz'))->slice(0, -4);
|
||||
}
|
||||
|
||||
public function testSliceLengthTooLargeWithOffset() {
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->expectExceptionMessage('Length 3 is out of bounds');
|
||||
(new Name('foo\bar\baz'))->slice(1, 3);
|
||||
}
|
||||
|
||||
public function testConcat() {
|
||||
$this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz'));
|
||||
$this->assertEquals(
|
||||
|
@ -102,12 +102,16 @@ function() {};
|
||||
fn()
|
||||
=> 42;
|
||||
-----
|
||||
// TODO: Currently we lose formatting for this case.
|
||||
$attrGroup = new Node\AttributeGroup([
|
||||
new Node\Attribute(new Node\Name('A'), []),
|
||||
]);
|
||||
$attrGroup2 = new Node\AttributeGroup([
|
||||
new Node\Attribute(new Node\Name('B'), []),
|
||||
]);
|
||||
$stmts[0]->attrGroups[] = $attrGroup;
|
||||
$stmts[0]->attrGroups[] = $attrGroup2;
|
||||
$stmts[0]->stmts[0]->attrGroups[] = $attrGroup;
|
||||
$stmts[0]->stmts[0]->attrGroups[] = $attrGroup2;
|
||||
$stmts[0]->stmts[1]->attrGroups[] = $attrGroup;
|
||||
$stmts[0]->stmts[2]->attrGroups[] = $attrGroup;
|
||||
$stmts[1]->attrGroups[] = $attrGroup;
|
||||
@ -119,39 +123,34 @@ $stmts[6]->expr->attrGroups[] = $attrGroup;
|
||||
-----
|
||||
<?php
|
||||
#[A]
|
||||
class X
|
||||
{
|
||||
#[B]
|
||||
class X {
|
||||
#[A]
|
||||
public function m()
|
||||
{
|
||||
}
|
||||
#[B]
|
||||
public function m() {}
|
||||
|
||||
#[A]
|
||||
public $prop;
|
||||
public
|
||||
$prop;
|
||||
|
||||
#[A]
|
||||
const X = 42;
|
||||
const
|
||||
X = 42;
|
||||
}
|
||||
|
||||
#[A]
|
||||
trait X
|
||||
{
|
||||
}
|
||||
trait X {}
|
||||
|
||||
#[A]
|
||||
interface X
|
||||
{
|
||||
}
|
||||
interface X {}
|
||||
|
||||
#[A]
|
||||
function f()
|
||||
{
|
||||
}
|
||||
function f() {}
|
||||
|
||||
new #[A] class
|
||||
{
|
||||
};
|
||||
#[A] function () {
|
||||
};
|
||||
#[A] fn() => 42;
|
||||
new #[A] class {};
|
||||
#[A] function() {};
|
||||
#[A] fn()
|
||||
=> 42;
|
||||
-----
|
||||
<?php
|
||||
|
||||
@ -176,4 +175,4 @@ class X {};
|
||||
B,
|
||||
C,
|
||||
]
|
||||
class X {};
|
||||
class X {};
|
||||
|
@ -49,4 +49,4 @@ class Test {
|
||||
public function test() {
|
||||
// some code
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,4 +107,4 @@ Foo
|
||||
|
||||
new class
|
||||
($a, $b)
|
||||
extends Foo {};
|
||||
extends Foo {};
|
||||
|
@ -42,6 +42,12 @@ $foo -> bar;
|
||||
$foo -> bar;
|
||||
self :: $foo;
|
||||
self :: $foo;
|
||||
new Foo();
|
||||
$x instanceof Foo;
|
||||
Foo :: bar;
|
||||
Foo :: $bar;
|
||||
Foo :: bar();
|
||||
Foo :: bar;
|
||||
-----
|
||||
$stmts[0]->expr->name = new Expr\Variable('a');
|
||||
$stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
@ -54,6 +60,12 @@ $stmts[5]->expr->name = new Expr\Variable('bar');
|
||||
$stmts[6]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[7]->expr->name = new Node\VarLikeIdentifier('bar');
|
||||
$stmts[8]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
|
||||
$stmts[9]->expr->class = new Scalar\String_('Foo');
|
||||
$stmts[10]->expr->class = new Scalar\String_('Foo');
|
||||
$stmts[11]->expr->class = new Expr\ConstFetch(new Node\Name('FOO'));
|
||||
$stmts[12]->expr->class = new Expr\ConstFetch(new Node\Name('FOO'));
|
||||
$stmts[13]->expr->class = new Expr\ConstFetch(new Node\Name('FOO'));
|
||||
$stmts[14]->expr->name = new Expr\Variable('bar');
|
||||
-----
|
||||
<?php
|
||||
$a ();
|
||||
@ -64,4 +76,10 @@ $foo -> foo;
|
||||
$foo -> {$bar};
|
||||
$foo -> {$a . $b};
|
||||
self :: $bar;
|
||||
self :: ${$a . $b};
|
||||
self :: ${$a . $b};
|
||||
new ('Foo')();
|
||||
$x instanceof ('Foo');
|
||||
(FOO) :: bar;
|
||||
(FOO) :: $bar;
|
||||
(FOO) :: bar();
|
||||
Foo :: {$bar};
|
||||
|
@ -42,13 +42,71 @@ function test() {
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
// TODO Fix broken result
|
||||
// TODO Preserve formatting
|
||||
$stmts[0]->stmts[1] = $stmts[0]->stmts[2];
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
foo();
|
||||
baz();
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foo();<?php
|
||||
foo();
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
// TODO Preserve formatting
|
||||
unset($stmts[0]->stmts[2]);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
foo();
|
||||
?>Bar<?php
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foo();
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
}
|
||||
-----
|
||||
// TODO Preserve formatting
|
||||
array_splice($stmts[0]->stmts, 0, 1, []);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foo();
|
||||
?>Bar<?php
|
||||
baz();
|
||||
}
|
||||
-----
|
||||
// TODO Preserve formatting
|
||||
array_splice($stmts[0]->stmts, 1, 1, []);
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test()
|
||||
{
|
||||
foo();
|
||||
baz();
|
||||
}
|
||||
|
@ -49,6 +49,10 @@ X
|
||||
private
|
||||
$x
|
||||
;
|
||||
|
||||
const
|
||||
X
|
||||
= 1;
|
||||
}
|
||||
|
||||
foreach (
|
||||
@ -86,6 +90,7 @@ $stmts[9]->expr = new Expr\Variable('x');
|
||||
$stmts[10]->extends = new Node\Name\FullyQualified('Bar');
|
||||
$stmts[10]->stmts[0]->returnType = new Node\Name('Y');
|
||||
$stmts[10]->stmts[1]->props[0]->default = new Scalar\DNumber(42.0);
|
||||
$stmts[10]->stmts[2]->type = new Node\Identifier('int');
|
||||
$stmts[11]->keyVar = new Expr\Variable('z');
|
||||
$stmts[12]->vars[0]->default = new Scalar\String_('abc');
|
||||
$stmts[13]->finally = new Stmt\Finally_([]);
|
||||
@ -140,6 +145,10 @@ X extends \Bar
|
||||
private
|
||||
$x = 42.0
|
||||
;
|
||||
|
||||
const int
|
||||
X
|
||||
= 1;
|
||||
}
|
||||
|
||||
foreach (
|
||||
|
@ -54,4 +54,15 @@ function test(
|
||||
= 'z',
|
||||
public T3 $z
|
||||
= 'x',
|
||||
) {}
|
||||
) {}
|
||||
-----
|
||||
<?php
|
||||
new class {};
|
||||
new readonly class {};
|
||||
-----
|
||||
$stmts[0]->expr->class->flags = Stmt\Class_::MODIFIER_READONLY;
|
||||
$stmts[1]->expr->class->flags = 0;
|
||||
-----
|
||||
<?php
|
||||
readonly class {};
|
||||
class {};
|
||||
|
@ -35,6 +35,11 @@ Bar
|
||||
y
|
||||
;
|
||||
}
|
||||
|
||||
const
|
||||
int
|
||||
X
|
||||
= 1;
|
||||
}
|
||||
|
||||
$foo [ $bar ];
|
||||
@ -97,6 +102,7 @@ $stmts[2]->extends = null;
|
||||
$stmts[2]->stmts[0]->returnType = null;
|
||||
$stmts[2]->stmts[1]->props[0]->default = null;
|
||||
$stmts[2]->stmts[2]->adaptations[0]->newName = null;
|
||||
$stmts[2]->stmts[3]->type = null;
|
||||
$stmts[3]->expr->dim = null;
|
||||
$stmts[4]->expr->expr = null;
|
||||
$stmts[5]->expr->if = null;
|
||||
@ -141,6 +147,10 @@ Foo
|
||||
public
|
||||
;
|
||||
}
|
||||
|
||||
const
|
||||
X
|
||||
= 1;
|
||||
}
|
||||
|
||||
$foo [];
|
||||
|
@ -745,6 +745,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -1508,6 +1509,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
|
43
test/code/parser/expr/dynamicClassConst.test
Normal file
43
test/code/parser/expr/dynamicClassConst.test
Normal file
@ -0,0 +1,43 @@
|
||||
Dynamic class constant fetch
|
||||
-----
|
||||
<?php
|
||||
Foo::{bar()};
|
||||
$foo::{bar()};
|
||||
-----
|
||||
!!php7
|
||||
array(
|
||||
0: Stmt_Expression(
|
||||
expr: Expr_ClassConstFetch(
|
||||
class: Name(
|
||||
parts: array(
|
||||
0: Foo
|
||||
)
|
||||
)
|
||||
name: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: bar
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_Expression(
|
||||
expr: Expr_ClassConstFetch(
|
||||
class: Expr_Variable(
|
||||
name: foo
|
||||
)
|
||||
name: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: bar
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
@ -17,6 +17,7 @@ Different float syntaxes
|
||||
// (all are actually the same number, just in different representations)
|
||||
18446744073709551615;
|
||||
0xFFFFFFFFFFFFFFFF;
|
||||
0xEEEEEEEEEEEEEEEE;
|
||||
01777777777777777777777;
|
||||
0177777777777777777777787;
|
||||
0b1111111111111111111111111111111111111111111111111111111111111111;
|
||||
@ -92,7 +93,7 @@ array(
|
||||
)
|
||||
12: Stmt_Expression(
|
||||
expr: Scalar_DNumber(
|
||||
value: 1.844674407371E+19
|
||||
value: 1.7216961135462E+19
|
||||
)
|
||||
)
|
||||
13: Stmt_Expression(
|
||||
@ -105,4 +106,9 @@ array(
|
||||
value: 1.844674407371E+19
|
||||
)
|
||||
)
|
||||
)
|
||||
15: Stmt_Expression(
|
||||
expr: Scalar_DNumber(
|
||||
value: 1.844674407371E+19
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -4,7 +4,7 @@ Different integer syntaxes
|
||||
|
||||
6.674_083e-11;
|
||||
299_792_458;
|
||||
0xCAFE_F00D;
|
||||
0x7AFE_F00D;
|
||||
0b0101_1111;
|
||||
0137_041;
|
||||
|
||||
@ -42,7 +42,7 @@ array(
|
||||
)
|
||||
2: Stmt_Expression(
|
||||
expr: Scalar_LNumber(
|
||||
value: 3405705229
|
||||
value: 2063527949
|
||||
)
|
||||
)
|
||||
3: Stmt_Expression(
|
||||
@ -196,4 +196,4 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -152,6 +152,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -175,6 +176,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
|
@ -205,6 +205,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
|
@ -23,6 +23,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_STATIC (8)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -61,6 +62,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_ABSTRACT (16)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -99,6 +101,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_READONLY (64)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -137,6 +140,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PUBLIC (1)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -150,4 +154,4 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -27,6 +27,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -42,6 +43,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PUBLIC (1)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -57,6 +59,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PROTECTED (2)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -72,6 +75,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PRIVATE (4)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -87,6 +91,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_FINAL (32)
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
@ -100,4 +105,4 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -280,7 +280,7 @@ array(
|
||||
// Type in the partial parse could conceivably be any of 0, 16 or 32
|
||||
-----
|
||||
!!php5
|
||||
Syntax error, unexpected T_READONLY from 1:7 to 1:14
|
||||
Syntax error, unexpected T_CLASS, expecting '(' from 1:16 to 1:20
|
||||
array(
|
||||
0: Stmt_Class(
|
||||
attrGroups: array(
|
||||
@ -366,4 +366,4 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -28,7 +28,7 @@ readonly class A {
|
||||
}
|
||||
-----
|
||||
!!php5
|
||||
Syntax error, unexpected T_READONLY from 3:1 to 3:8
|
||||
Syntax error, unexpected T_CLASS, expecting '(' from 3:10 to 3:14
|
||||
array(
|
||||
0: Stmt_Class(
|
||||
attrGroups: array(
|
||||
@ -65,4 +65,4 @@ array(
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
26
test/code/parser/stmt/class/readonlyAnonyous.test
Normal file
26
test/code/parser/stmt/class/readonlyAnonyous.test
Normal file
@ -0,0 +1,26 @@
|
||||
Readonly anonymous class
|
||||
-----
|
||||
<?php
|
||||
|
||||
new readonly class {};
|
||||
-----
|
||||
!!php7
|
||||
array(
|
||||
0: Stmt_Expression(
|
||||
expr: Expr_New(
|
||||
class: Stmt_Class(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_READONLY (64)
|
||||
name: null
|
||||
extends: null
|
||||
implements: array(
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
@ -46,6 +46,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
|
125
test/code/parser/stmt/class/typedConstants.test
Normal file
125
test/code/parser/stmt/class/typedConstants.test
Normal file
@ -0,0 +1,125 @@
|
||||
Typed constants
|
||||
-----
|
||||
<?php
|
||||
class Test {
|
||||
const int X = 1;
|
||||
private const string Y = "a", Z = "b";
|
||||
const array ARRAY = [];
|
||||
const Foo|Bar|null FOO = null;
|
||||
}
|
||||
-----
|
||||
!!php7
|
||||
array(
|
||||
0: Stmt_Class(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
name: Identifier(
|
||||
name: Test
|
||||
)
|
||||
extends: null
|
||||
implements: array(
|
||||
)
|
||||
stmts: array(
|
||||
0: Stmt_ClassConst(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: Identifier(
|
||||
name: int
|
||||
)
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
name: X
|
||||
)
|
||||
value: Scalar_LNumber(
|
||||
value: 1
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_ClassConst(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PRIVATE (4)
|
||||
type: Identifier(
|
||||
name: string
|
||||
)
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
name: Y
|
||||
)
|
||||
value: Scalar_String(
|
||||
value: a
|
||||
)
|
||||
)
|
||||
1: Const(
|
||||
name: Identifier(
|
||||
name: Z
|
||||
)
|
||||
value: Scalar_String(
|
||||
value: b
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
2: Stmt_ClassConst(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: Identifier(
|
||||
name: array
|
||||
)
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
name: ARRAY
|
||||
)
|
||||
value: Expr_Array(
|
||||
items: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
3: Stmt_ClassConst(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: UnionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: Foo
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: Bar
|
||||
)
|
||||
)
|
||||
2: Identifier(
|
||||
name: null
|
||||
)
|
||||
)
|
||||
)
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
name: FOO
|
||||
)
|
||||
value: Expr_ConstFetch(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: null
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
195
test/code/parser/stmt/function/disjointNormalFormTypes.test
Normal file
195
test/code/parser/stmt/function/disjointNormalFormTypes.test
Normal file
@ -0,0 +1,195 @@
|
||||
DNF types
|
||||
-----
|
||||
<?php
|
||||
|
||||
class Test {
|
||||
public (A&B)|(X&Y) $prop;
|
||||
public readonly (A&B)|C $prop2;
|
||||
}
|
||||
|
||||
function test((A&B)|(X&Y) $a): (A&B)|(X&Y) {}
|
||||
-----
|
||||
!!php7
|
||||
array(
|
||||
0: Stmt_Class(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
name: Identifier(
|
||||
name: Test
|
||||
)
|
||||
extends: null
|
||||
implements: array(
|
||||
)
|
||||
stmts: array(
|
||||
0: Stmt_Property(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PUBLIC (1)
|
||||
type: UnionType(
|
||||
types: array(
|
||||
0: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: A
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: B
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: X
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: Y
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
props: array(
|
||||
0: Stmt_PropertyProperty(
|
||||
name: VarLikeIdentifier(
|
||||
name: prop
|
||||
)
|
||||
default: null
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_Property(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: MODIFIER_PUBLIC | MODIFIER_READONLY (65)
|
||||
type: UnionType(
|
||||
types: array(
|
||||
0: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: A
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: B
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: C
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
props: array(
|
||||
0: Stmt_PropertyProperty(
|
||||
name: VarLikeIdentifier(
|
||||
name: prop2
|
||||
)
|
||||
default: null
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_Function(
|
||||
attrGroups: array(
|
||||
)
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: test
|
||||
)
|
||||
params: array(
|
||||
0: Param(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: UnionType(
|
||||
types: array(
|
||||
0: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: A
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: B
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: X
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: Y
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
var: Expr_Variable(
|
||||
name: a
|
||||
)
|
||||
default: null
|
||||
)
|
||||
)
|
||||
returnType: UnionType(
|
||||
types: array(
|
||||
0: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: A
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: B
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
1: IntersectionType(
|
||||
types: array(
|
||||
0: Name(
|
||||
parts: array(
|
||||
0: X
|
||||
)
|
||||
)
|
||||
1: Name(
|
||||
parts: array(
|
||||
0: Y
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
56
test/code/parser/stmt/function/nullFalseTrueTypes.test
Normal file
56
test/code/parser/stmt/function/nullFalseTrueTypes.test
Normal file
@ -0,0 +1,56 @@
|
||||
standalone null, false and true types
|
||||
-----
|
||||
<?php
|
||||
|
||||
function test(): null {}
|
||||
function test(): false {}
|
||||
function test(): true {}
|
||||
-----
|
||||
!!php7
|
||||
array(
|
||||
0: Stmt_Function(
|
||||
attrGroups: array(
|
||||
)
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: test
|
||||
)
|
||||
params: array(
|
||||
)
|
||||
returnType: Identifier(
|
||||
name: null
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
1: Stmt_Function(
|
||||
attrGroups: array(
|
||||
)
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: test
|
||||
)
|
||||
params: array(
|
||||
)
|
||||
returnType: Identifier(
|
||||
name: false
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
2: Stmt_Function(
|
||||
attrGroups: array(
|
||||
)
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: test
|
||||
)
|
||||
params: array(
|
||||
)
|
||||
returnType: Identifier(
|
||||
name: true
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
32
test/code/parser/stmt/function/readonlyFunction.test
Normal file
32
test/code/parser/stmt/function/readonlyFunction.test
Normal file
@ -0,0 +1,32 @@
|
||||
readonly function
|
||||
-----
|
||||
<?php
|
||||
function readonly() {}
|
||||
readonly();
|
||||
-----
|
||||
array(
|
||||
0: Stmt_Function(
|
||||
attrGroups: array(
|
||||
)
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: readonly
|
||||
)
|
||||
params: array(
|
||||
)
|
||||
returnType: null
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
1: Stmt_Expression(
|
||||
expr: Expr_FuncCall(
|
||||
name: Name(
|
||||
parts: array(
|
||||
0: readonly
|
||||
)
|
||||
)
|
||||
args: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
@ -127,6 +127,7 @@ array(
|
||||
attrGroups: array(
|
||||
)
|
||||
flags: 0
|
||||
type: null
|
||||
consts: array(
|
||||
0: Const(
|
||||
name: Identifier(
|
||||
|
@ -64,4 +64,28 @@ function test()
|
||||
function test()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
function noDuplicateComment()
|
||||
{
|
||||
if (true):
|
||||
// TEST 1
|
||||
elseif (true):
|
||||
// TEST 2
|
||||
else:
|
||||
// TEST 3
|
||||
endif;
|
||||
}
|
||||
-----
|
||||
function noDuplicateComment()
|
||||
{
|
||||
if (true) {
|
||||
// TEST 1
|
||||
} elseif (true) {
|
||||
// TEST 2
|
||||
} else {
|
||||
// TEST 3
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ new class($a) extends A {
|
||||
$this->a = $a;
|
||||
}
|
||||
};
|
||||
new readonly class {};
|
||||
-----
|
||||
!!php7
|
||||
new class
|
||||
{
|
||||
};
|
||||
@ -25,3 +27,6 @@ new class($a) extends A
|
||||
$this->a = $a;
|
||||
}
|
||||
};
|
||||
new readonly class
|
||||
{
|
||||
};
|
||||
|
9
test/code/prettyPrinter/expr/dynamicClassConstFetch.test
Normal file
9
test/code/prettyPrinter/expr/dynamicClassConstFetch.test
Normal file
@ -0,0 +1,9 @@
|
||||
Dynamic class constant fetch
|
||||
-----
|
||||
<?php
|
||||
Foo::{bar()};
|
||||
$foo::{bar()};
|
||||
-----
|
||||
!!php7
|
||||
Foo::{bar()};
|
||||
$foo::{bar()};
|
@ -2,10 +2,22 @@ Parentheses for complex new/instanceof expressions
|
||||
-----
|
||||
<?php
|
||||
new ('a' . 'b');
|
||||
new (x);
|
||||
new (foo());
|
||||
new ('foo');
|
||||
new (x[0]);
|
||||
new (x->y);
|
||||
new ((x)::$y);
|
||||
$x instanceof ('a' . 'b');
|
||||
$x instanceof ($y++);
|
||||
-----
|
||||
!!php7
|
||||
new ('a' . 'b')();
|
||||
new (x)();
|
||||
new (foo())();
|
||||
new ('foo')();
|
||||
new (x[0])();
|
||||
new (x->y)();
|
||||
new ((x)::$y)();
|
||||
$x instanceof ('a' . 'b');
|
||||
$x instanceof ($y++);
|
||||
$x instanceof ($y++);
|
||||
|
@ -11,6 +11,9 @@ A::$$b[$c]();
|
||||
($a->b)();
|
||||
(A::$b)();
|
||||
('a' . 'b')::X;
|
||||
(A)::X;
|
||||
(A)::$x;
|
||||
(A)::x();
|
||||
-----
|
||||
!!php7
|
||||
(function () {
|
||||
@ -22,4 +25,7 @@ $A::{$b[$c]}();
|
||||
A::${$b}[$c]();
|
||||
($a->b)();
|
||||
(A::$b)();
|
||||
('a' . 'b')::X;
|
||||
('a' . 'b')::X;
|
||||
(A)::X;
|
||||
(A)::$x;
|
||||
(A)::x();
|
||||
|
@ -7,7 +7,7 @@ class Foo
|
||||
const A = 1, B = 2;
|
||||
public const C = 3, D = 4;
|
||||
protected const E = 5, F = 6;
|
||||
private const G = 7, H = 8;
|
||||
private const int G = 7, H = 8;
|
||||
}
|
||||
-----
|
||||
!!php7
|
||||
@ -16,5 +16,5 @@ class Foo
|
||||
const A = 1, B = 2;
|
||||
public const C = 3, D = 4;
|
||||
protected const E = 5, F = 6;
|
||||
private const G = 7, H = 8;
|
||||
}
|
||||
private const int G = 7, H = 8;
|
||||
}
|
||||
|
18
test/code/prettyPrinter/stmt/disjointNormalFormTypes.test
Normal file
18
test/code/prettyPrinter/stmt/disjointNormalFormTypes.test
Normal file
@ -0,0 +1,18 @@
|
||||
Union types
|
||||
-----
|
||||
<?php
|
||||
|
||||
class Test {
|
||||
public (A&B)|(X&Y) $prop;
|
||||
}
|
||||
|
||||
function test((A&B)|(X&Y) $a): (A&B)|(X&Y) {}
|
||||
-----
|
||||
!!php7
|
||||
class Test
|
||||
{
|
||||
public (A&B)|(X&Y) $prop;
|
||||
}
|
||||
function test((A&B)|(X&Y) $a) : (A&B)|(X&Y)
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user