Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Break_ extends Node\Stmt
* @param null|Node\Expr $num Number of loops to break
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $num = null, array $attributes = array()) {
public function __construct(Node\Expr $num = null, array $attributes = []) {
parent::__construct($attributes);
$this->num = $num;
}
public function getSubNodeNames() {
return array('num');
public function getSubNodeNames() : array {
return ['num'];
}
public function getType() : string {
return 'Stmt_Break';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -8,23 +8,27 @@ class Case_ extends Node\Stmt
{
/** @var null|Node\Expr $cond Condition (null for default) */
public $cond;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs a case node.
*
* @param null|Node\Expr $cond Condition (null for default)
* @param Node[] $stmts Statements
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct($cond, array $stmts = array(), array $attributes = array()) {
public function __construct($cond, array $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('cond', 'stmts');
public function getSubNodeNames() : array {
return ['cond', 'stmts'];
}
public function getType() : string {
return 'Stmt_Case';
}
}

View File

@@ -1,34 +1,41 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Node\Expr;
class Catch_ extends Node\Stmt
{
/** @var Node\Name Class of exception */
public $type;
/** @var string Variable for exception */
/** @var Node\Name[] Types of exceptions to catch */
public $types;
/** @var Expr\Variable Variable for exception */
public $var;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs a catch node.
*
* @param Node\Name $type Class of exception
* @param string $var Variable for exception
* @param Node[] $stmts Statements
* @param array $attributes Additional attributes
* @param Node\Name[] $types Types of exceptions to catch
* @param Expr\Variable $var Variable for exception
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $type, $var, array $stmts = array(), array $attributes = array()) {
public function __construct(
array $types, Expr\Variable $var, array $stmts = [], array $attributes = []
) {
parent::__construct($attributes);
$this->type = $type;
$this->types = $types;
$this->var = $var;
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('type', 'var', 'stmts');
public function getSubNodeNames() : array {
return ['types', 'var', 'stmts'];
}
public function getType() : string {
return 'Stmt_Catch';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -6,6 +6,8 @@ use PhpParser\Node;
class ClassConst extends Node\Stmt
{
/** @var int Modifiers */
public $flags;
/** @var Node\Const_[] Constant declarations */
public $consts;
@@ -13,14 +15,48 @@ class ClassConst extends Node\Stmt
* Constructs a class const list node.
*
* @param Node\Const_[] $consts Constant declarations
* @param int $flags Modifiers
* @param array $attributes Additional attributes
*/
public function __construct(array $consts, array $attributes = array()) {
public function __construct(array $consts, int $flags = 0, array $attributes = []) {
parent::__construct($attributes);
$this->flags = $flags;
$this->consts = $consts;
}
public function getSubNodeNames() {
return array('consts');
public function getSubNodeNames() : array {
return ['flags', 'consts'];
}
/**
* Whether constant is explicitly or implicitly public.
*
* @return bool
*/
public function isPublic() : bool {
return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
|| ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
}
/**
* Whether constant is protected.
*
* @return bool
*/
public function isProtected() : bool {
return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
}
/**
* Whether constant is private.
*
* @return bool
*/
public function isPrivate() : bool {
return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
}
public function getType() : string {
return 'Stmt_ClassConst';
}
}

View File

@@ -1,13 +1,17 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
abstract class ClassLike extends Node\Stmt {
/** @var string Name */
/**
* @property Node\Name $namespacedName Namespaced name (if using NameResolver)
*/
abstract class ClassLike extends Node\Stmt
{
/** @var Node\Identifier|null Name */
public $name;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
@@ -15,8 +19,8 @@ abstract class ClassLike extends Node\Stmt {
*
* @return ClassMethod[]
*/
public function getMethods() {
$methods = array();
public function getMethods() : array {
$methods = [];
foreach ($this->stmts as $stmt) {
if ($stmt instanceof ClassMethod) {
$methods[] = $stmt;
@@ -32,10 +36,10 @@ abstract class ClassLike extends Node\Stmt {
*
* @return ClassMethod|null Method node or null if the method does not exist
*/
public function getMethod($name) {
public function getMethod(string $name) {
$lowerName = strtolower($name);
foreach ($this->stmts as $stmt) {
if ($stmt instanceof ClassMethod && $lowerName === strtolower($stmt->name)) {
if ($stmt instanceof ClassMethod && $lowerName === $stmt->name->toLowerString()) {
return $stmt;
}
}

View File

@@ -1,68 +1,75 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Node\FunctionLike;
use PhpParser\Error;
class ClassMethod extends Node\Stmt implements FunctionLike
{
/** @var int Type */
public $type;
/** @var int Flags */
public $flags;
/** @var bool Whether to return by reference */
public $byRef;
/** @var string Name */
/** @var Node\Identifier Name */
public $name;
/** @var Node\Param[] Parameters */
public $params;
/** @var null|string|Node\Name Return type */
/** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
public $returnType;
/** @var Node[] Statements */
/** @var Node\Stmt[]|null Statements */
public $stmts;
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,
];
/**
* Constructs a class method node.
*
* @param string $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'type' => MODIFIER_PUBLIC: Type
* 'byRef' => false : Whether to return by reference
* 'params' => array() : Parameters
* 'returnType' => null : Return type
* 'stmts' => array() : Statements
* @param array $attributes Additional attributes
* @param string|Node\Identifier $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'flags => MODIFIER_PUBLIC: Flags
* 'byRef' => false : Whether to return by reference
* 'params' => array() : Parameters
* 'returnType' => null : Return type
* 'stmts' => array() : Statements
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
public function __construct($name, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
$this->name = $name;
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
$this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
if ($this->type & Class_::MODIFIER_STATIC) {
switch (strtolower($this->name)) {
case '__construct':
throw new Error(sprintf('Constructor %s() cannot be static', $this->name));
case '__destruct':
throw new Error(sprintf('Destructor %s() cannot be static', $this->name));
case '__clone':
throw new Error(sprintf('Clone method %s() cannot be static', $this->name));
}
}
$this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
$this->byRef = $subNodes['byRef'] ?? false;
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
$this->params = $subNodes['params'] ?? [];
$returnType = $subNodes['returnType'] ?? null;
$this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
$this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : [];
}
public function getSubNodeNames() {
return array('type', 'byRef', 'name', 'params', 'returnType', 'stmts');
public function getSubNodeNames() : array {
return ['flags', 'byRef', 'name', 'params', 'returnType', 'stmts'];
}
public function returnsByRef() {
public function returnsByRef() : bool {
return $this->byRef;
}
public function getParams() {
public function getParams() : array {
return $this->params;
}
@@ -74,28 +81,71 @@ class ClassMethod extends Node\Stmt implements FunctionLike
return $this->stmts;
}
public function isPublic() {
return ($this->type & Class_::MODIFIER_PUBLIC) !== 0
|| ($this->type & Class_::VISIBILITY_MODIFER_MASK) === 0;
/**
* Whether the method is explicitly or implicitly public.
*
* @return bool
*/
public function isPublic() : bool {
return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
|| ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
}
public function isProtected() {
return (bool) ($this->type & Class_::MODIFIER_PROTECTED);
/**
* Whether the method is protected.
*
* @return bool
*/
public function isProtected() : bool {
return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
}
public function isPrivate() {
return (bool) ($this->type & Class_::MODIFIER_PRIVATE);
/**
* Whether the method is private.
*
* @return bool
*/
public function isPrivate() : bool {
return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
}
public function isAbstract() {
return (bool) ($this->type & Class_::MODIFIER_ABSTRACT);
/**
* Whether the method is abstract.
*
* @return bool
*/
public function isAbstract() : bool {
return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
}
public function isFinal() {
return (bool) ($this->type & Class_::MODIFIER_FINAL);
/**
* Whether the method is final.
*
* @return bool
*/
public function isFinal() : bool {
return (bool) ($this->flags & Class_::MODIFIER_FINAL);
}
public function isStatic() {
return (bool) ($this->type & Class_::MODIFIER_STATIC);
/**
* Whether the method is static.
*
* @return bool
*/
public function isStatic() : bool {
return (bool) ($this->flags & Class_::MODIFIER_STATIC);
}
/**
* Whether the method is magic.
*
* @return bool
*/
public function isMagic() : bool {
return isset(self::$magicNames[$this->name->toLowerString()]);
}
public function getType() : string {
return 'Stmt_ClassMethod';
}
}

View File

@@ -1,9 +1,9 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Error;
use PhpParser\Node;
class Class_ extends ClassLike
{
@@ -14,74 +14,63 @@ class Class_ extends ClassLike
const MODIFIER_ABSTRACT = 16;
const MODIFIER_FINAL = 32;
const VISIBILITY_MODIFER_MASK = 7; // 1 | 2 | 4
const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4
/** @var int Type */
public $type;
public $flags;
/** @var null|Node\Name Name of extended class */
public $extends;
/** @var Node\Name[] Names of implemented interfaces */
public $implements;
protected static $specialNames = array(
'self' => true,
'parent' => true,
'static' => true,
);
/**
* Constructs a class node.
*
* @param string|null $name Name
* @param string|Node\Identifier|null $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'type' => 0 : Type
* 'flags' => 0 : Flags
* 'extends' => null : Name of extended class
* 'implements' => array(): Names of implemented interfaces
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
public function __construct($name, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
$this->name = $name;
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null;
$this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
if (null !== $this->name && isset(self::$specialNames[strtolower($this->name)])) {
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
}
if (isset(self::$specialNames[strtolower($this->extends)])) {
throw new Error(
sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends),
$this->extends->getAttributes()
);
}
foreach ($this->implements as $interface) {
if (isset(self::$specialNames[strtolower($interface)])) {
throw new Error(
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
$interface->getAttributes()
);
}
}
$this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
$this->extends = $subNodes['extends'] ?? null;
$this->implements = $subNodes['implements'] ?? [];
$this->stmts = $subNodes['stmts'] ?? [];
}
public function getSubNodeNames() {
return array('type', 'name', 'extends', 'implements', 'stmts');
public function getSubNodeNames() : array {
return ['flags', 'name', 'extends', 'implements', 'stmts'];
}
public function isAbstract() {
return (bool) ($this->type & self::MODIFIER_ABSTRACT);
/**
* Whether the class is explicitly abstract.
*
* @return bool
*/
public function isAbstract() : bool {
return (bool) ($this->flags & self::MODIFIER_ABSTRACT);
}
public function isFinal() {
return (bool) ($this->type & self::MODIFIER_FINAL);
/**
* Whether the class is final.
*
* @return bool
*/
public function isFinal() : bool {
return (bool) ($this->flags & self::MODIFIER_FINAL);
}
public function isAnonymous() {
/**
* Whether the class is anonymous.
*
* @return bool
*/
public function isAnonymous() : bool {
return null === $this->name;
}
@@ -89,7 +78,7 @@ class Class_ extends ClassLike
* @internal
*/
public static function verifyModifier($a, $b) {
if ($a & self::VISIBILITY_MODIFER_MASK && $b & self::VISIBILITY_MODIFER_MASK) {
if ($a & self::VISIBILITY_MODIFIER_MASK && $b & self::VISIBILITY_MODIFIER_MASK) {
throw new Error('Multiple access type modifiers are not allowed');
}
@@ -109,4 +98,8 @@ class Class_ extends ClassLike
throw new Error('Cannot use the final modifier on an abstract class member');
}
}
public function getType() : string {
return 'Stmt_Class';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Const_ extends Node\Stmt
* @param Node\Const_[] $consts Constant declarations
* @param array $attributes Additional attributes
*/
public function __construct(array $consts, array $attributes = array()) {
public function __construct(array $consts, array $attributes = []) {
parent::__construct($attributes);
$this->consts = $consts;
}
public function getSubNodeNames() {
return array('consts');
public function getSubNodeNames() : array {
return ['consts'];
}
public function getType() : string {
return 'Stmt_Const';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Continue_ extends Node\Stmt
* @param null|Node\Expr $num Number of loops to continue
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $num = null, array $attributes = array()) {
public function __construct(Node\Expr $num = null, array $attributes = []) {
parent::__construct($attributes);
$this->num = $num;
}
public function getSubNodeNames() {
return array('num');
public function getSubNodeNames() : array {
return ['num'];
}
public function getType() : string {
return 'Stmt_Continue';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -6,7 +6,7 @@ use PhpParser\Node;
class DeclareDeclare extends Node\Stmt
{
/** @var string Key */
/** @var Node\Identifier Key */
public $key;
/** @var Node\Expr Value */
public $value;
@@ -14,17 +14,21 @@ class DeclareDeclare extends Node\Stmt
/**
* Constructs a declare key=>value pair node.
*
* @param string $key Key
* @param Node\Expr $value Value
* @param array $attributes Additional attributes
* @param string|Node\Identifier $key Key
* @param Node\Expr $value Value
* @param array $attributes Additional attributes
*/
public function __construct($key, Node\Expr $value, array $attributes = array()) {
public function __construct($key, Node\Expr $value, array $attributes = []) {
parent::__construct($attributes);
$this->key = $key;
$this->key = \is_string($key) ? new Node\Identifier($key) : $key;
$this->value = $value;
}
public function getSubNodeNames() {
return array('key', 'value');
public function getSubNodeNames() : array {
return ['key', 'value'];
}
public function getType() : string {
return 'Stmt_DeclareDeclare';
}
}

View File

@@ -1,29 +1,34 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
class Declare_ extends Node\Stmt
{
/** @var DeclareDeclare[] List of declares */
public $declares;
/** @var Node[] Statements */
/** @var Node\Stmt[]|null Statements */
public $stmts;
/**
* Constructs a declare node.
*
* @param DeclareDeclare[] $declares List of declares
* @param Node[]|null $stmts Statements
* @param Node\Stmt[]|null $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $declares, array $stmts = null, array $attributes = array()) {
public function __construct(array $declares, array $stmts = null, array $attributes = []) {
parent::__construct($attributes);
$this->declares = $declares;
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('declares', 'stmts');
public function getSubNodeNames() : array {
return ['declares', 'stmts'];
}
public function getType() : string {
return 'Stmt_Declare';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -6,25 +6,29 @@ use PhpParser\Node;
class Do_ extends Node\Stmt
{
/** @var Node\Stmt[] Statements */
public $stmts;
/** @var Node\Expr Condition */
public $cond;
/** @var Node[] Statements */
public $stmts;
/**
* Constructs a do while node.
*
* @param Node\Expr $cond Condition
* @param Node[] $stmts Statements
* @param array $attributes Additional attributes
* @param Node\Expr $cond Condition
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('cond', 'stmts');
public function getSubNodeNames() : array {
return ['stmts', 'cond'];
}
public function getType() : string {
return 'Stmt_Do';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Echo_ extends Node\Stmt
* @param Node\Expr[] $exprs Expressions
* @param array $attributes Additional attributes
*/
public function __construct(array $exprs, array $attributes = array()) {
public function __construct(array $exprs, array $attributes = []) {
parent::__construct($attributes);
$this->exprs = $exprs;
}
public function getSubNodeNames() {
return array('exprs');
public function getSubNodeNames() : array {
return ['exprs'];
}
public function getType() : string {
return 'Stmt_Echo';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -8,23 +8,27 @@ class ElseIf_ extends Node\Stmt
{
/** @var Node\Expr Condition */
public $cond;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs an elseif node.
*
* @param Node\Expr $cond Condition
* @param Node[] $stmts Statements
* @param array $attributes Additional attributes
* @param Node\Expr $cond Condition
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('cond', 'stmts');
public function getSubNodeNames() : array {
return ['cond', 'stmts'];
}
public function getType() : string {
return 'Stmt_ElseIf';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -6,21 +6,25 @@ use PhpParser\Node;
class Else_ extends Node\Stmt
{
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs an else node.
*
* @param Node[] $stmts Statements
* @param array $attributes Additional attributes
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $stmts = array(), array $attributes = array()) {
public function __construct(array $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('stmts');
public function getSubNodeNames() : array {
return ['stmts'];
}
public function getType() : string {
return 'Stmt_Else';
}
}

View File

@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
/**
* Represents statements of type "expr;"
*/
class Expression extends Node\Stmt
{
/** @var Node\Expr Expression */
public $expr;
/**
* Constructs an expression statement.
*
* @param Node\Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr, array $attributes = []) {
parent::__construct($attributes);
$this->expr = $expr;
}
public function getSubNodeNames() : array {
return ['expr'];
}
public function getType() : string {
return 'Stmt_Expression';
}
}

View File

@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
class Finally_ extends Node\Stmt
{
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs a finally node.
*
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->stmts = $stmts;
}
public function getSubNodeNames() : array {
return ['stmts'];
}
public function getType() : string {
return 'Stmt_Finally';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -12,7 +12,7 @@ class For_ extends Node\Stmt
public $cond;
/** @var Node\Expr[] Loop expressions */
public $loop;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
@@ -25,15 +25,19 @@ class For_ extends Node\Stmt
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $subNodes = array(), array $attributes = array()) {
public function __construct(array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->init = isset($subNodes['init']) ? $subNodes['init'] : array();
$this->cond = isset($subNodes['cond']) ? $subNodes['cond'] : array();
$this->loop = isset($subNodes['loop']) ? $subNodes['loop'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
$this->init = $subNodes['init'] ?? [];
$this->cond = $subNodes['cond'] ?? [];
$this->loop = $subNodes['loop'] ?? [];
$this->stmts = $subNodes['stmts'] ?? [];
}
public function getSubNodeNames() {
return array('init', 'cond', 'loop', 'stmts');
public function getSubNodeNames() : array {
return ['init', 'cond', 'loop', 'stmts'];
}
public function getType() : string {
return 'Stmt_For';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -14,7 +14,7 @@ class Foreach_ extends Node\Stmt
public $byRef;
/** @var Node\Expr Variable to assign value to */
public $valueVar;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
@@ -28,16 +28,20 @@ class Foreach_ extends Node\Stmt
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = array(), array $attributes = array()) {
public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->expr = $expr;
$this->keyVar = isset($subNodes['keyVar']) ? $subNodes['keyVar'] : null;
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
$this->keyVar = $subNodes['keyVar'] ?? null;
$this->byRef = $subNodes['byRef'] ?? false;
$this->valueVar = $valueVar;
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
$this->stmts = $subNodes['stmts'] ?? [];
}
public function getSubNodeNames() {
return array('expr', 'keyVar', 'byRef', 'valueVar', 'stmts');
public function getSubNodeNames() : array {
return ['expr', 'keyVar', 'byRef', 'valueVar', 'stmts'];
}
public function getType() : string {
return 'Stmt_Foreach';
}
}

View File

@@ -1,27 +1,30 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Node\FunctionLike;
/**
* @property Node\Name $namespacedName Namespaced name (if using NameResolver)
*/
class Function_ extends Node\Stmt implements FunctionLike
{
/** @var bool Whether function returns by reference */
public $byRef;
/** @var string Name */
/** @var Node\Identifier Name */
public $name;
/** @var Node\Param[] Parameters */
public $params;
/** @var null|string|Node\Name Return type */
/** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
public $returnType;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs a function node.
*
* @param string $name Name
* @param string|Node\Identifier $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'byRef' => false : Whether to return by reference
* 'params' => array(): Parameters
@@ -29,24 +32,25 @@ class Function_ extends Node\Stmt implements FunctionLike
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
public function __construct($name, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
$this->name = $name;
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
$this->byRef = $subNodes['byRef'] ?? false;
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
$this->params = $subNodes['params'] ?? [];
$returnType = $subNodes['returnType'] ?? null;
$this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
$this->stmts = $subNodes['stmts'] ?? [];
}
public function getSubNodeNames() {
return array('byRef', 'name', 'params', 'returnType', 'stmts');
public function getSubNodeNames() : array {
return ['byRef', 'name', 'params', 'returnType', 'stmts'];
}
public function returnsByRef() {
public function returnsByRef() : bool {
return $this->byRef;
}
public function getParams() {
public function getParams() : array {
return $this->params;
}
@@ -54,7 +58,12 @@ class Function_ extends Node\Stmt implements FunctionLike
return $this->returnType;
}
public function getStmts() {
/** @return Node\Stmt[] */
public function getStmts() : array {
return $this->stmts;
}
public function getType() : string {
return 'Stmt_Function';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Global_ extends Node\Stmt
* @param Node\Expr[] $vars Variables to unset
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
public function __construct(array $vars, array $attributes = []) {
parent::__construct($attributes);
$this->vars = $vars;
}
public function getSubNodeNames() {
return array('vars');
public function getSubNodeNames() : array {
return ['vars'];
}
public function getType() : string {
return 'Stmt_Global';
}
}

View File

@@ -1,26 +1,31 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt;
class Goto_ extends Stmt
{
/** @var string Name of label to jump to */
/** @var Identifier Name of label to jump to */
public $name;
/**
* Constructs a goto node.
*
* @param string $name Name of label to jump to
* @param array $attributes Additional attributes
* @param string|Identifier $name Name of label to jump to
* @param array $attributes Additional attributes
*/
public function __construct($name, array $attributes = array()) {
public function __construct($name, array $attributes = []) {
parent::__construct($attributes);
$this->name = $name;
$this->name = \is_string($name) ? new Identifier($name) : $name;
}
public function getSubNodeNames() {
return array('name');
public function getSubNodeNames() : array {
return ['name'];
}
public function getType() : string {
return 'Stmt_Goto';
}
}

View File

@@ -1,9 +1,9 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node\Stmt;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
class GroupUse extends Stmt
{
@@ -22,14 +22,18 @@ class GroupUse extends Stmt
* @param int $type Type of group use
* @param array $attributes Additional attributes
*/
public function __construct(Name $prefix, array $uses, $type = Use_::TYPE_NORMAL, array $attributes = array()) {
public function __construct(Name $prefix, array $uses, int $type = Use_::TYPE_NORMAL, array $attributes = []) {
parent::__construct($attributes);
$this->type = $type;
$this->prefix = $prefix;
$this->uses = $uses;
}
public function getSubNodeNames() {
return array('type', 'prefix', 'uses');
public function getSubNodeNames() : array {
return ['type', 'prefix', 'uses'];
}
public function getType() : string {
return 'Stmt_GroupUse';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class HaltCompiler extends Stmt
* @param string $remaining Remaining text after halt compiler statement.
* @param array $attributes Additional attributes
*/
public function __construct($remaining, array $attributes = array()) {
public function __construct(string $remaining, array $attributes = []) {
parent::__construct($attributes);
$this->remaining = $remaining;
}
public function getSubNodeNames() {
return array('remaining');
public function getSubNodeNames() : array {
return ['remaining'];
}
public function getType() : string {
return 'Stmt_HaltCompiler';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -8,7 +8,7 @@ class If_ extends Node\Stmt
{
/** @var Node\Expr Condition expression */
public $cond;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/** @var ElseIf_[] Elseif clauses */
public $elseifs;
@@ -25,15 +25,19 @@ class If_ extends Node\Stmt
* 'else' => null : Else clause
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $subNodes = array(), array $attributes = array()) {
public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
$this->elseifs = isset($subNodes['elseifs']) ? $subNodes['elseifs'] : array();
$this->else = isset($subNodes['else']) ? $subNodes['else'] : null;
$this->stmts = $subNodes['stmts'] ?? [];
$this->elseifs = $subNodes['elseifs'] ?? [];
$this->else = $subNodes['else'] ?? null;
}
public function getSubNodeNames() {
return array('cond', 'stmts', 'elseifs', 'else');
public function getSubNodeNames() : array {
return ['cond', 'stmts', 'elseifs', 'else'];
}
public function getType() : string {
return 'Stmt_If';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class InlineHTML extends Stmt
* @param string $value String
* @param array $attributes Additional attributes
*/
public function __construct($value, array $attributes = array()) {
public function __construct(string $value, array $attributes = []) {
parent::__construct($attributes);
$this->value = $value;
}
public function getSubNodeNames() {
return array('value');
public function getSubNodeNames() : array {
return ['value'];
}
public function getType() : string {
return 'Stmt_InlineHTML';
}
}

View File

@@ -1,51 +1,35 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Error;
class Interface_ extends ClassLike
{
/** @var Node\Name[] Extended interfaces */
public $extends;
protected static $specialNames = array(
'self' => true,
'parent' => true,
'static' => true,
);
/**
* Constructs a class node.
*
* @param string $name Name
* @param string|Node\Identifier $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'extends' => array(): Name of extended interfaces
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
public function __construct($name, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->name = $name;
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
if (isset(self::$specialNames[strtolower($this->name)])) {
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
}
foreach ($this->extends as $interface) {
if (isset(self::$specialNames[strtolower($interface)])) {
throw new Error(
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
$interface->getAttributes()
);
}
}
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
$this->extends = $subNodes['extends'] ?? [];
$this->stmts = $subNodes['stmts'] ?? [];
}
public function getSubNodeNames() {
return array('name', 'extends', 'stmts');
public function getSubNodeNames() : array {
return ['name', 'extends', 'stmts'];
}
public function getType() : string {
return 'Stmt_Interface';
}
}

View File

@@ -1,26 +1,31 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt;
class Label extends Stmt
{
/** @var string Name */
/** @var Identifier Name */
public $name;
/**
* Constructs a label node.
*
* @param string $name Name
* @param array $attributes Additional attributes
* @param string|Identifier $name Name
* @param array $attributes Additional attributes
*/
public function __construct($name, array $attributes = array()) {
public function __construct($name, array $attributes = []) {
parent::__construct($attributes);
$this->name = $name;
$this->name = \is_string($name) ? new Identifier($name) : $name;
}
public function getSubNodeNames() {
return array('name');
public function getSubNodeNames() : array {
return ['name'];
}
public function getType() : string {
return 'Stmt_Label';
}
}

View File

@@ -1,52 +1,38 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Error;
class Namespace_ extends Node\Stmt
{
/* For use in the "kind" attribute */
const KIND_SEMICOLON = 1;
const KIND_BRACED = 2;
/** @var null|Node\Name Name */
public $name;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
protected static $specialNames = array(
'self' => true,
'parent' => true,
'static' => true,
);
/**
* Constructs a namespace node.
*
* @param null|Node\Name $name Name
* @param null|Node[] $stmts Statements
* @param array $attributes Additional attributes
* @param null|Node\Name $name Name
* @param null|Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $name = null, $stmts = array(), array $attributes = array()) {
public function __construct(Node\Name $name = null, $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->name = $name;
$this->stmts = $stmts;
if (isset(self::$specialNames[strtolower($this->name)])) {
throw new Error(
sprintf('Cannot use \'%s\' as namespace name', $this->name),
$this->name->getAttributes()
);
}
if (null !== $this->stmts) {
foreach ($this->stmts as $stmt) {
if ($stmt instanceof self) {
throw new Error('Namespace declarations cannot be nested', $stmt->getAttributes());
}
}
}
}
public function getSubNodeNames() {
return array('name', 'stmts');
public function getSubNodeNames() : array {
return ['name', 'stmts'];
}
public function getType() : string {
return 'Stmt_Namespace';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -7,7 +7,11 @@ use PhpParser\Node;
/** Nop/empty statement (;). */
class Nop extends Node\Stmt
{
public function getSubNodeNames() {
return array();
public function getSubNodeNames() : array {
return [];
}
public function getType() : string {
return 'Stmt_Nop';
}
}

View File

@@ -1,56 +1,71 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Error;
class Property extends Node\Stmt
{
/** @var int Modifiers */
public $type;
public $flags;
/** @var PropertyProperty[] Properties */
public $props;
/**
* Constructs a class property list node.
*
* @param int $type Modifiers
* @param int $flags Modifiers
* @param PropertyProperty[] $props Properties
* @param array $attributes Additional attributes
*/
public function __construct($type, array $props, array $attributes = array()) {
if ($type & Class_::MODIFIER_ABSTRACT) {
throw new Error('Properties cannot be declared abstract');
}
if ($type & Class_::MODIFIER_FINAL) {
throw new Error('Properties cannot be declared final');
}
public function __construct(int $flags, array $props, array $attributes = []) {
parent::__construct($attributes);
$this->type = $type;
$this->flags = $flags;
$this->props = $props;
}
public function getSubNodeNames() {
return array('type', 'props');
public function getSubNodeNames() : array {
return ['flags', 'props'];
}
public function isPublic() {
return ($this->type & Class_::MODIFIER_PUBLIC) !== 0
|| ($this->type & Class_::VISIBILITY_MODIFER_MASK) === 0;
/**
* Whether the property is explicitly or implicitly public.
*
* @return bool
*/
public function isPublic() : bool {
return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
|| ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
}
public function isProtected() {
return (bool) ($this->type & Class_::MODIFIER_PROTECTED);
/**
* Whether the property is protected.
*
* @return bool
*/
public function isProtected() : bool {
return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
}
public function isPrivate() {
return (bool) ($this->type & Class_::MODIFIER_PRIVATE);
/**
* Whether the property is private.
*
* @return bool
*/
public function isPrivate() : bool {
return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
}
public function isStatic() {
return (bool) ($this->type & Class_::MODIFIER_STATIC);
/**
* Whether the property is static.
*
* @return bool
*/
public function isStatic() : bool {
return (bool) ($this->flags & Class_::MODIFIER_STATIC);
}
public function getType() : string {
return 'Stmt_Property';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -6,7 +6,7 @@ use PhpParser\Node;
class PropertyProperty extends Node\Stmt
{
/** @var string Name */
/** @var Node\VarLikeIdentifier Name */
public $name;
/** @var null|Node\Expr Default */
public $default;
@@ -14,17 +14,21 @@ class PropertyProperty extends Node\Stmt
/**
* Constructs a class property node.
*
* @param string $name Name
* @param null|Node\Expr $default Default value
* @param array $attributes Additional attributes
* @param string|Node\VarLikeIdentifier $name Name
* @param null|Node\Expr $default Default value
* @param array $attributes Additional attributes
*/
public function __construct($name, Node\Expr $default = null, array $attributes = array()) {
public function __construct($name, Node\Expr $default = null, array $attributes = []) {
parent::__construct($attributes);
$this->name = $name;
$this->name = \is_string($name) ? new Node\VarLikeIdentifier($name) : $name;
$this->default = $default;
}
public function getSubNodeNames() {
return array('name', 'default');
public function getSubNodeNames() : array {
return ['name', 'default'];
}
public function getType() : string {
return 'Stmt_PropertyProperty';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Return_ extends Node\Stmt
* @param null|Node\Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr = null, array $attributes = array()) {
public function __construct(Node\Expr $expr = null, array $attributes = []) {
parent::__construct($attributes);
$this->expr = $expr;
}
public function getSubNodeNames() {
return array('expr');
public function getSubNodeNames() : array {
return ['expr'];
}
public function getType() : string {
return 'Stmt_Return';
}
}

View File

@@ -1,30 +1,37 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Node\Expr;
class StaticVar extends Node\Stmt
{
/** @var string Name */
public $name;
/** @var Expr\Variable Variable */
public $var;
/** @var null|Node\Expr Default value */
public $default;
/**
* Constructs a static variable node.
*
* @param string $name Name
* @param Expr\Variable $var Name
* @param null|Node\Expr $default Default value
* @param array $attributes Additional attributes
*/
public function __construct($name, Node\Expr $default = null, array $attributes = array()) {
public function __construct(
Expr\Variable $var, Node\Expr $default = null, array $attributes = []
) {
parent::__construct($attributes);
$this->name = $name;
$this->var = $var;
$this->default = $default;
}
public function getSubNodeNames() {
return array('name', 'default');
public function getSubNodeNames() : array {
return ['var', 'default'];
}
public function getType() : string {
return 'Stmt_StaticVar';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Static_ extends Stmt
* @param StaticVar[] $vars Variable definitions
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
public function __construct(array $vars, array $attributes = []) {
parent::__construct($attributes);
$this->vars = $vars;
}
public function getSubNodeNames() {
return array('vars');
public function getSubNodeNames() : array {
return ['vars'];
}
public function getType() : string {
return 'Stmt_Static';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -18,13 +18,17 @@ class Switch_ extends Node\Stmt
* @param Case_[] $cases Case list
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $cases, array $attributes = array()) {
public function __construct(Node\Expr $cond, array $cases, array $attributes = []) {
parent::__construct($attributes);
$this->cond = $cond;
$this->cases = $cases;
}
public function getSubNodeNames() {
return array('cond', 'cases');
public function getSubNodeNames() : array {
return ['cond', 'cases'];
}
public function getType() : string {
return 'Stmt_Switch';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Throw_ extends Node\Stmt
* @param Node\Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr, array $attributes = array()) {
public function __construct(Node\Expr $expr, array $attributes = []) {
parent::__construct($attributes);
$this->expr = $expr;
}
public function getSubNodeNames() {
return array('expr');
public function getSubNodeNames() : array {
return ['expr'];
}
public function getType() : string {
return 'Stmt_Throw';
}
}

View File

@@ -1,10 +1,9 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
class TraitUse extends Node\Stmt
{
/** @var Node\Name[] Traits */
@@ -19,13 +18,17 @@ class TraitUse extends Node\Stmt
* @param TraitUseAdaptation[] $adaptations Adaptations
* @param array $attributes Additional attributes
*/
public function __construct(array $traits, array $adaptations = array(), array $attributes = array()) {
public function __construct(array $traits, array $adaptations = [], array $attributes = []) {
parent::__construct($attributes);
$this->traits = $traits;
$this->adaptations = $adaptations;
}
public function getSubNodeNames() {
return array('traits', 'adaptations');
public function getSubNodeNames() : array {
return ['traits', 'adaptations'];
}
public function getType() : string {
return 'Stmt_TraitUse';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -6,8 +6,8 @@ use PhpParser\Node;
abstract class TraitUseAdaptation extends Node\Stmt
{
/** @var Node\Name Trait name */
/** @var Node\Name|null Trait name */
public $trait;
/** @var string Method name */
/** @var Node\Identifier Method name */
public $method;
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt\TraitUseAdaptation;
@@ -8,27 +8,31 @@ class Alias extends Node\Stmt\TraitUseAdaptation
{
/** @var null|int New modifier */
public $newModifier;
/** @var null|string New name */
/** @var null|Node\Identifier New name */
public $newName;
/**
* Constructs a trait use precedence adaptation node.
*
* @param null|Node\Name $trait Trait name
* @param string $method Method name
* @param null|int $newModifier New modifier
* @param null|string $newName New name
* @param array $attributes Additional attributes
* @param null|Node\Name $trait Trait name
* @param string|Node\Identifier $method Method name
* @param null|int $newModifier New modifier
* @param null|string|Node\Identifier $newName New name
* @param array $attributes Additional attributes
*/
public function __construct($trait, $method, $newModifier, $newName, array $attributes = array()) {
public function __construct($trait, $method, $newModifier, $newName, array $attributes = []) {
parent::__construct($attributes);
$this->trait = $trait;
$this->method = $method;
$this->method = \is_string($method) ? new Node\Identifier($method) : $method;
$this->newModifier = $newModifier;
$this->newName = $newName;
$this->newName = \is_string($newName) ? new Node\Identifier($newName) : $newName;
}
public function getSubNodeNames() {
return array('trait', 'method', 'newModifier', 'newName');
public function getSubNodeNames() : array {
return ['trait', 'method', 'newModifier', 'newName'];
}
public function getType() : string {
return 'Stmt_TraitUseAdaptation_Alias';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt\TraitUseAdaptation;
@@ -12,19 +12,23 @@ class Precedence extends Node\Stmt\TraitUseAdaptation
/**
* Constructs a trait use precedence adaptation node.
*
* @param Node\Name $trait Trait name
* @param string $method Method name
* @param Node\Name[] $insteadof Overwritten traits
* @param array $attributes Additional attributes
* @param Node\Name $trait Trait name
* @param string|Node\Identifier $method Method name
* @param Node\Name[] $insteadof Overwritten traits
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $trait, $method, array $insteadof, array $attributes = array()) {
public function __construct(Node\Name $trait, $method, array $insteadof, array $attributes = []) {
parent::__construct($attributes);
$this->trait = $trait;
$this->method = $method;
$this->method = \is_string($method) ? new Node\Identifier($method) : $method;
$this->insteadof = $insteadof;
}
public function getSubNodeNames() {
return array('trait', 'method', 'insteadof');
public function getSubNodeNames() : array {
return ['trait', 'method', 'insteadof'];
}
public function getType() : string {
return 'Stmt_TraitUseAdaptation_Precedence';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -9,17 +9,22 @@ class Trait_ extends ClassLike
/**
* Constructs a trait node.
*
* @param string $name Name
* @param Node[] $stmts Statements
* @param string|Node\Identifier $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct($name, array $stmts = array(), array $attributes = array()) {
public function __construct($name, array $subNodes = [], array $attributes = []) {
parent::__construct($attributes);
$this->name = $name;
$this->stmts = $stmts;
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
$this->stmts = $subNodes['stmts'] ?? [];
}
public function getSubNodeNames() {
return array('name', 'stmts');
public function getSubNodeNames() : array {
return ['name', 'stmts'];
}
public function getType() : string {
return 'Stmt_Trait';
}
}

View File

@@ -1,39 +1,38 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Error;
class TryCatch extends Node\Stmt
{
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/** @var Catch_[] Catches */
public $catches;
/** @var null|Node[] Finally statements */
public $finallyStmts;
/** @var null|Finally_ Optional finally node */
public $finally;
/**
* Constructs a try catch node.
*
* @param Node[] $stmts Statements
* @param Catch_[] $catches Catches
* @param null|Node[] $finallyStmts Finally statements (null means no finally clause)
* @param array|null $attributes Additional attributes
* @param Node\Stmt[] $stmts Statements
* @param Catch_[] $catches Catches
* @param null|Finally_ $finally Optionaly finally node
* @param array $attributes Additional attributes
*/
public function __construct(array $stmts, array $catches, array $finallyStmts = null, array $attributes = array()) {
if (empty($catches) && null === $finallyStmts) {
throw new Error('Cannot use try without catch or finally');
}
public function __construct(array $stmts, array $catches, Finally_ $finally = null, array $attributes = []) {
parent::__construct($attributes);
$this->stmts = $stmts;
$this->catches = $catches;
$this->finallyStmts = $finallyStmts;
$this->finally = $finally;
}
public function getSubNodeNames() {
return array('stmts', 'catches', 'finallyStmts');
public function getSubNodeNames() : array {
return ['stmts', 'catches', 'finally'];
}
public function getType() : string {
return 'Stmt_TryCatch';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -15,12 +15,16 @@ class Unset_ extends Node\Stmt
* @param Node\Expr[] $vars Variables to unset
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
public function __construct(array $vars, array $attributes = []) {
parent::__construct($attributes);
$this->vars = $vars;
}
public function getSubNodeNames() {
return array('vars');
public function getSubNodeNames() : array {
return ['vars'];
}
public function getType() : string {
return 'Stmt_Unset';
}
}

View File

@@ -1,9 +1,9 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Error;
use PhpParser\Node\Identifier;
class UseUse extends Node\Stmt
{
@@ -11,36 +11,42 @@ class UseUse extends Node\Stmt
public $type;
/** @var Node\Name Namespace, class, function or constant to alias */
public $name;
/** @var string Alias */
/** @var Identifier|null Alias */
public $alias;
/**
* Constructs an alias (use) node.
*
* @param Node\Name $name Namespace/Class to alias
* @param null|string $alias Alias
* @param int $type Type of the use element (for mixed group use declarations only)
* @param array $attributes Additional attributes
* @param Node\Name $name Namespace/Class to alias
* @param null|string|Identifier $alias Alias
* @param int $type Type of the use element (for mixed group use only)
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $name, $alias = null, $type = Use_::TYPE_UNKNOWN, array $attributes = array()) {
if (null === $alias) {
$alias = $name->getLast();
}
if ('self' == strtolower($alias) || 'parent' == strtolower($alias)) {
throw new Error(sprintf(
'Cannot use %s as %s because \'%2$s\' is a special class name',
$name, $alias
));
}
public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) {
parent::__construct($attributes);
$this->type = $type;
$this->name = $name;
$this->alias = $alias;
$this->alias = \is_string($alias) ? new Identifier($alias) : $alias;
}
public function getSubNodeNames() {
return array('type', 'name', 'alias');
public function getSubNodeNames() : array {
return ['type', 'name', 'alias'];
}
/**
* Get alias. If not explicitly given this is the last component of the used name.
*
* @return Identifier
*/
public function getAlias() : Identifier {
if (null !== $this->alias) {
return $this->alias;
}
return new Identifier($this->name->getLast());
}
public function getType() : string {
return 'Stmt_UseUse';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -31,13 +31,17 @@ class Use_ extends Stmt
* @param int $type Type of alias
* @param array $attributes Additional attributes
*/
public function __construct(array $uses, $type = self::TYPE_NORMAL, array $attributes = array()) {
public function __construct(array $uses, int $type = self::TYPE_NORMAL, array $attributes = []) {
parent::__construct($attributes);
$this->type = $type;
$this->uses = $uses;
}
public function getSubNodeNames() {
return array('type', 'uses');
public function getSubNodeNames() : array {
return ['type', 'uses'];
}
public function getType() : string {
return 'Stmt_Use';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
@@ -8,23 +8,27 @@ class While_ extends Node\Stmt
{
/** @var Node\Expr Condition */
public $cond;
/** @var Node[] Statements */
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs a while node.
*
* @param Node\Expr $cond Condition
* @param Node[] $stmts Statements
* @param array $attributes Additional attributes
* @param Node\Expr $cond Condition
* @param Node\Stmt[] $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) {
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}
public function getSubNodeNames() {
return array('cond', 'stmts');
public function getSubNodeNames() : array {
return ['cond', 'stmts'];
}
public function getType() : string {
return 'Stmt_While';
}
}