-<?php
+<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
const MODIFIER_FINAL = 32;
const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4
- /** @deprecated */
- const VISIBILITY_MODIFER_MASK = self::VISIBILITY_MODIFIER_MASK;
/** @var int Type */
public $flags;
/** @var Node\Name[] Names of implemented interfaces */
public $implements;
- /** @deprecated Use $flags instead */
- public $type;
-
- 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:
* 'flags' => 0 : Flags
* 'extends' => null : Name of extended class
* '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->flags = isset($subNodes['flags']) ? $subNodes['flags']
- : (isset($subNodes['type']) ? $subNodes['type'] : 0);
- $this->type = $this->flags;
- $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->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('flags', 'name', 'extends', 'implements', 'stmts');
+ public function getSubNodeNames() : array {
+ return ['flags', 'name', 'extends', 'implements', 'stmts'];
}
- public function isAbstract() {
+ /**
+ * Whether the class is explicitly abstract.
+ *
+ * @return bool
+ */
+ public function isAbstract() : bool {
return (bool) ($this->flags & self::MODIFIER_ABSTRACT);
}
- public function isFinal() {
+ /**
+ * 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;
}
throw new Error('Cannot use the final modifier on an abstract class member');
}
}
+
+ public function getType() : string {
+ return 'Stmt_Class';
+ }
}