PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.2
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
betterdocs / includes / Dependencies / PhpParser / Builder / Method.php

Method.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.2, at includes/Dependencies/PhpParser/Builder/Method.php

129 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Dependencies\PhpParser\Builder;
4
5 use WPDeveloper\BetterDocs\Dependencies\PhpParser;
6 use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node;
7 use WPDeveloper\BetterDocs\Dependencies\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|WPDeveloper\BetterDocs\Dependencies\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 }
129