mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Use null-coalesce operator
This commit is contained in:
parent
7bdb55f9a8
commit
fba61390d8
@ -39,7 +39,7 @@ class Error extends \RuntimeException
|
||||
* @return int Error start line
|
||||
*/
|
||||
public function getStartLine() {
|
||||
return isset($this->attributes['startLine']) ? $this->attributes['startLine'] : -1;
|
||||
return $this->attributes['startLine'] ?? -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +48,7 @@ class Error extends \RuntimeException
|
||||
* @return int Error end line
|
||||
*/
|
||||
public function getEndLine() {
|
||||
return isset($this->attributes['endLine']) ? $this->attributes['endLine'] : -1;
|
||||
return $this->attributes['endLine'] ?? -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,12 +35,12 @@ class Closure extends Expr implements FunctionLike
|
||||
*/
|
||||
public function __construct(array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->static = isset($subNodes['static']) ? $subNodes['static'] : false;
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
||||
$this->uses = isset($subNodes['uses']) ? $subNodes['uses'] : array();
|
||||
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
$this->static = $subNodes['static'] ?? false;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
$this->params = $subNodes['params'] ?? array();
|
||||
$this->uses = $subNodes['uses'] ?? array();
|
||||
$this->returnType = $subNodes['returnType'] ?? null;
|
||||
$this->stmts = $subNodes['stmts'] ?? array();
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -52,12 +52,11 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
*/
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->flags = isset($subNodes['flags']) ? $subNodes['flags']
|
||||
: (isset($subNodes['type']) ? $subNodes['type'] : 0);
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
$this->name = $name;
|
||||
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
||||
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
|
||||
$this->params = $subNodes['params'] ?? array();
|
||||
$this->returnType = $subNodes['returnType'] ?? null;
|
||||
$this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
|
||||
}
|
||||
|
||||
|
@ -44,12 +44,11 @@ class Class_ extends ClassLike
|
||||
*/
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->flags = isset($subNodes['flags']) ? $subNodes['flags']
|
||||
: (isset($subNodes['type']) ? $subNodes['type'] : 0);
|
||||
$this->flags = $subNodes['flags'] ?? $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();
|
||||
$this->extends = $subNodes['extends'] ?? null;
|
||||
$this->implements = $subNodes['implements'] ?? array();
|
||||
$this->stmts = $subNodes['stmts'] ?? array();
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -27,10 +27,10 @@ class For_ extends Node\Stmt
|
||||
*/
|
||||
public function __construct(array $subNodes = array(), array $attributes = array()) {
|
||||
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'] ?? array();
|
||||
$this->cond = $subNodes['cond'] ?? array();
|
||||
$this->loop = $subNodes['loop'] ?? array();
|
||||
$this->stmts = $subNodes['stmts'] ?? array();
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -31,10 +31,10 @@ class Foreach_ extends Node\Stmt
|
||||
public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = array(), array $attributes = array()) {
|
||||
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'] ?? array();
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -34,11 +34,11 @@ class Function_ extends Node\Stmt implements FunctionLike
|
||||
*/
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->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->params = $subNodes['params'] ?? array();
|
||||
$this->returnType = $subNodes['returnType'] ?? null;
|
||||
$this->stmts = $subNodes['stmts'] ?? array();
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -28,9 +28,9 @@ class If_ extends Node\Stmt
|
||||
public function __construct(Node\Expr $cond, array $subNodes = array(), array $attributes = array()) {
|
||||
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'] ?? array();
|
||||
$this->elseifs = $subNodes['elseifs'] ?? array();
|
||||
$this->else = $subNodes['else'] ?? null;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -21,8 +21,8 @@ class Interface_ extends ClassLike
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->name = $name;
|
||||
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array();
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
$this->extends = $subNodes['extends'] ?? array();
|
||||
$this->stmts = $subNodes['stmts'] ?? array();
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@ -43,8 +43,8 @@ class NameResolver extends NodeVisitorAbstract
|
||||
*/
|
||||
public function __construct(ErrorHandler $errorHandler = null, array $options = []) {
|
||||
$this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing;
|
||||
$this->preserveOriginalNames = !empty($options['preserveOriginalNames']);
|
||||
$this->replaceNodes = isset($options['replaceNodes']) ? $options['replaceNodes'] : true;
|
||||
$this->preserveOriginalNames = $options['preserveOriginalNames'] ?? false;
|
||||
$this->replaceNodes = $options['replaceNodes'] ?? true;
|
||||
}
|
||||
|
||||
public function beforeTraverse(array $nodes) {
|
||||
|
Loading…
Reference in New Issue
Block a user