@@ -9,59 +9,59 @@ |
||
9 | 9 | |
10 | 10 | class Function_ extends FunctionLike |
11 | 11 | { |
12 | - protected $name; |
|
13 | - protected $stmts = []; |
|
12 | + protected $name; |
|
13 | + protected $stmts = []; |
|
14 | 14 | |
15 | - /** @var Node\AttributeGroup[] */ |
|
16 | - protected $attributeGroups = []; |
|
15 | + /** @var Node\AttributeGroup[] */ |
|
16 | + protected $attributeGroups = []; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Creates a function builder. |
|
20 | - * |
|
21 | - * @param string $name Name of the function |
|
22 | - */ |
|
23 | - public function __construct(string $name) { |
|
24 | - $this->name = $name; |
|
25 | - } |
|
18 | + /** |
|
19 | + * Creates a function builder. |
|
20 | + * |
|
21 | + * @param string $name Name of the function |
|
22 | + */ |
|
23 | + public function __construct(string $name) { |
|
24 | + $this->name = $name; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Adds a statement. |
|
29 | - * |
|
30 | - * @param Node|PhpParser\Builder $stmt The statement to add |
|
31 | - * |
|
32 | - * @return $this The builder instance (for fluid interface) |
|
33 | - */ |
|
34 | - public function addStmt($stmt) { |
|
35 | - $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
|
27 | + /** |
|
28 | + * Adds a statement. |
|
29 | + * |
|
30 | + * @param Node|PhpParser\Builder $stmt The statement to add |
|
31 | + * |
|
32 | + * @return $this The builder instance (for fluid interface) |
|
33 | + */ |
|
34 | + public function addStmt($stmt) { |
|
35 | + $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
|
36 | 36 | |
37 | - return $this; |
|
38 | - } |
|
37 | + return $this; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Adds an attribute group. |
|
42 | - * |
|
43 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
44 | - * |
|
45 | - * @return $this The builder instance (for fluid interface) |
|
46 | - */ |
|
47 | - public function addAttribute($attribute) { |
|
48 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
40 | + /** |
|
41 | + * Adds an attribute group. |
|
42 | + * |
|
43 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
44 | + * |
|
45 | + * @return $this The builder instance (for fluid interface) |
|
46 | + */ |
|
47 | + public function addAttribute($attribute) { |
|
48 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
49 | 49 | |
50 | - return $this; |
|
51 | - } |
|
50 | + return $this; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the built function node. |
|
55 | - * |
|
56 | - * @return Stmt\Function_ The built function node |
|
57 | - */ |
|
58 | - public function getNode() : Node { |
|
59 | - return new Stmt\Function_($this->name, [ |
|
60 | - 'byRef' => $this->returnByRef, |
|
61 | - 'params' => $this->params, |
|
62 | - 'returnType' => $this->returnType, |
|
63 | - 'stmts' => $this->stmts, |
|
64 | - 'attrGroups' => $this->attributeGroups, |
|
65 | - ], $this->attributes); |
|
66 | - } |
|
53 | + /** |
|
54 | + * Returns the built function node. |
|
55 | + * |
|
56 | + * @return Stmt\Function_ The built function node |
|
57 | + */ |
|
58 | + public function getNode() : Node { |
|
59 | + return new Stmt\Function_($this->name, [ |
|
60 | + 'byRef' => $this->returnByRef, |
|
61 | + 'params' => $this->params, |
|
62 | + 'returnType' => $this->returnType, |
|
63 | + 'stmts' => $this->stmts, |
|
64 | + 'attrGroups' => $this->attributeGroups, |
|
65 | + ], $this->attributes); |
|
66 | + } |
|
67 | 67 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class Function_ extends FunctionLike |
|
11 | -{ |
|
10 | +class Function_ extends FunctionLike { |
|
12 | 11 | protected $name; |
13 | 12 | protected $stmts = []; |
14 | 13 |
@@ -10,84 +10,84 @@ |
||
10 | 10 | |
11 | 11 | class Interface_ extends Declaration |
12 | 12 | { |
13 | - protected $name; |
|
14 | - protected $extends = []; |
|
15 | - protected $constants = []; |
|
16 | - protected $methods = []; |
|
13 | + protected $name; |
|
14 | + protected $extends = []; |
|
15 | + protected $constants = []; |
|
16 | + protected $methods = []; |
|
17 | 17 | |
18 | - /** @var Node\AttributeGroup[] */ |
|
19 | - protected $attributeGroups = []; |
|
18 | + /** @var Node\AttributeGroup[] */ |
|
19 | + protected $attributeGroups = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Creates an interface builder. |
|
23 | - * |
|
24 | - * @param string $name Name of the interface |
|
25 | - */ |
|
26 | - public function __construct(string $name) { |
|
27 | - $this->name = $name; |
|
28 | - } |
|
21 | + /** |
|
22 | + * Creates an interface builder. |
|
23 | + * |
|
24 | + * @param string $name Name of the interface |
|
25 | + */ |
|
26 | + public function __construct(string $name) { |
|
27 | + $this->name = $name; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Extends one or more interfaces. |
|
32 | - * |
|
33 | - * @param Name|string ...$interfaces Names of interfaces to extend |
|
34 | - * |
|
35 | - * @return $this The builder instance (for fluid interface) |
|
36 | - */ |
|
37 | - public function extend(...$interfaces) { |
|
38 | - foreach ($interfaces as $interface) { |
|
39 | - $this->extends[] = BuilderHelpers::normalizeName($interface); |
|
40 | - } |
|
30 | + /** |
|
31 | + * Extends one or more interfaces. |
|
32 | + * |
|
33 | + * @param Name|string ...$interfaces Names of interfaces to extend |
|
34 | + * |
|
35 | + * @return $this The builder instance (for fluid interface) |
|
36 | + */ |
|
37 | + public function extend(...$interfaces) { |
|
38 | + foreach ($interfaces as $interface) { |
|
39 | + $this->extends[] = BuilderHelpers::normalizeName($interface); |
|
40 | + } |
|
41 | 41 | |
42 | - return $this; |
|
43 | - } |
|
42 | + return $this; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Adds a statement. |
|
47 | - * |
|
48 | - * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
49 | - * |
|
50 | - * @return $this The builder instance (for fluid interface) |
|
51 | - */ |
|
52 | - public function addStmt($stmt) { |
|
53 | - $stmt = BuilderHelpers::normalizeNode($stmt); |
|
45 | + /** |
|
46 | + * Adds a statement. |
|
47 | + * |
|
48 | + * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
49 | + * |
|
50 | + * @return $this The builder instance (for fluid interface) |
|
51 | + */ |
|
52 | + public function addStmt($stmt) { |
|
53 | + $stmt = BuilderHelpers::normalizeNode($stmt); |
|
54 | 54 | |
55 | - if ($stmt instanceof Stmt\ClassConst) { |
|
56 | - $this->constants[] = $stmt; |
|
57 | - } elseif ($stmt instanceof Stmt\ClassMethod) { |
|
58 | - // we erase all statements in the body of an interface method |
|
59 | - $stmt->stmts = null; |
|
60 | - $this->methods[] = $stmt; |
|
61 | - } else { |
|
62 | - throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
63 | - } |
|
55 | + if ($stmt instanceof Stmt\ClassConst) { |
|
56 | + $this->constants[] = $stmt; |
|
57 | + } elseif ($stmt instanceof Stmt\ClassMethod) { |
|
58 | + // we erase all statements in the body of an interface method |
|
59 | + $stmt->stmts = null; |
|
60 | + $this->methods[] = $stmt; |
|
61 | + } else { |
|
62 | + throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
63 | + } |
|
64 | 64 | |
65 | - return $this; |
|
66 | - } |
|
65 | + return $this; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Adds an attribute group. |
|
70 | - * |
|
71 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
72 | - * |
|
73 | - * @return $this The builder instance (for fluid interface) |
|
74 | - */ |
|
75 | - public function addAttribute($attribute) { |
|
76 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
68 | + /** |
|
69 | + * Adds an attribute group. |
|
70 | + * |
|
71 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
72 | + * |
|
73 | + * @return $this The builder instance (for fluid interface) |
|
74 | + */ |
|
75 | + public function addAttribute($attribute) { |
|
76 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
77 | 77 | |
78 | - return $this; |
|
79 | - } |
|
78 | + return $this; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Returns the built interface node. |
|
83 | - * |
|
84 | - * @return Stmt\Interface_ The built interface node |
|
85 | - */ |
|
86 | - public function getNode() : PhpParser\Node { |
|
87 | - return new Stmt\Interface_($this->name, [ |
|
88 | - 'extends' => $this->extends, |
|
89 | - 'stmts' => array_merge($this->constants, $this->methods), |
|
90 | - 'attrGroups' => $this->attributeGroups, |
|
91 | - ], $this->attributes); |
|
92 | - } |
|
81 | + /** |
|
82 | + * Returns the built interface node. |
|
83 | + * |
|
84 | + * @return Stmt\Interface_ The built interface node |
|
85 | + */ |
|
86 | + public function getNode() : PhpParser\Node { |
|
87 | + return new Stmt\Interface_($this->name, [ |
|
88 | + 'extends' => $this->extends, |
|
89 | + 'stmts' => array_merge($this->constants, $this->methods), |
|
90 | + 'attrGroups' => $this->attributeGroups, |
|
91 | + ], $this->attributes); |
|
92 | + } |
|
93 | 93 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | use PhpParser\Node\Name; |
9 | 9 | use PhpParser\Node\Stmt; |
10 | 10 | |
11 | -class Interface_ extends Declaration |
|
12 | -{ |
|
11 | +class Interface_ extends Declaration { |
|
13 | 12 | protected $name; |
14 | 13 | protected $extends = []; |
15 | 14 | protected $constants = []; |
@@ -10,137 +10,137 @@ |
||
10 | 10 | |
11 | 11 | class Class_ extends Declaration |
12 | 12 | { |
13 | - protected $name; |
|
14 | - |
|
15 | - protected $extends = null; |
|
16 | - protected $implements = []; |
|
17 | - protected $flags = 0; |
|
18 | - |
|
19 | - protected $uses = []; |
|
20 | - protected $constants = []; |
|
21 | - protected $properties = []; |
|
22 | - protected $methods = []; |
|
23 | - |
|
24 | - /** @var Node\AttributeGroup[] */ |
|
25 | - protected $attributeGroups = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * Creates a class builder. |
|
29 | - * |
|
30 | - * @param string $name Name of the class |
|
31 | - */ |
|
32 | - public function __construct(string $name) { |
|
33 | - $this->name = $name; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Extends a class. |
|
38 | - * |
|
39 | - * @param Name|string $class Name of class to extend |
|
40 | - * |
|
41 | - * @return $this The builder instance (for fluid interface) |
|
42 | - */ |
|
43 | - public function extend($class) { |
|
44 | - $this->extends = BuilderHelpers::normalizeName($class); |
|
45 | - |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Implements one or more interfaces. |
|
51 | - * |
|
52 | - * @param Name|string ...$interfaces Names of interfaces to implement |
|
53 | - * |
|
54 | - * @return $this The builder instance (for fluid interface) |
|
55 | - */ |
|
56 | - public function implement(...$interfaces) { |
|
57 | - foreach ($interfaces as $interface) { |
|
58 | - $this->implements[] = BuilderHelpers::normalizeName($interface); |
|
59 | - } |
|
60 | - |
|
61 | - return $this; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Makes the class abstract. |
|
66 | - * |
|
67 | - * @return $this The builder instance (for fluid interface) |
|
68 | - */ |
|
69 | - public function makeAbstract() { |
|
70 | - $this->flags = BuilderHelpers::addClassModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); |
|
71 | - |
|
72 | - return $this; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Makes the class final. |
|
77 | - * |
|
78 | - * @return $this The builder instance (for fluid interface) |
|
79 | - */ |
|
80 | - public function makeFinal() { |
|
81 | - $this->flags = BuilderHelpers::addClassModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
|
82 | - |
|
83 | - return $this; |
|
84 | - } |
|
85 | - |
|
86 | - public function makeReadonly() { |
|
87 | - $this->flags = BuilderHelpers::addClassModifier($this->flags, Stmt\Class_::MODIFIER_READONLY); |
|
88 | - |
|
89 | - return $this; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Adds a statement. |
|
94 | - * |
|
95 | - * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
96 | - * |
|
97 | - * @return $this The builder instance (for fluid interface) |
|
98 | - */ |
|
99 | - public function addStmt($stmt) { |
|
100 | - $stmt = BuilderHelpers::normalizeNode($stmt); |
|
101 | - |
|
102 | - $targets = [ |
|
103 | - Stmt\TraitUse::class => &$this->uses, |
|
104 | - Stmt\ClassConst::class => &$this->constants, |
|
105 | - Stmt\Property::class => &$this->properties, |
|
106 | - Stmt\ClassMethod::class => &$this->methods, |
|
107 | - ]; |
|
108 | - |
|
109 | - $class = \get_class($stmt); |
|
110 | - if (!isset($targets[$class])) { |
|
111 | - throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
112 | - } |
|
113 | - |
|
114 | - $targets[$class][] = $stmt; |
|
115 | - |
|
116 | - return $this; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Adds an attribute group. |
|
121 | - * |
|
122 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
123 | - * |
|
124 | - * @return $this The builder instance (for fluid interface) |
|
125 | - */ |
|
126 | - public function addAttribute($attribute) { |
|
127 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
128 | - |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Returns the built class node. |
|
134 | - * |
|
135 | - * @return Stmt\Class_ The built class node |
|
136 | - */ |
|
137 | - public function getNode() : PhpParser\Node { |
|
138 | - return new Stmt\Class_($this->name, [ |
|
139 | - 'flags' => $this->flags, |
|
140 | - 'extends' => $this->extends, |
|
141 | - 'implements' => $this->implements, |
|
142 | - 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), |
|
143 | - 'attrGroups' => $this->attributeGroups, |
|
144 | - ], $this->attributes); |
|
145 | - } |
|
13 | + protected $name; |
|
14 | + |
|
15 | + protected $extends = null; |
|
16 | + protected $implements = []; |
|
17 | + protected $flags = 0; |
|
18 | + |
|
19 | + protected $uses = []; |
|
20 | + protected $constants = []; |
|
21 | + protected $properties = []; |
|
22 | + protected $methods = []; |
|
23 | + |
|
24 | + /** @var Node\AttributeGroup[] */ |
|
25 | + protected $attributeGroups = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * Creates a class builder. |
|
29 | + * |
|
30 | + * @param string $name Name of the class |
|
31 | + */ |
|
32 | + public function __construct(string $name) { |
|
33 | + $this->name = $name; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Extends a class. |
|
38 | + * |
|
39 | + * @param Name|string $class Name of class to extend |
|
40 | + * |
|
41 | + * @return $this The builder instance (for fluid interface) |
|
42 | + */ |
|
43 | + public function extend($class) { |
|
44 | + $this->extends = BuilderHelpers::normalizeName($class); |
|
45 | + |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Implements one or more interfaces. |
|
51 | + * |
|
52 | + * @param Name|string ...$interfaces Names of interfaces to implement |
|
53 | + * |
|
54 | + * @return $this The builder instance (for fluid interface) |
|
55 | + */ |
|
56 | + public function implement(...$interfaces) { |
|
57 | + foreach ($interfaces as $interface) { |
|
58 | + $this->implements[] = BuilderHelpers::normalizeName($interface); |
|
59 | + } |
|
60 | + |
|
61 | + return $this; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Makes the class abstract. |
|
66 | + * |
|
67 | + * @return $this The builder instance (for fluid interface) |
|
68 | + */ |
|
69 | + public function makeAbstract() { |
|
70 | + $this->flags = BuilderHelpers::addClassModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); |
|
71 | + |
|
72 | + return $this; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Makes the class final. |
|
77 | + * |
|
78 | + * @return $this The builder instance (for fluid interface) |
|
79 | + */ |
|
80 | + public function makeFinal() { |
|
81 | + $this->flags = BuilderHelpers::addClassModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
|
82 | + |
|
83 | + return $this; |
|
84 | + } |
|
85 | + |
|
86 | + public function makeReadonly() { |
|
87 | + $this->flags = BuilderHelpers::addClassModifier($this->flags, Stmt\Class_::MODIFIER_READONLY); |
|
88 | + |
|
89 | + return $this; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Adds a statement. |
|
94 | + * |
|
95 | + * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
96 | + * |
|
97 | + * @return $this The builder instance (for fluid interface) |
|
98 | + */ |
|
99 | + public function addStmt($stmt) { |
|
100 | + $stmt = BuilderHelpers::normalizeNode($stmt); |
|
101 | + |
|
102 | + $targets = [ |
|
103 | + Stmt\TraitUse::class => &$this->uses, |
|
104 | + Stmt\ClassConst::class => &$this->constants, |
|
105 | + Stmt\Property::class => &$this->properties, |
|
106 | + Stmt\ClassMethod::class => &$this->methods, |
|
107 | + ]; |
|
108 | + |
|
109 | + $class = \get_class($stmt); |
|
110 | + if (!isset($targets[$class])) { |
|
111 | + throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
112 | + } |
|
113 | + |
|
114 | + $targets[$class][] = $stmt; |
|
115 | + |
|
116 | + return $this; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Adds an attribute group. |
|
121 | + * |
|
122 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
123 | + * |
|
124 | + * @return $this The builder instance (for fluid interface) |
|
125 | + */ |
|
126 | + public function addAttribute($attribute) { |
|
127 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
128 | + |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Returns the built class node. |
|
134 | + * |
|
135 | + * @return Stmt\Class_ The built class node |
|
136 | + */ |
|
137 | + public function getNode() : PhpParser\Node { |
|
138 | + return new Stmt\Class_($this->name, [ |
|
139 | + 'flags' => $this->flags, |
|
140 | + 'extends' => $this->extends, |
|
141 | + 'implements' => $this->implements, |
|
142 | + 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), |
|
143 | + 'attrGroups' => $this->attributeGroups, |
|
144 | + ], $this->attributes); |
|
145 | + } |
|
146 | 146 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | use PhpParser\Node\Name; |
9 | 9 | use PhpParser\Node\Stmt; |
10 | 10 | |
11 | -class Class_ extends Declaration |
|
12 | -{ |
|
11 | +class Class_ extends Declaration { |
|
13 | 12 | protected $name; |
14 | 13 | |
15 | 14 | protected $extends = null; |
@@ -7,67 +7,67 @@ |
||
7 | 7 | |
8 | 8 | abstract class FunctionLike extends Declaration |
9 | 9 | { |
10 | - protected $returnByRef = false; |
|
11 | - protected $params = []; |
|
10 | + protected $returnByRef = false; |
|
11 | + protected $params = []; |
|
12 | 12 | |
13 | - /** @var string|Node\Name|Node\NullableType|null */ |
|
14 | - protected $returnType = null; |
|
13 | + /** @var string|Node\Name|Node\NullableType|null */ |
|
14 | + protected $returnType = null; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Make the function return by reference. |
|
18 | - * |
|
19 | - * @return $this The builder instance (for fluid interface) |
|
20 | - */ |
|
21 | - public function makeReturnByRef() { |
|
22 | - $this->returnByRef = true; |
|
16 | + /** |
|
17 | + * Make the function return by reference. |
|
18 | + * |
|
19 | + * @return $this The builder instance (for fluid interface) |
|
20 | + */ |
|
21 | + public function makeReturnByRef() { |
|
22 | + $this->returnByRef = true; |
|
23 | 23 | |
24 | - return $this; |
|
25 | - } |
|
24 | + return $this; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Adds a parameter. |
|
29 | - * |
|
30 | - * @param Node\Param|Param $param The parameter to add |
|
31 | - * |
|
32 | - * @return $this The builder instance (for fluid interface) |
|
33 | - */ |
|
34 | - public function addParam($param) { |
|
35 | - $param = BuilderHelpers::normalizeNode($param); |
|
27 | + /** |
|
28 | + * Adds a parameter. |
|
29 | + * |
|
30 | + * @param Node\Param|Param $param The parameter to add |
|
31 | + * |
|
32 | + * @return $this The builder instance (for fluid interface) |
|
33 | + */ |
|
34 | + public function addParam($param) { |
|
35 | + $param = BuilderHelpers::normalizeNode($param); |
|
36 | 36 | |
37 | - if (!$param instanceof Node\Param) { |
|
38 | - throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); |
|
39 | - } |
|
37 | + if (!$param instanceof Node\Param) { |
|
38 | + throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); |
|
39 | + } |
|
40 | 40 | |
41 | - $this->params[] = $param; |
|
41 | + $this->params[] = $param; |
|
42 | 42 | |
43 | - return $this; |
|
44 | - } |
|
43 | + return $this; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Adds multiple parameters. |
|
48 | - * |
|
49 | - * @param array $params The parameters to add |
|
50 | - * |
|
51 | - * @return $this The builder instance (for fluid interface) |
|
52 | - */ |
|
53 | - public function addParams(array $params) { |
|
54 | - foreach ($params as $param) { |
|
55 | - $this->addParam($param); |
|
56 | - } |
|
46 | + /** |
|
47 | + * Adds multiple parameters. |
|
48 | + * |
|
49 | + * @param array $params The parameters to add |
|
50 | + * |
|
51 | + * @return $this The builder instance (for fluid interface) |
|
52 | + */ |
|
53 | + public function addParams(array $params) { |
|
54 | + foreach ($params as $param) { |
|
55 | + $this->addParam($param); |
|
56 | + } |
|
57 | 57 | |
58 | - return $this; |
|
59 | - } |
|
58 | + return $this; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Sets the return type for PHP 7. |
|
63 | - * |
|
64 | - * @param string|Node\Name|Node\Identifier|Node\ComplexType $type |
|
65 | - * |
|
66 | - * @return $this The builder instance (for fluid interface) |
|
67 | - */ |
|
68 | - public function setReturnType($type) { |
|
69 | - $this->returnType = BuilderHelpers::normalizeType($type); |
|
61 | + /** |
|
62 | + * Sets the return type for PHP 7. |
|
63 | + * |
|
64 | + * @param string|Node\Name|Node\Identifier|Node\ComplexType $type |
|
65 | + * |
|
66 | + * @return $this The builder instance (for fluid interface) |
|
67 | + */ |
|
68 | + public function setReturnType($type) { |
|
69 | + $this->returnType = BuilderHelpers::normalizeType($type); |
|
70 | 70 | |
71 | - return $this; |
|
72 | - } |
|
71 | + return $this; |
|
72 | + } |
|
73 | 73 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\BuilderHelpers; |
6 | 6 | use PhpParser\Node; |
7 | 7 | |
8 | -abstract class FunctionLike extends Declaration |
|
9 | -{ |
|
8 | +abstract class FunctionLike extends Declaration { |
|
10 | 9 | protected $returnByRef = false; |
11 | 10 | protected $params = []; |
12 | 11 |
@@ -8,161 +8,161 @@ |
||
8 | 8 | |
9 | 9 | class Param implements PhpParser\Builder |
10 | 10 | { |
11 | - protected $name; |
|
12 | - |
|
13 | - protected $default = null; |
|
14 | - |
|
15 | - /** @var Node\Identifier|Node\Name|Node\NullableType|null */ |
|
16 | - protected $type = null; |
|
17 | - |
|
18 | - protected $byRef = false; |
|
19 | - |
|
20 | - protected $variadic = false; |
|
21 | - |
|
22 | - protected $flags = 0; |
|
23 | - |
|
24 | - /** @var Node\AttributeGroup[] */ |
|
25 | - protected $attributeGroups = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * Creates a parameter builder. |
|
29 | - * |
|
30 | - * @param string $name Name of the parameter |
|
31 | - */ |
|
32 | - public function __construct(string $name) { |
|
33 | - $this->name = $name; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Sets default value for the parameter. |
|
38 | - * |
|
39 | - * @param mixed $value Default value to use |
|
40 | - * |
|
41 | - * @return $this The builder instance (for fluid interface) |
|
42 | - */ |
|
43 | - public function setDefault($value) { |
|
44 | - $this->default = BuilderHelpers::normalizeValue($value); |
|
45 | - |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Sets type for the parameter. |
|
51 | - * |
|
52 | - * @param string|Node\Name|Node\Identifier|Node\ComplexType $type Parameter type |
|
53 | - * |
|
54 | - * @return $this The builder instance (for fluid interface) |
|
55 | - */ |
|
56 | - public function setType($type) { |
|
57 | - $this->type = BuilderHelpers::normalizeType($type); |
|
58 | - if ($this->type == 'void') { |
|
59 | - throw new \LogicException('Parameter type cannot be void'); |
|
60 | - } |
|
61 | - |
|
62 | - return $this; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Sets type for the parameter. |
|
67 | - * |
|
68 | - * @param string|Node\Name|Node\Identifier|Node\ComplexType $type Parameter type |
|
69 | - * |
|
70 | - * @return $this The builder instance (for fluid interface) |
|
71 | - * |
|
72 | - * @deprecated Use setType() instead |
|
73 | - */ |
|
74 | - public function setTypeHint($type) { |
|
75 | - return $this->setType($type); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Make the parameter accept the value by reference. |
|
80 | - * |
|
81 | - * @return $this The builder instance (for fluid interface) |
|
82 | - */ |
|
83 | - public function makeByRef() { |
|
84 | - $this->byRef = true; |
|
85 | - |
|
86 | - return $this; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Make the parameter variadic |
|
91 | - * |
|
92 | - * @return $this The builder instance (for fluid interface) |
|
93 | - */ |
|
94 | - public function makeVariadic() { |
|
95 | - $this->variadic = true; |
|
96 | - |
|
97 | - return $this; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Makes the (promoted) parameter public. |
|
102 | - * |
|
103 | - * @return $this The builder instance (for fluid interface) |
|
104 | - */ |
|
105 | - public function makePublic() { |
|
106 | - $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PUBLIC); |
|
107 | - |
|
108 | - return $this; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Makes the (promoted) parameter protected. |
|
113 | - * |
|
114 | - * @return $this The builder instance (for fluid interface) |
|
115 | - */ |
|
116 | - public function makeProtected() { |
|
117 | - $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PROTECTED); |
|
118 | - |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Makes the (promoted) parameter private. |
|
124 | - * |
|
125 | - * @return $this The builder instance (for fluid interface) |
|
126 | - */ |
|
127 | - public function makePrivate() { |
|
128 | - $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PRIVATE); |
|
129 | - |
|
130 | - return $this; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Makes the (promoted) parameter readonly. |
|
135 | - * |
|
136 | - * @return $this The builder instance (for fluid interface) |
|
137 | - */ |
|
138 | - public function makeReadonly() { |
|
139 | - $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_READONLY); |
|
140 | - |
|
141 | - return $this; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Adds an attribute group. |
|
146 | - * |
|
147 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
148 | - * |
|
149 | - * @return $this The builder instance (for fluid interface) |
|
150 | - */ |
|
151 | - public function addAttribute($attribute) { |
|
152 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
153 | - |
|
154 | - return $this; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns the built parameter node. |
|
159 | - * |
|
160 | - * @return Node\Param The built parameter node |
|
161 | - */ |
|
162 | - public function getNode() : Node { |
|
163 | - return new Node\Param( |
|
164 | - new Node\Expr\Variable($this->name), |
|
165 | - $this->default, $this->type, $this->byRef, $this->variadic, [], $this->flags, $this->attributeGroups |
|
166 | - ); |
|
167 | - } |
|
11 | + protected $name; |
|
12 | + |
|
13 | + protected $default = null; |
|
14 | + |
|
15 | + /** @var Node\Identifier|Node\Name|Node\NullableType|null */ |
|
16 | + protected $type = null; |
|
17 | + |
|
18 | + protected $byRef = false; |
|
19 | + |
|
20 | + protected $variadic = false; |
|
21 | + |
|
22 | + protected $flags = 0; |
|
23 | + |
|
24 | + /** @var Node\AttributeGroup[] */ |
|
25 | + protected $attributeGroups = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * Creates a parameter builder. |
|
29 | + * |
|
30 | + * @param string $name Name of the parameter |
|
31 | + */ |
|
32 | + public function __construct(string $name) { |
|
33 | + $this->name = $name; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Sets default value for the parameter. |
|
38 | + * |
|
39 | + * @param mixed $value Default value to use |
|
40 | + * |
|
41 | + * @return $this The builder instance (for fluid interface) |
|
42 | + */ |
|
43 | + public function setDefault($value) { |
|
44 | + $this->default = BuilderHelpers::normalizeValue($value); |
|
45 | + |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Sets type for the parameter. |
|
51 | + * |
|
52 | + * @param string|Node\Name|Node\Identifier|Node\ComplexType $type Parameter type |
|
53 | + * |
|
54 | + * @return $this The builder instance (for fluid interface) |
|
55 | + */ |
|
56 | + public function setType($type) { |
|
57 | + $this->type = BuilderHelpers::normalizeType($type); |
|
58 | + if ($this->type == 'void') { |
|
59 | + throw new \LogicException('Parameter type cannot be void'); |
|
60 | + } |
|
61 | + |
|
62 | + return $this; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Sets type for the parameter. |
|
67 | + * |
|
68 | + * @param string|Node\Name|Node\Identifier|Node\ComplexType $type Parameter type |
|
69 | + * |
|
70 | + * @return $this The builder instance (for fluid interface) |
|
71 | + * |
|
72 | + * @deprecated Use setType() instead |
|
73 | + */ |
|
74 | + public function setTypeHint($type) { |
|
75 | + return $this->setType($type); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Make the parameter accept the value by reference. |
|
80 | + * |
|
81 | + * @return $this The builder instance (for fluid interface) |
|
82 | + */ |
|
83 | + public function makeByRef() { |
|
84 | + $this->byRef = true; |
|
85 | + |
|
86 | + return $this; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Make the parameter variadic |
|
91 | + * |
|
92 | + * @return $this The builder instance (for fluid interface) |
|
93 | + */ |
|
94 | + public function makeVariadic() { |
|
95 | + $this->variadic = true; |
|
96 | + |
|
97 | + return $this; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Makes the (promoted) parameter public. |
|
102 | + * |
|
103 | + * @return $this The builder instance (for fluid interface) |
|
104 | + */ |
|
105 | + public function makePublic() { |
|
106 | + $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PUBLIC); |
|
107 | + |
|
108 | + return $this; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Makes the (promoted) parameter protected. |
|
113 | + * |
|
114 | + * @return $this The builder instance (for fluid interface) |
|
115 | + */ |
|
116 | + public function makeProtected() { |
|
117 | + $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PROTECTED); |
|
118 | + |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Makes the (promoted) parameter private. |
|
124 | + * |
|
125 | + * @return $this The builder instance (for fluid interface) |
|
126 | + */ |
|
127 | + public function makePrivate() { |
|
128 | + $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_PRIVATE); |
|
129 | + |
|
130 | + return $this; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Makes the (promoted) parameter readonly. |
|
135 | + * |
|
136 | + * @return $this The builder instance (for fluid interface) |
|
137 | + */ |
|
138 | + public function makeReadonly() { |
|
139 | + $this->flags = BuilderHelpers::addModifier($this->flags, Node\Stmt\Class_::MODIFIER_READONLY); |
|
140 | + |
|
141 | + return $this; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Adds an attribute group. |
|
146 | + * |
|
147 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
148 | + * |
|
149 | + * @return $this The builder instance (for fluid interface) |
|
150 | + */ |
|
151 | + public function addAttribute($attribute) { |
|
152 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
153 | + |
|
154 | + return $this; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns the built parameter node. |
|
159 | + * |
|
160 | + * @return Node\Param The built parameter node |
|
161 | + */ |
|
162 | + public function getNode() : Node { |
|
163 | + return new Node\Param( |
|
164 | + new Node\Expr\Variable($this->name), |
|
165 | + $this->default, $this->type, $this->byRef, $this->variadic, [], $this->flags, $this->attributeGroups |
|
166 | + ); |
|
167 | + } |
|
168 | 168 | } |
@@ -9,140 +9,140 @@ |
||
9 | 9 | |
10 | 10 | class TraitUseAdaptation implements Builder |
11 | 11 | { |
12 | - const TYPE_UNDEFINED = 0; |
|
13 | - const TYPE_ALIAS = 1; |
|
14 | - const TYPE_PRECEDENCE = 2; |
|
15 | - |
|
16 | - /** @var int Type of building adaptation */ |
|
17 | - protected $type; |
|
18 | - |
|
19 | - protected $trait; |
|
20 | - protected $method; |
|
21 | - |
|
22 | - protected $modifier = null; |
|
23 | - protected $alias = null; |
|
24 | - |
|
25 | - protected $insteadof = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * Creates a trait use adaptation builder. |
|
29 | - * |
|
30 | - * @param Node\Name|string|null $trait Name of adaptated trait |
|
31 | - * @param Node\Identifier|string $method Name of adaptated method |
|
32 | - */ |
|
33 | - public function __construct($trait, $method) { |
|
34 | - $this->type = self::TYPE_UNDEFINED; |
|
35 | - |
|
36 | - $this->trait = is_null($trait)? null: BuilderHelpers::normalizeName($trait); |
|
37 | - $this->method = BuilderHelpers::normalizeIdentifier($method); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Sets alias of method. |
|
42 | - * |
|
43 | - * @param Node\Identifier|string $alias Alias for adaptated method |
|
44 | - * |
|
45 | - * @return $this The builder instance (for fluid interface) |
|
46 | - */ |
|
47 | - public function as($alias) { |
|
48 | - if ($this->type === self::TYPE_UNDEFINED) { |
|
49 | - $this->type = self::TYPE_ALIAS; |
|
50 | - } |
|
51 | - |
|
52 | - if ($this->type !== self::TYPE_ALIAS) { |
|
53 | - throw new \LogicException('Cannot set alias for not alias adaptation buider'); |
|
54 | - } |
|
55 | - |
|
56 | - $this->alias = $alias; |
|
57 | - return $this; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets adaptated method public. |
|
62 | - * |
|
63 | - * @return $this The builder instance (for fluid interface) |
|
64 | - */ |
|
65 | - public function makePublic() { |
|
66 | - $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC); |
|
67 | - return $this; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Sets adaptated method protected. |
|
72 | - * |
|
73 | - * @return $this The builder instance (for fluid interface) |
|
74 | - */ |
|
75 | - public function makeProtected() { |
|
76 | - $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED); |
|
77 | - return $this; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets adaptated method private. |
|
82 | - * |
|
83 | - * @return $this The builder instance (for fluid interface) |
|
84 | - */ |
|
85 | - public function makePrivate() { |
|
86 | - $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE); |
|
87 | - return $this; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Adds overwritten traits. |
|
92 | - * |
|
93 | - * @param Node\Name|string ...$traits Traits for overwrite |
|
94 | - * |
|
95 | - * @return $this The builder instance (for fluid interface) |
|
96 | - */ |
|
97 | - public function insteadof(...$traits) { |
|
98 | - if ($this->type === self::TYPE_UNDEFINED) { |
|
99 | - if (is_null($this->trait)) { |
|
100 | - throw new \LogicException('Precedence adaptation must have trait'); |
|
101 | - } |
|
102 | - |
|
103 | - $this->type = self::TYPE_PRECEDENCE; |
|
104 | - } |
|
105 | - |
|
106 | - if ($this->type !== self::TYPE_PRECEDENCE) { |
|
107 | - throw new \LogicException('Cannot add overwritten traits for not precedence adaptation buider'); |
|
108 | - } |
|
109 | - |
|
110 | - foreach ($traits as $trait) { |
|
111 | - $this->insteadof[] = BuilderHelpers::normalizeName($trait); |
|
112 | - } |
|
113 | - |
|
114 | - return $this; |
|
115 | - } |
|
116 | - |
|
117 | - protected function setModifier(int $modifier) { |
|
118 | - if ($this->type === self::TYPE_UNDEFINED) { |
|
119 | - $this->type = self::TYPE_ALIAS; |
|
120 | - } |
|
121 | - |
|
122 | - if ($this->type !== self::TYPE_ALIAS) { |
|
123 | - throw new \LogicException('Cannot set access modifier for not alias adaptation buider'); |
|
124 | - } |
|
125 | - |
|
126 | - if (is_null($this->modifier)) { |
|
127 | - $this->modifier = $modifier; |
|
128 | - } else { |
|
129 | - throw new \LogicException('Multiple access type modifiers are not allowed'); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the built node. |
|
135 | - * |
|
136 | - * @return Node The built node |
|
137 | - */ |
|
138 | - public function getNode() : Node { |
|
139 | - switch ($this->type) { |
|
140 | - case self::TYPE_ALIAS: |
|
141 | - return new Stmt\TraitUseAdaptation\Alias($this->trait, $this->method, $this->modifier, $this->alias); |
|
142 | - case self::TYPE_PRECEDENCE: |
|
143 | - return new Stmt\TraitUseAdaptation\Precedence($this->trait, $this->method, $this->insteadof); |
|
144 | - default: |
|
145 | - throw new \LogicException('Type of adaptation is not defined'); |
|
146 | - } |
|
147 | - } |
|
12 | + const TYPE_UNDEFINED = 0; |
|
13 | + const TYPE_ALIAS = 1; |
|
14 | + const TYPE_PRECEDENCE = 2; |
|
15 | + |
|
16 | + /** @var int Type of building adaptation */ |
|
17 | + protected $type; |
|
18 | + |
|
19 | + protected $trait; |
|
20 | + protected $method; |
|
21 | + |
|
22 | + protected $modifier = null; |
|
23 | + protected $alias = null; |
|
24 | + |
|
25 | + protected $insteadof = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * Creates a trait use adaptation builder. |
|
29 | + * |
|
30 | + * @param Node\Name|string|null $trait Name of adaptated trait |
|
31 | + * @param Node\Identifier|string $method Name of adaptated method |
|
32 | + */ |
|
33 | + public function __construct($trait, $method) { |
|
34 | + $this->type = self::TYPE_UNDEFINED; |
|
35 | + |
|
36 | + $this->trait = is_null($trait)? null: BuilderHelpers::normalizeName($trait); |
|
37 | + $this->method = BuilderHelpers::normalizeIdentifier($method); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Sets alias of method. |
|
42 | + * |
|
43 | + * @param Node\Identifier|string $alias Alias for adaptated method |
|
44 | + * |
|
45 | + * @return $this The builder instance (for fluid interface) |
|
46 | + */ |
|
47 | + public function as($alias) { |
|
48 | + if ($this->type === self::TYPE_UNDEFINED) { |
|
49 | + $this->type = self::TYPE_ALIAS; |
|
50 | + } |
|
51 | + |
|
52 | + if ($this->type !== self::TYPE_ALIAS) { |
|
53 | + throw new \LogicException('Cannot set alias for not alias adaptation buider'); |
|
54 | + } |
|
55 | + |
|
56 | + $this->alias = $alias; |
|
57 | + return $this; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets adaptated method public. |
|
62 | + * |
|
63 | + * @return $this The builder instance (for fluid interface) |
|
64 | + */ |
|
65 | + public function makePublic() { |
|
66 | + $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC); |
|
67 | + return $this; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Sets adaptated method protected. |
|
72 | + * |
|
73 | + * @return $this The builder instance (for fluid interface) |
|
74 | + */ |
|
75 | + public function makeProtected() { |
|
76 | + $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED); |
|
77 | + return $this; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets adaptated method private. |
|
82 | + * |
|
83 | + * @return $this The builder instance (for fluid interface) |
|
84 | + */ |
|
85 | + public function makePrivate() { |
|
86 | + $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE); |
|
87 | + return $this; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Adds overwritten traits. |
|
92 | + * |
|
93 | + * @param Node\Name|string ...$traits Traits for overwrite |
|
94 | + * |
|
95 | + * @return $this The builder instance (for fluid interface) |
|
96 | + */ |
|
97 | + public function insteadof(...$traits) { |
|
98 | + if ($this->type === self::TYPE_UNDEFINED) { |
|
99 | + if (is_null($this->trait)) { |
|
100 | + throw new \LogicException('Precedence adaptation must have trait'); |
|
101 | + } |
|
102 | + |
|
103 | + $this->type = self::TYPE_PRECEDENCE; |
|
104 | + } |
|
105 | + |
|
106 | + if ($this->type !== self::TYPE_PRECEDENCE) { |
|
107 | + throw new \LogicException('Cannot add overwritten traits for not precedence adaptation buider'); |
|
108 | + } |
|
109 | + |
|
110 | + foreach ($traits as $trait) { |
|
111 | + $this->insteadof[] = BuilderHelpers::normalizeName($trait); |
|
112 | + } |
|
113 | + |
|
114 | + return $this; |
|
115 | + } |
|
116 | + |
|
117 | + protected function setModifier(int $modifier) { |
|
118 | + if ($this->type === self::TYPE_UNDEFINED) { |
|
119 | + $this->type = self::TYPE_ALIAS; |
|
120 | + } |
|
121 | + |
|
122 | + if ($this->type !== self::TYPE_ALIAS) { |
|
123 | + throw new \LogicException('Cannot set access modifier for not alias adaptation buider'); |
|
124 | + } |
|
125 | + |
|
126 | + if (is_null($this->modifier)) { |
|
127 | + $this->modifier = $modifier; |
|
128 | + } else { |
|
129 | + throw new \LogicException('Multiple access type modifiers are not allowed'); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the built node. |
|
135 | + * |
|
136 | + * @return Node The built node |
|
137 | + */ |
|
138 | + public function getNode() : Node { |
|
139 | + switch ($this->type) { |
|
140 | + case self::TYPE_ALIAS: |
|
141 | + return new Stmt\TraitUseAdaptation\Alias($this->trait, $this->method, $this->modifier, $this->alias); |
|
142 | + case self::TYPE_PRECEDENCE: |
|
143 | + return new Stmt\TraitUseAdaptation\Precedence($this->trait, $this->method, $this->insteadof); |
|
144 | + default: |
|
145 | + throw new \LogicException('Type of adaptation is not defined'); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | public function __construct($trait, $method) { |
34 | 34 | $this->type = self::TYPE_UNDEFINED; |
35 | 35 | |
36 | - $this->trait = is_null($trait)? null: BuilderHelpers::normalizeName($trait); |
|
36 | + $this->trait = is_null($trait) ? null: BuilderHelpers::normalizeName($trait); |
|
37 | 37 | $this->method = BuilderHelpers::normalizeIdentifier($method); |
38 | 38 | } |
39 | 39 |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class TraitUseAdaptation implements Builder |
|
11 | -{ |
|
10 | +class TraitUseAdaptation implements Builder { |
|
12 | 11 | const TYPE_UNDEFINED = 0; |
13 | 12 | const TYPE_ALIAS = 1; |
14 | 13 | const TYPE_PRECEDENCE = 2; |
@@ -11,107 +11,107 @@ |
||
11 | 11 | |
12 | 12 | class Enum_ extends Declaration |
13 | 13 | { |
14 | - protected $name; |
|
15 | - protected $scalarType = null; |
|
16 | - |
|
17 | - protected $implements = []; |
|
18 | - |
|
19 | - protected $uses = []; |
|
20 | - protected $enumCases = []; |
|
21 | - protected $constants = []; |
|
22 | - protected $methods = []; |
|
23 | - |
|
24 | - /** @var Node\AttributeGroup[] */ |
|
25 | - protected $attributeGroups = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * Creates an enum builder. |
|
29 | - * |
|
30 | - * @param string $name Name of the enum |
|
31 | - */ |
|
32 | - public function __construct(string $name) { |
|
33 | - $this->name = $name; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Sets the scalar type. |
|
38 | - * |
|
39 | - * @param string|Identifier $type |
|
40 | - * |
|
41 | - * @return $this |
|
42 | - */ |
|
43 | - public function setScalarType($scalarType) { |
|
44 | - $this->scalarType = BuilderHelpers::normalizeType($scalarType); |
|
45 | - |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Implements one or more interfaces. |
|
51 | - * |
|
52 | - * @param Name|string ...$interfaces Names of interfaces to implement |
|
53 | - * |
|
54 | - * @return $this The builder instance (for fluid interface) |
|
55 | - */ |
|
56 | - public function implement(...$interfaces) { |
|
57 | - foreach ($interfaces as $interface) { |
|
58 | - $this->implements[] = BuilderHelpers::normalizeName($interface); |
|
59 | - } |
|
60 | - |
|
61 | - return $this; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Adds a statement. |
|
66 | - * |
|
67 | - * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
68 | - * |
|
69 | - * @return $this The builder instance (for fluid interface) |
|
70 | - */ |
|
71 | - public function addStmt($stmt) { |
|
72 | - $stmt = BuilderHelpers::normalizeNode($stmt); |
|
73 | - |
|
74 | - $targets = [ |
|
75 | - Stmt\TraitUse::class => &$this->uses, |
|
76 | - Stmt\EnumCase::class => &$this->enumCases, |
|
77 | - Stmt\ClassConst::class => &$this->constants, |
|
78 | - Stmt\ClassMethod::class => &$this->methods, |
|
79 | - ]; |
|
80 | - |
|
81 | - $class = \get_class($stmt); |
|
82 | - if (!isset($targets[$class])) { |
|
83 | - throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
84 | - } |
|
85 | - |
|
86 | - $targets[$class][] = $stmt; |
|
87 | - |
|
88 | - return $this; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Adds an attribute group. |
|
93 | - * |
|
94 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
95 | - * |
|
96 | - * @return $this The builder instance (for fluid interface) |
|
97 | - */ |
|
98 | - public function addAttribute($attribute) { |
|
99 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
100 | - |
|
101 | - return $this; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns the built class node. |
|
106 | - * |
|
107 | - * @return Stmt\Enum_ The built enum node |
|
108 | - */ |
|
109 | - public function getNode() : PhpParser\Node { |
|
110 | - return new Stmt\Enum_($this->name, [ |
|
111 | - 'scalarType' => $this->scalarType, |
|
112 | - 'implements' => $this->implements, |
|
113 | - 'stmts' => array_merge($this->uses, $this->enumCases, $this->constants, $this->methods), |
|
114 | - 'attrGroups' => $this->attributeGroups, |
|
115 | - ], $this->attributes); |
|
116 | - } |
|
14 | + protected $name; |
|
15 | + protected $scalarType = null; |
|
16 | + |
|
17 | + protected $implements = []; |
|
18 | + |
|
19 | + protected $uses = []; |
|
20 | + protected $enumCases = []; |
|
21 | + protected $constants = []; |
|
22 | + protected $methods = []; |
|
23 | + |
|
24 | + /** @var Node\AttributeGroup[] */ |
|
25 | + protected $attributeGroups = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * Creates an enum builder. |
|
29 | + * |
|
30 | + * @param string $name Name of the enum |
|
31 | + */ |
|
32 | + public function __construct(string $name) { |
|
33 | + $this->name = $name; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Sets the scalar type. |
|
38 | + * |
|
39 | + * @param string|Identifier $type |
|
40 | + * |
|
41 | + * @return $this |
|
42 | + */ |
|
43 | + public function setScalarType($scalarType) { |
|
44 | + $this->scalarType = BuilderHelpers::normalizeType($scalarType); |
|
45 | + |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Implements one or more interfaces. |
|
51 | + * |
|
52 | + * @param Name|string ...$interfaces Names of interfaces to implement |
|
53 | + * |
|
54 | + * @return $this The builder instance (for fluid interface) |
|
55 | + */ |
|
56 | + public function implement(...$interfaces) { |
|
57 | + foreach ($interfaces as $interface) { |
|
58 | + $this->implements[] = BuilderHelpers::normalizeName($interface); |
|
59 | + } |
|
60 | + |
|
61 | + return $this; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Adds a statement. |
|
66 | + * |
|
67 | + * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
68 | + * |
|
69 | + * @return $this The builder instance (for fluid interface) |
|
70 | + */ |
|
71 | + public function addStmt($stmt) { |
|
72 | + $stmt = BuilderHelpers::normalizeNode($stmt); |
|
73 | + |
|
74 | + $targets = [ |
|
75 | + Stmt\TraitUse::class => &$this->uses, |
|
76 | + Stmt\EnumCase::class => &$this->enumCases, |
|
77 | + Stmt\ClassConst::class => &$this->constants, |
|
78 | + Stmt\ClassMethod::class => &$this->methods, |
|
79 | + ]; |
|
80 | + |
|
81 | + $class = \get_class($stmt); |
|
82 | + if (!isset($targets[$class])) { |
|
83 | + throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
84 | + } |
|
85 | + |
|
86 | + $targets[$class][] = $stmt; |
|
87 | + |
|
88 | + return $this; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Adds an attribute group. |
|
93 | + * |
|
94 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
95 | + * |
|
96 | + * @return $this The builder instance (for fluid interface) |
|
97 | + */ |
|
98 | + public function addAttribute($attribute) { |
|
99 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
100 | + |
|
101 | + return $this; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns the built class node. |
|
106 | + * |
|
107 | + * @return Stmt\Enum_ The built enum node |
|
108 | + */ |
|
109 | + public function getNode() : PhpParser\Node { |
|
110 | + return new Stmt\Enum_($this->name, [ |
|
111 | + 'scalarType' => $this->scalarType, |
|
112 | + 'implements' => $this->implements, |
|
113 | + 'stmts' => array_merge($this->uses, $this->enumCases, $this->constants, $this->methods), |
|
114 | + 'attrGroups' => $this->attributeGroups, |
|
115 | + ], $this->attributes); |
|
116 | + } |
|
117 | 117 | } |
@@ -9,8 +9,7 @@ |
||
9 | 9 | use PhpParser\Node\Name; |
10 | 10 | use PhpParser\Node\Stmt; |
11 | 11 | |
12 | -class Enum_ extends Declaration |
|
13 | -{ |
|
12 | +class Enum_ extends Declaration { |
|
14 | 13 | protected $name; |
15 | 14 | protected $scalarType = null; |
16 | 15 |
@@ -7,37 +7,37 @@ |
||
7 | 7 | |
8 | 8 | abstract class Declaration implements PhpParser\Builder |
9 | 9 | { |
10 | - protected $attributes = []; |
|
11 | - |
|
12 | - abstract public function addStmt($stmt); |
|
13 | - |
|
14 | - /** |
|
15 | - * Adds multiple statements. |
|
16 | - * |
|
17 | - * @param array $stmts The statements to add |
|
18 | - * |
|
19 | - * @return $this The builder instance (for fluid interface) |
|
20 | - */ |
|
21 | - public function addStmts(array $stmts) { |
|
22 | - foreach ($stmts as $stmt) { |
|
23 | - $this->addStmt($stmt); |
|
24 | - } |
|
25 | - |
|
26 | - return $this; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Sets doc comment for the declaration. |
|
31 | - * |
|
32 | - * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
33 | - * |
|
34 | - * @return $this The builder instance (for fluid interface) |
|
35 | - */ |
|
36 | - public function setDocComment($docComment) { |
|
37 | - $this->attributes['comments'] = [ |
|
38 | - BuilderHelpers::normalizeDocComment($docComment) |
|
39 | - ]; |
|
40 | - |
|
41 | - return $this; |
|
42 | - } |
|
10 | + protected $attributes = []; |
|
11 | + |
|
12 | + abstract public function addStmt($stmt); |
|
13 | + |
|
14 | + /** |
|
15 | + * Adds multiple statements. |
|
16 | + * |
|
17 | + * @param array $stmts The statements to add |
|
18 | + * |
|
19 | + * @return $this The builder instance (for fluid interface) |
|
20 | + */ |
|
21 | + public function addStmts(array $stmts) { |
|
22 | + foreach ($stmts as $stmt) { |
|
23 | + $this->addStmt($stmt); |
|
24 | + } |
|
25 | + |
|
26 | + return $this; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Sets doc comment for the declaration. |
|
31 | + * |
|
32 | + * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
33 | + * |
|
34 | + * @return $this The builder instance (for fluid interface) |
|
35 | + */ |
|
36 | + public function setDocComment($docComment) { |
|
37 | + $this->attributes['comments'] = [ |
|
38 | + BuilderHelpers::normalizeDocComment($docComment) |
|
39 | + ]; |
|
40 | + |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | } |
@@ -9,138 +9,138 @@ |
||
9 | 9 | |
10 | 10 | class Method extends FunctionLike |
11 | 11 | { |
12 | - protected $name; |
|
13 | - protected $flags = 0; |
|
14 | - |
|
15 | - /** @var array|null */ |
|
16 | - protected $stmts = []; |
|
17 | - |
|
18 | - /** @var Node\AttributeGroup[] */ |
|
19 | - protected $attributeGroups = []; |
|
20 | - |
|
21 | - /** |
|
22 | - * Creates a method builder. |
|
23 | - * |
|
24 | - * @param string $name Name of the method |
|
25 | - */ |
|
26 | - public function __construct(string $name) { |
|
27 | - $this->name = $name; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Makes the method public. |
|
32 | - * |
|
33 | - * @return $this The builder instance (for fluid interface) |
|
34 | - */ |
|
35 | - public function makePublic() { |
|
36 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
|
37 | - |
|
38 | - return $this; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Makes the method protected. |
|
43 | - * |
|
44 | - * @return $this The builder instance (for fluid interface) |
|
45 | - */ |
|
46 | - public function makeProtected() { |
|
47 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
|
48 | - |
|
49 | - return $this; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Makes the method private. |
|
54 | - * |
|
55 | - * @return $this The builder instance (for fluid interface) |
|
56 | - */ |
|
57 | - public function makePrivate() { |
|
58 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
|
59 | - |
|
60 | - return $this; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Makes the method static. |
|
65 | - * |
|
66 | - * @return $this The builder instance (for fluid interface) |
|
67 | - */ |
|
68 | - public function makeStatic() { |
|
69 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); |
|
70 | - |
|
71 | - return $this; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Makes the method abstract. |
|
76 | - * |
|
77 | - * @return $this The builder instance (for fluid interface) |
|
78 | - */ |
|
79 | - public function makeAbstract() { |
|
80 | - if (!empty($this->stmts)) { |
|
81 | - throw new \LogicException('Cannot make method with statements abstract'); |
|
82 | - } |
|
83 | - |
|
84 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); |
|
85 | - $this->stmts = null; // abstract methods don't have statements |
|
86 | - |
|
87 | - return $this; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Makes the method final. |
|
92 | - * |
|
93 | - * @return $this The builder instance (for fluid interface) |
|
94 | - */ |
|
95 | - public function makeFinal() { |
|
96 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
|
97 | - |
|
98 | - return $this; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Adds a statement. |
|
103 | - * |
|
104 | - * @param Node|PhpParser\Builder $stmt The statement to add |
|
105 | - * |
|
106 | - * @return $this The builder instance (for fluid interface) |
|
107 | - */ |
|
108 | - public function addStmt($stmt) { |
|
109 | - if (null === $this->stmts) { |
|
110 | - throw new \LogicException('Cannot add statements to an abstract method'); |
|
111 | - } |
|
112 | - |
|
113 | - $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
|
114 | - |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Adds an attribute group. |
|
120 | - * |
|
121 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
122 | - * |
|
123 | - * @return $this The builder instance (for fluid interface) |
|
124 | - */ |
|
125 | - public function addAttribute($attribute) { |
|
126 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
127 | - |
|
128 | - return $this; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Returns the built method node. |
|
133 | - * |
|
134 | - * @return Stmt\ClassMethod The built method node |
|
135 | - */ |
|
136 | - public function getNode() : Node { |
|
137 | - return new Stmt\ClassMethod($this->name, [ |
|
138 | - 'flags' => $this->flags, |
|
139 | - 'byRef' => $this->returnByRef, |
|
140 | - 'params' => $this->params, |
|
141 | - 'returnType' => $this->returnType, |
|
142 | - 'stmts' => $this->stmts, |
|
143 | - 'attrGroups' => $this->attributeGroups, |
|
144 | - ], $this->attributes); |
|
145 | - } |
|
12 | + protected $name; |
|
13 | + protected $flags = 0; |
|
14 | + |
|
15 | + /** @var array|null */ |
|
16 | + protected $stmts = []; |
|
17 | + |
|
18 | + /** @var Node\AttributeGroup[] */ |
|
19 | + protected $attributeGroups = []; |
|
20 | + |
|
21 | + /** |
|
22 | + * Creates a method builder. |
|
23 | + * |
|
24 | + * @param string $name Name of the method |
|
25 | + */ |
|
26 | + public function __construct(string $name) { |
|
27 | + $this->name = $name; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Makes the method public. |
|
32 | + * |
|
33 | + * @return $this The builder instance (for fluid interface) |
|
34 | + */ |
|
35 | + public function makePublic() { |
|
36 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
|
37 | + |
|
38 | + return $this; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Makes the method protected. |
|
43 | + * |
|
44 | + * @return $this The builder instance (for fluid interface) |
|
45 | + */ |
|
46 | + public function makeProtected() { |
|
47 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
|
48 | + |
|
49 | + return $this; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Makes the method private. |
|
54 | + * |
|
55 | + * @return $this The builder instance (for fluid interface) |
|
56 | + */ |
|
57 | + public function makePrivate() { |
|
58 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
|
59 | + |
|
60 | + return $this; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Makes the method static. |
|
65 | + * |
|
66 | + * @return $this The builder instance (for fluid interface) |
|
67 | + */ |
|
68 | + public function makeStatic() { |
|
69 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); |
|
70 | + |
|
71 | + return $this; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Makes the method abstract. |
|
76 | + * |
|
77 | + * @return $this The builder instance (for fluid interface) |
|
78 | + */ |
|
79 | + public function makeAbstract() { |
|
80 | + if (!empty($this->stmts)) { |
|
81 | + throw new \LogicException('Cannot make method with statements abstract'); |
|
82 | + } |
|
83 | + |
|
84 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); |
|
85 | + $this->stmts = null; // abstract methods don't have statements |
|
86 | + |
|
87 | + return $this; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Makes the method final. |
|
92 | + * |
|
93 | + * @return $this The builder instance (for fluid interface) |
|
94 | + */ |
|
95 | + public function makeFinal() { |
|
96 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
|
97 | + |
|
98 | + return $this; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Adds a statement. |
|
103 | + * |
|
104 | + * @param Node|PhpParser\Builder $stmt The statement to add |
|
105 | + * |
|
106 | + * @return $this The builder instance (for fluid interface) |
|
107 | + */ |
|
108 | + public function addStmt($stmt) { |
|
109 | + if (null === $this->stmts) { |
|
110 | + throw new \LogicException('Cannot add statements to an abstract method'); |
|
111 | + } |
|
112 | + |
|
113 | + $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
|
114 | + |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Adds an attribute group. |
|
120 | + * |
|
121 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
122 | + * |
|
123 | + * @return $this The builder instance (for fluid interface) |
|
124 | + */ |
|
125 | + public function addAttribute($attribute) { |
|
126 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
127 | + |
|
128 | + return $this; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Returns the built method node. |
|
133 | + * |
|
134 | + * @return Stmt\ClassMethod The built method node |
|
135 | + */ |
|
136 | + public function getNode() : Node { |
|
137 | + return new Stmt\ClassMethod($this->name, [ |
|
138 | + 'flags' => $this->flags, |
|
139 | + 'byRef' => $this->returnByRef, |
|
140 | + 'params' => $this->params, |
|
141 | + 'returnType' => $this->returnType, |
|
142 | + 'stmts' => $this->stmts, |
|
143 | + 'attrGroups' => $this->attributeGroups, |
|
144 | + ], $this->attributes); |
|
145 | + } |
|
146 | 146 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class Method extends FunctionLike |
|
11 | -{ |
|
10 | +class Method extends FunctionLike { |
|
12 | 11 | protected $name; |
13 | 12 | protected $flags = 0; |
14 | 13 |