mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-09 16:36:31 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
adf44419c0 | |||
5219f75719 | |||
a485ecd7ba | |||
030de805e1 | |||
aa6aec90e1 | |||
3e158a2313 |
19
CHANGELOG.md
19
CHANGELOG.md
@ -1,8 +1,25 @@
|
||||
Version 3.0.1-dev
|
||||
Version 3.0.3-dev
|
||||
-----------------
|
||||
|
||||
Nothing yet.
|
||||
|
||||
Version 3.0.2 (2016-12-06)
|
||||
--------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed name resolution of nullable types.
|
||||
* Fixed pretty-printing of nullable types.
|
||||
|
||||
Version 3.0.1 (2016-12-01)
|
||||
--------------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed handling of nested `list()`s: If the nested list was unkeyed, it was directly included in
|
||||
the list items. If it was keyed, it was wrapped in `ArrayItem`. Now nested `List_` nodes are
|
||||
always wrapped in `ArrayItem`s.
|
||||
|
||||
Version 3.0.0 (2016-11-30)
|
||||
--------------------------
|
||||
|
||||
|
@ -939,7 +939,7 @@ list_expr_elements:
|
||||
|
||||
list_expr_element:
|
||||
variable { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| list_expr { $$ = $1; }
|
||||
| list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| /* empty */ { $$ = null; }
|
||||
;
|
||||
|
||||
|
@ -823,7 +823,7 @@ list_expr_elements:
|
||||
|
||||
list_expr_element:
|
||||
variable { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| list_expr { $$ = $1; }
|
||||
| list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| expr T_DOUBLE_ARROW variable { $$ = Expr\ArrayItem[$3, $1, false]; }
|
||||
| expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; }
|
||||
| /* empty */ { $$ = null; }
|
||||
|
@ -9,6 +9,8 @@ abstract class FunctionLike extends Declaration
|
||||
{
|
||||
protected $returnByRef = false;
|
||||
protected $params = array();
|
||||
|
||||
/** @var string|Node\Name|Node\NullableType|null */
|
||||
protected $returnType = null;
|
||||
|
||||
/**
|
||||
@ -59,7 +61,7 @@ abstract class FunctionLike extends Declaration
|
||||
/**
|
||||
* Sets the return type for PHP 7.
|
||||
*
|
||||
* @param string|Node\Name $type One of array, callable, string, int, float, bool, iterable,
|
||||
* @param string|Node\Name|Node\NullableType $type One of array, callable, string, int, float, bool, iterable,
|
||||
* or a class/interface name.
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
|
@ -10,6 +10,8 @@ class Method extends FunctionLike
|
||||
{
|
||||
protected $name;
|
||||
protected $flags = 0;
|
||||
|
||||
/** @var array|null */
|
||||
protected $stmts = array();
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,10 @@ class Param extends PhpParser\BuilderAbstract
|
||||
protected $name;
|
||||
|
||||
protected $default = null;
|
||||
|
||||
/** @var string|Node\Name|Node\NullableType|null */
|
||||
protected $type = null;
|
||||
|
||||
protected $byRef = false;
|
||||
|
||||
/**
|
||||
@ -38,7 +41,7 @@ class Param extends PhpParser\BuilderAbstract
|
||||
/**
|
||||
* Sets type hint for the parameter.
|
||||
*
|
||||
* @param string|Node\Name $type Type hint to use
|
||||
* @param string|Node\Name|Node\NullableType $type Type hint to use
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
|
@ -60,9 +60,9 @@ abstract class BuilderAbstract implements Builder {
|
||||
* In particular, builtin types are left as strings, custom types become Names and nullables
|
||||
* are wrapped in NullableType nodes.
|
||||
*
|
||||
* @param Name|string $type The type to normalize
|
||||
* @param Name|string|NullableType $type The type to normalize
|
||||
*
|
||||
* @return Name|string The normalized type
|
||||
* @return Name|string|NullableType The normalized type
|
||||
*/
|
||||
protected function normalizeType($type) {
|
||||
if (!is_string($type)) {
|
||||
|
@ -16,7 +16,7 @@ class Closure extends Expr implements FunctionLike
|
||||
public $params;
|
||||
/** @var ClosureUse[] use()s */
|
||||
public $uses;
|
||||
/** @var null|string|Node\Name Return type */
|
||||
/** @var null|string|Node\Name|Node\NullableType Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
@ -23,7 +23,7 @@ interface FunctionLike extends Node
|
||||
/**
|
||||
* Get the declared return type or null
|
||||
*
|
||||
* @return null|string|Node\Name
|
||||
* @return null|string|Node\Name|Node\NullableType
|
||||
*/
|
||||
public function getReturnType();
|
||||
|
||||
|
@ -6,7 +6,7 @@ use PhpParser\NodeAbstract;
|
||||
|
||||
class Param extends NodeAbstract
|
||||
{
|
||||
/** @var null|string|Name Typehint */
|
||||
/** @var null|string|Name|NullableType Typehint */
|
||||
public $type;
|
||||
/** @var bool Whether parameter is passed by reference */
|
||||
public $byRef;
|
||||
@ -22,7 +22,7 @@ class Param extends NodeAbstract
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param null|Expr $default Default value
|
||||
* @param null|string|Name $type Typehint
|
||||
* @param null|string|Name|NullableType $type Typehint
|
||||
* @param bool $byRef Whether is passed by reference
|
||||
* @param bool $variadic Whether this is a variadic argument
|
||||
* @param array $attributes Additional attributes
|
||||
|
@ -15,7 +15,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
public $name;
|
||||
/** @var Node\Param[] Parameters */
|
||||
public $params;
|
||||
/** @var null|string|Node\Name Return type */
|
||||
/** @var null|string|Node\Name|Node\NullableType Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
@ -13,7 +13,7 @@ class Function_ extends Node\Stmt implements FunctionLike
|
||||
public $name;
|
||||
/** @var Node\Param[] Parameters */
|
||||
public $params;
|
||||
/** @var null|string|Node\Name Return type */
|
||||
/** @var null|string|Node\Name|Node\NullableType Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
@ -112,7 +112,10 @@ class NameResolver extends NodeVisitorAbstract
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($node instanceof Node\NullableType) {
|
||||
if ($node->type instanceof Name) {
|
||||
$node->type = $this->resolveClassName($node->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3035,7 +3035,7 @@ class Php5 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule523() {
|
||||
$this->semValue = $this->semStack[$this->stackPos-(1-1)];
|
||||
$this->semValue = new Expr\ArrayItem($this->semStack[$this->stackPos-(1-1)], null, false, $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes);
|
||||
}
|
||||
|
||||
protected function reduceRule524() {
|
||||
|
@ -2657,7 +2657,7 @@ class Php7 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule460() {
|
||||
$this->semValue = $this->semStack[$this->stackPos-(1-1)];
|
||||
$this->semValue = new Expr\ArrayItem($this->semStack[$this->stackPos-(1-1)], null, false, $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes);
|
||||
}
|
||||
|
||||
protected function reduceRule461() {
|
||||
|
@ -34,7 +34,7 @@ class Standard extends PrettyPrinterAbstract
|
||||
}
|
||||
|
||||
protected function pNullableType(Node\NullableType $node) {
|
||||
return '?' . $node->type;
|
||||
return '?' . $this->pType($node->type);
|
||||
}
|
||||
|
||||
// Names
|
||||
|
@ -199,9 +199,12 @@ interface A extends C, D {
|
||||
public function a(A $a) : A;
|
||||
}
|
||||
|
||||
function fn() : A {}
|
||||
function fn2() : array {}
|
||||
function() : A {};
|
||||
function fn(A $a) : A {}
|
||||
function fn2(array $a) : array {}
|
||||
function(A $a) : A {};
|
||||
|
||||
function fn3(?A $a) : ?A {}
|
||||
function fn4(?array $a) : ?array {}
|
||||
|
||||
A::b();
|
||||
A::$b;
|
||||
@ -233,14 +236,20 @@ interface A extends \NS\C, \NS\D
|
||||
{
|
||||
public function a(\NS\A $a) : \NS\A;
|
||||
}
|
||||
function fn() : \NS\A
|
||||
function fn(\NS\A $a) : \NS\A
|
||||
{
|
||||
}
|
||||
function fn2() : array
|
||||
function fn2(array $a) : array
|
||||
{
|
||||
}
|
||||
function () : \NS\A {
|
||||
function (\NS\A $a) : \NS\A {
|
||||
};
|
||||
function fn3(?\NS\A $a) : ?\NS\A
|
||||
{
|
||||
}
|
||||
function fn4(?array $a) : ?array
|
||||
{
|
||||
}
|
||||
\NS\A::b();
|
||||
\NS\A::$b;
|
||||
\NS\A::B;
|
||||
|
@ -246,7 +246,9 @@ array(
|
||||
)
|
||||
byRef: false
|
||||
)
|
||||
1: Expr_List(
|
||||
1: Expr_ArrayItem(
|
||||
key: null
|
||||
value: Expr_List(
|
||||
items: array(
|
||||
0: null
|
||||
1: Expr_ArrayItem(
|
||||
@ -258,6 +260,8 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
)
|
||||
2: Expr_ArrayItem(
|
||||
key: null
|
||||
value: Expr_Variable(
|
||||
|
@ -1,11 +1,11 @@
|
||||
Nullable types
|
||||
-----
|
||||
<?php
|
||||
function test(?Foo $bar, ?string $foo) : ?Baz
|
||||
function test(?Foo $bar, ?string $foo, ?\Xyz $zyx) : ?Baz
|
||||
{
|
||||
}
|
||||
-----
|
||||
!!php7
|
||||
function test(?Foo $bar, ?string $foo) : ?Baz
|
||||
function test(?Foo $bar, ?string $foo, ?\Xyz $zyx) : ?Baz
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user