Chris@0: true, Chris@0: '__destruct' => true, Chris@0: '__call' => true, Chris@0: '__callstatic' => true, Chris@0: '__get' => true, Chris@0: '__set' => true, Chris@0: '__isset' => true, Chris@0: '__unset' => true, Chris@0: '__sleep' => true, Chris@0: '__wakeup' => true, Chris@0: '__tostring' => true, Chris@0: '__set_state' => true, Chris@0: '__clone' => true, Chris@0: '__invoke' => true, Chris@0: '__debuginfo' => true, Chris@0: ]; Chris@0: Chris@0: /** Chris@0: * Constructs a class method node. Chris@0: * Chris@0: * @param string|Node\Identifier $name Name Chris@0: * @param array $subNodes Array of the following optional subnodes: Chris@0: * 'flags => MODIFIER_PUBLIC: Flags Chris@0: * 'byRef' => false : Whether to return by reference Chris@0: * 'params' => array() : Parameters Chris@0: * 'returnType' => null : Return type Chris@0: * 'stmts' => array() : Statements Chris@0: * @param array $attributes Additional attributes Chris@0: */ Chris@0: public function __construct($name, array $subNodes = [], array $attributes = []) { Chris@0: parent::__construct($attributes); Chris@0: $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0; Chris@0: $this->byRef = $subNodes['byRef'] ?? false; Chris@0: $this->name = \is_string($name) ? new Node\Identifier($name) : $name; Chris@0: $this->params = $subNodes['params'] ?? []; Chris@0: $returnType = $subNodes['returnType'] ?? null; Chris@0: $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; Chris@0: $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : []; Chris@0: } Chris@0: Chris@0: public function getSubNodeNames() : array { Chris@0: return ['flags', 'byRef', 'name', 'params', 'returnType', 'stmts']; Chris@0: } Chris@0: Chris@0: public function returnsByRef() : bool { Chris@0: return $this->byRef; Chris@0: } Chris@0: Chris@0: public function getParams() : array { Chris@0: return $this->params; Chris@0: } Chris@0: Chris@0: public function getReturnType() { Chris@0: return $this->returnType; Chris@0: } Chris@0: Chris@0: public function getStmts() { Chris@0: return $this->stmts; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is explicitly or implicitly public. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isPublic() : bool { Chris@0: return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0 Chris@0: || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is protected. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isProtected() : bool { Chris@0: return (bool) ($this->flags & Class_::MODIFIER_PROTECTED); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is private. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isPrivate() : bool { Chris@0: return (bool) ($this->flags & Class_::MODIFIER_PRIVATE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is abstract. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isAbstract() : bool { Chris@0: return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is final. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isFinal() : bool { Chris@0: return (bool) ($this->flags & Class_::MODIFIER_FINAL); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is static. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isStatic() : bool { Chris@0: return (bool) ($this->flags & Class_::MODIFIER_STATIC); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Whether the method is magic. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isMagic() : bool { Chris@0: return isset(self::$magicNames[$this->name->toLowerString()]); Chris@0: } Chris@0: Chris@0: public function getType() : string { Chris@0: return 'Stmt_ClassMethod'; Chris@0: } Chris@0: }