Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Builder/Method.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | 1 <?php declare(strict_types=1); |
2 | 2 |
3 namespace PhpParser\Builder; | 3 namespace PhpParser\Builder; |
4 | 4 |
5 use PhpParser; | 5 use PhpParser; |
6 use PhpParser\BuilderHelpers; | |
6 use PhpParser\Node; | 7 use PhpParser\Node; |
7 use PhpParser\Node\Stmt; | 8 use PhpParser\Node\Stmt; |
8 | 9 |
9 class Method extends FunctionLike | 10 class Method extends FunctionLike |
10 { | 11 { |
11 protected $name; | 12 protected $name; |
12 protected $flags = 0; | 13 protected $flags = 0; |
13 | 14 |
14 /** @var array|null */ | 15 /** @var array|null */ |
15 protected $stmts = array(); | 16 protected $stmts = []; |
16 | 17 |
17 /** | 18 /** |
18 * Creates a method builder. | 19 * Creates a method builder. |
19 * | 20 * |
20 * @param string $name Name of the method | 21 * @param string $name Name of the method |
21 */ | 22 */ |
22 public function __construct($name) { | 23 public function __construct(string $name) { |
23 $this->name = $name; | 24 $this->name = $name; |
24 } | 25 } |
25 | 26 |
26 /** | 27 /** |
27 * Makes the method public. | 28 * Makes the method public. |
28 * | 29 * |
29 * @return $this The builder instance (for fluid interface) | 30 * @return $this The builder instance (for fluid interface) |
30 */ | 31 */ |
31 public function makePublic() { | 32 public function makePublic() { |
32 $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC); | 33 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
33 | 34 |
34 return $this; | 35 return $this; |
35 } | 36 } |
36 | 37 |
37 /** | 38 /** |
38 * Makes the method protected. | 39 * Makes the method protected. |
39 * | 40 * |
40 * @return $this The builder instance (for fluid interface) | 41 * @return $this The builder instance (for fluid interface) |
41 */ | 42 */ |
42 public function makeProtected() { | 43 public function makeProtected() { |
43 $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED); | 44 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
44 | 45 |
45 return $this; | 46 return $this; |
46 } | 47 } |
47 | 48 |
48 /** | 49 /** |
49 * Makes the method private. | 50 * Makes the method private. |
50 * | 51 * |
51 * @return $this The builder instance (for fluid interface) | 52 * @return $this The builder instance (for fluid interface) |
52 */ | 53 */ |
53 public function makePrivate() { | 54 public function makePrivate() { |
54 $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE); | 55 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
55 | 56 |
56 return $this; | 57 return $this; |
57 } | 58 } |
58 | 59 |
59 /** | 60 /** |
60 * Makes the method static. | 61 * Makes the method static. |
61 * | 62 * |
62 * @return $this The builder instance (for fluid interface) | 63 * @return $this The builder instance (for fluid interface) |
63 */ | 64 */ |
64 public function makeStatic() { | 65 public function makeStatic() { |
65 $this->setModifier(Stmt\Class_::MODIFIER_STATIC); | 66 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); |
66 | 67 |
67 return $this; | 68 return $this; |
68 } | 69 } |
69 | 70 |
70 /** | 71 /** |
75 public function makeAbstract() { | 76 public function makeAbstract() { |
76 if (!empty($this->stmts)) { | 77 if (!empty($this->stmts)) { |
77 throw new \LogicException('Cannot make method with statements abstract'); | 78 throw new \LogicException('Cannot make method with statements abstract'); |
78 } | 79 } |
79 | 80 |
80 $this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT); | 81 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); |
81 $this->stmts = null; // abstract methods don't have statements | 82 $this->stmts = null; // abstract methods don't have statements |
82 | 83 |
83 return $this; | 84 return $this; |
84 } | 85 } |
85 | 86 |
87 * Makes the method final. | 88 * Makes the method final. |
88 * | 89 * |
89 * @return $this The builder instance (for fluid interface) | 90 * @return $this The builder instance (for fluid interface) |
90 */ | 91 */ |
91 public function makeFinal() { | 92 public function makeFinal() { |
92 $this->setModifier(Stmt\Class_::MODIFIER_FINAL); | 93 $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
93 | 94 |
94 return $this; | 95 return $this; |
95 } | 96 } |
96 | 97 |
97 /** | 98 /** |
104 public function addStmt($stmt) { | 105 public function addStmt($stmt) { |
105 if (null === $this->stmts) { | 106 if (null === $this->stmts) { |
106 throw new \LogicException('Cannot add statements to an abstract method'); | 107 throw new \LogicException('Cannot add statements to an abstract method'); |
107 } | 108 } |
108 | 109 |
109 $this->stmts[] = $this->normalizeNode($stmt); | 110 $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
110 | 111 |
111 return $this; | 112 return $this; |
112 } | 113 } |
113 | 114 |
114 /** | 115 /** |
115 * Returns the built method node. | 116 * Returns the built method node. |
116 * | 117 * |
117 * @return Stmt\ClassMethod The built method node | 118 * @return Stmt\ClassMethod The built method node |
118 */ | 119 */ |
119 public function getNode() { | 120 public function getNode() : Node { |
120 return new Stmt\ClassMethod($this->name, array( | 121 return new Stmt\ClassMethod($this->name, [ |
121 'flags' => $this->flags, | 122 'flags' => $this->flags, |
122 'byRef' => $this->returnByRef, | 123 'byRef' => $this->returnByRef, |
123 'params' => $this->params, | 124 'params' => $this->params, |
124 'returnType' => $this->returnType, | 125 'returnType' => $this->returnType, |
125 'stmts' => $this->stmts, | 126 'stmts' => $this->stmts, |
126 ), $this->attributes); | 127 ], $this->attributes); |
127 } | 128 } |
128 } | 129 } |