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