annotate vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMethod.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 5fb285c0d0e3
children
rev   line source
Chris@13 1 <?php declare(strict_types=1);
Chris@0 2
Chris@0 3 namespace PhpParser\Node\Stmt;
Chris@0 4
Chris@0 5 use PhpParser\Node;
Chris@0 6 use PhpParser\Node\FunctionLike;
Chris@0 7
Chris@0 8 class ClassMethod extends Node\Stmt implements FunctionLike
Chris@0 9 {
Chris@0 10 /** @var int Flags */
Chris@0 11 public $flags;
Chris@0 12 /** @var bool Whether to return by reference */
Chris@0 13 public $byRef;
Chris@13 14 /** @var Node\Identifier Name */
Chris@0 15 public $name;
Chris@0 16 /** @var Node\Param[] Parameters */
Chris@0 17 public $params;
Chris@13 18 /** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
Chris@0 19 public $returnType;
Chris@13 20 /** @var Node\Stmt[]|null Statements */
Chris@0 21 public $stmts;
Chris@0 22
Chris@13 23 private static $magicNames = [
Chris@13 24 '__construct' => true,
Chris@13 25 '__destruct' => true,
Chris@13 26 '__call' => true,
Chris@13 27 '__callstatic' => true,
Chris@13 28 '__get' => true,
Chris@13 29 '__set' => true,
Chris@13 30 '__isset' => true,
Chris@13 31 '__unset' => true,
Chris@13 32 '__sleep' => true,
Chris@13 33 '__wakeup' => true,
Chris@13 34 '__tostring' => true,
Chris@13 35 '__set_state' => true,
Chris@13 36 '__clone' => true,
Chris@13 37 '__invoke' => true,
Chris@13 38 '__debuginfo' => true,
Chris@13 39 ];
Chris@0 40
Chris@0 41 /**
Chris@0 42 * Constructs a class method node.
Chris@0 43 *
Chris@13 44 * @param string|Node\Identifier $name Name
Chris@13 45 * @param array $subNodes Array of the following optional subnodes:
Chris@13 46 * 'flags => MODIFIER_PUBLIC: Flags
Chris@13 47 * 'byRef' => false : Whether to return by reference
Chris@13 48 * 'params' => array() : Parameters
Chris@13 49 * 'returnType' => null : Return type
Chris@13 50 * 'stmts' => array() : Statements
Chris@13 51 * @param array $attributes Additional attributes
Chris@0 52 */
Chris@13 53 public function __construct($name, array $subNodes = [], array $attributes = []) {
Chris@0 54 parent::__construct($attributes);
Chris@13 55 $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
Chris@13 56 $this->byRef = $subNodes['byRef'] ?? false;
Chris@13 57 $this->name = \is_string($name) ? new Node\Identifier($name) : $name;
Chris@13 58 $this->params = $subNodes['params'] ?? [];
Chris@13 59 $returnType = $subNodes['returnType'] ?? null;
Chris@13 60 $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
Chris@13 61 $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : [];
Chris@0 62 }
Chris@0 63
Chris@13 64 public function getSubNodeNames() : array {
Chris@13 65 return ['flags', 'byRef', 'name', 'params', 'returnType', 'stmts'];
Chris@0 66 }
Chris@0 67
Chris@13 68 public function returnsByRef() : bool {
Chris@0 69 return $this->byRef;
Chris@0 70 }
Chris@0 71
Chris@13 72 public function getParams() : array {
Chris@0 73 return $this->params;
Chris@0 74 }
Chris@0 75
Chris@0 76 public function getReturnType() {
Chris@0 77 return $this->returnType;
Chris@0 78 }
Chris@0 79
Chris@0 80 public function getStmts() {
Chris@0 81 return $this->stmts;
Chris@0 82 }
Chris@0 83
Chris@13 84 /**
Chris@13 85 * Whether the method is explicitly or implicitly public.
Chris@13 86 *
Chris@13 87 * @return bool
Chris@13 88 */
Chris@13 89 public function isPublic() : bool {
Chris@0 90 return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
Chris@0 91 || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
Chris@0 92 }
Chris@0 93
Chris@13 94 /**
Chris@13 95 * Whether the method is protected.
Chris@13 96 *
Chris@13 97 * @return bool
Chris@13 98 */
Chris@13 99 public function isProtected() : bool {
Chris@0 100 return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
Chris@0 101 }
Chris@0 102
Chris@13 103 /**
Chris@13 104 * Whether the method is private.
Chris@13 105 *
Chris@13 106 * @return bool
Chris@13 107 */
Chris@13 108 public function isPrivate() : bool {
Chris@0 109 return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
Chris@0 110 }
Chris@0 111
Chris@13 112 /**
Chris@13 113 * Whether the method is abstract.
Chris@13 114 *
Chris@13 115 * @return bool
Chris@13 116 */
Chris@13 117 public function isAbstract() : bool {
Chris@0 118 return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
Chris@0 119 }
Chris@0 120
Chris@13 121 /**
Chris@13 122 * Whether the method is final.
Chris@13 123 *
Chris@13 124 * @return bool
Chris@13 125 */
Chris@13 126 public function isFinal() : bool {
Chris@0 127 return (bool) ($this->flags & Class_::MODIFIER_FINAL);
Chris@0 128 }
Chris@0 129
Chris@13 130 /**
Chris@13 131 * Whether the method is static.
Chris@13 132 *
Chris@13 133 * @return bool
Chris@13 134 */
Chris@13 135 public function isStatic() : bool {
Chris@0 136 return (bool) ($this->flags & Class_::MODIFIER_STATIC);
Chris@0 137 }
Chris@13 138
Chris@13 139 /**
Chris@13 140 * Whether the method is magic.
Chris@13 141 *
Chris@13 142 * @return bool
Chris@13 143 */
Chris@13 144 public function isMagic() : bool {
Chris@13 145 return isset(self::$magicNames[$this->name->toLowerString()]);
Chris@13 146 }
Chris@13 147
Chris@13 148 public function getType() : string {
Chris@13 149 return 'Stmt_ClassMethod';
Chris@13 150 }
Chris@0 151 }