Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/Builder/Method.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 5fb285c0d0e3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace PhpParser\Builder; | |
4 | |
5 use PhpParser; | |
6 use PhpParser\Node; | |
7 use PhpParser\Node\Stmt; | |
8 | |
9 class Method extends FunctionLike | |
10 { | |
11 protected $name; | |
12 protected $flags = 0; | |
13 | |
14 /** @var array|null */ | |
15 protected $stmts = array(); | |
16 | |
17 /** | |
18 * Creates a method builder. | |
19 * | |
20 * @param string $name Name of the method | |
21 */ | |
22 public function __construct($name) { | |
23 $this->name = $name; | |
24 } | |
25 | |
26 /** | |
27 * Makes the method public. | |
28 * | |
29 * @return $this The builder instance (for fluid interface) | |
30 */ | |
31 public function makePublic() { | |
32 $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC); | |
33 | |
34 return $this; | |
35 } | |
36 | |
37 /** | |
38 * Makes the method protected. | |
39 * | |
40 * @return $this The builder instance (for fluid interface) | |
41 */ | |
42 public function makeProtected() { | |
43 $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED); | |
44 | |
45 return $this; | |
46 } | |
47 | |
48 /** | |
49 * Makes the method private. | |
50 * | |
51 * @return $this The builder instance (for fluid interface) | |
52 */ | |
53 public function makePrivate() { | |
54 $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE); | |
55 | |
56 return $this; | |
57 } | |
58 | |
59 /** | |
60 * Makes the method static. | |
61 * | |
62 * @return $this The builder instance (for fluid interface) | |
63 */ | |
64 public function makeStatic() { | |
65 $this->setModifier(Stmt\Class_::MODIFIER_STATIC); | |
66 | |
67 return $this; | |
68 } | |
69 | |
70 /** | |
71 * Makes the method abstract. | |
72 * | |
73 * @return $this The builder instance (for fluid interface) | |
74 */ | |
75 public function makeAbstract() { | |
76 if (!empty($this->stmts)) { | |
77 throw new \LogicException('Cannot make method with statements abstract'); | |
78 } | |
79 | |
80 $this->setModifier(Stmt\Class_::MODIFIER_ABSTRACT); | |
81 $this->stmts = null; // abstract methods don't have statements | |
82 | |
83 return $this; | |
84 } | |
85 | |
86 /** | |
87 * Makes the method final. | |
88 * | |
89 * @return $this The builder instance (for fluid interface) | |
90 */ | |
91 public function makeFinal() { | |
92 $this->setModifier(Stmt\Class_::MODIFIER_FINAL); | |
93 | |
94 return $this; | |
95 } | |
96 | |
97 /** | |
98 * Adds a statement. | |
99 * | |
100 * @param Node|PhpParser\Builder $stmt The statement to add | |
101 * | |
102 * @return $this The builder instance (for fluid interface) | |
103 */ | |
104 public function addStmt($stmt) { | |
105 if (null === $this->stmts) { | |
106 throw new \LogicException('Cannot add statements to an abstract method'); | |
107 } | |
108 | |
109 $this->stmts[] = $this->normalizeNode($stmt); | |
110 | |
111 return $this; | |
112 } | |
113 | |
114 /** | |
115 * Returns the built method node. | |
116 * | |
117 * @return Stmt\ClassMethod The built method node | |
118 */ | |
119 public function getNode() { | |
120 return new Stmt\ClassMethod($this->name, array( | |
121 'flags' => $this->flags, | |
122 'byRef' => $this->returnByRef, | |
123 'params' => $this->params, | |
124 'returnType' => $this->returnType, | |
125 'stmts' => $this->stmts, | |
126 ), $this->attributes); | |
127 } | |
128 } |