@@ -12,74 +12,74 @@ |
||
12 | 12 | |
13 | 13 | class EnumCase implements PhpParser\Builder |
14 | 14 | { |
15 | - protected $name; |
|
16 | - protected $value = null; |
|
17 | - protected $attributes = []; |
|
15 | + protected $name; |
|
16 | + protected $value = null; |
|
17 | + protected $attributes = []; |
|
18 | 18 | |
19 | - /** @var Node\AttributeGroup[] */ |
|
20 | - protected $attributeGroups = []; |
|
19 | + /** @var Node\AttributeGroup[] */ |
|
20 | + protected $attributeGroups = []; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Creates an enum case builder. |
|
24 | - * |
|
25 | - * @param string|Identifier $name Name |
|
26 | - */ |
|
27 | - public function __construct($name) { |
|
28 | - $this->name = $name; |
|
29 | - } |
|
22 | + /** |
|
23 | + * Creates an enum case builder. |
|
24 | + * |
|
25 | + * @param string|Identifier $name Name |
|
26 | + */ |
|
27 | + public function __construct($name) { |
|
28 | + $this->name = $name; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Sets the value. |
|
33 | - * |
|
34 | - * @param Node\Expr|string|int $value |
|
35 | - * |
|
36 | - * @return $this |
|
37 | - */ |
|
38 | - public function setValue($value) { |
|
39 | - $this->value = BuilderHelpers::normalizeValue($value); |
|
31 | + /** |
|
32 | + * Sets the value. |
|
33 | + * |
|
34 | + * @param Node\Expr|string|int $value |
|
35 | + * |
|
36 | + * @return $this |
|
37 | + */ |
|
38 | + public function setValue($value) { |
|
39 | + $this->value = BuilderHelpers::normalizeValue($value); |
|
40 | 40 | |
41 | - return $this; |
|
42 | - } |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Sets doc comment for the constant. |
|
46 | - * |
|
47 | - * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
48 | - * |
|
49 | - * @return $this The builder instance (for fluid interface) |
|
50 | - */ |
|
51 | - public function setDocComment($docComment) { |
|
52 | - $this->attributes = [ |
|
53 | - 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
|
54 | - ]; |
|
44 | + /** |
|
45 | + * Sets doc comment for the constant. |
|
46 | + * |
|
47 | + * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
48 | + * |
|
49 | + * @return $this The builder instance (for fluid interface) |
|
50 | + */ |
|
51 | + public function setDocComment($docComment) { |
|
52 | + $this->attributes = [ |
|
53 | + 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
|
54 | + ]; |
|
55 | 55 | |
56 | - return $this; |
|
57 | - } |
|
56 | + return $this; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Adds an attribute group. |
|
61 | - * |
|
62 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
63 | - * |
|
64 | - * @return $this The builder instance (for fluid interface) |
|
65 | - */ |
|
66 | - public function addAttribute($attribute) { |
|
67 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
59 | + /** |
|
60 | + * Adds an attribute group. |
|
61 | + * |
|
62 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
63 | + * |
|
64 | + * @return $this The builder instance (for fluid interface) |
|
65 | + */ |
|
66 | + public function addAttribute($attribute) { |
|
67 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
68 | 68 | |
69 | - return $this; |
|
70 | - } |
|
69 | + return $this; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Returns the built enum case node. |
|
74 | - * |
|
75 | - * @return Stmt\EnumCase The built constant node |
|
76 | - */ |
|
77 | - public function getNode(): PhpParser\Node { |
|
78 | - return new Stmt\EnumCase( |
|
79 | - $this->name, |
|
80 | - $this->value, |
|
81 | - $this->attributeGroups, |
|
82 | - $this->attributes |
|
83 | - ); |
|
84 | - } |
|
72 | + /** |
|
73 | + * Returns the built enum case node. |
|
74 | + * |
|
75 | + * @return Stmt\EnumCase The built constant node |
|
76 | + */ |
|
77 | + public function getNode(): PhpParser\Node { |
|
78 | + return new Stmt\EnumCase( |
|
79 | + $this->name, |
|
80 | + $this->value, |
|
81 | + $this->attributeGroups, |
|
82 | + $this->attributes |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | } |
@@ -12,150 +12,150 @@ |
||
12 | 12 | |
13 | 13 | class Property implements PhpParser\Builder |
14 | 14 | { |
15 | - protected $name; |
|
16 | - |
|
17 | - protected $flags = 0; |
|
18 | - protected $default = null; |
|
19 | - protected $attributes = []; |
|
20 | - |
|
21 | - /** @var null|Identifier|Name|NullableType */ |
|
22 | - protected $type; |
|
23 | - |
|
24 | - /** @var Node\AttributeGroup[] */ |
|
25 | - protected $attributeGroups = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * Creates a property builder. |
|
29 | - * |
|
30 | - * @param string $name Name of the property |
|
31 | - */ |
|
32 | - public function __construct(string $name) { |
|
33 | - $this->name = $name; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Makes the property public. |
|
38 | - * |
|
39 | - * @return $this The builder instance (for fluid interface) |
|
40 | - */ |
|
41 | - public function makePublic() { |
|
42 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
|
43 | - |
|
44 | - return $this; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Makes the property protected. |
|
49 | - * |
|
50 | - * @return $this The builder instance (for fluid interface) |
|
51 | - */ |
|
52 | - public function makeProtected() { |
|
53 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
|
54 | - |
|
55 | - return $this; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Makes the property private. |
|
60 | - * |
|
61 | - * @return $this The builder instance (for fluid interface) |
|
62 | - */ |
|
63 | - public function makePrivate() { |
|
64 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
|
65 | - |
|
66 | - return $this; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Makes the property static. |
|
71 | - * |
|
72 | - * @return $this The builder instance (for fluid interface) |
|
73 | - */ |
|
74 | - public function makeStatic() { |
|
75 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); |
|
76 | - |
|
77 | - return $this; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Makes the property readonly. |
|
82 | - * |
|
83 | - * @return $this The builder instance (for fluid interface) |
|
84 | - */ |
|
85 | - public function makeReadonly() { |
|
86 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_READONLY); |
|
87 | - |
|
88 | - return $this; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets default value for the property. |
|
93 | - * |
|
94 | - * @param mixed $value Default value to use |
|
95 | - * |
|
96 | - * @return $this The builder instance (for fluid interface) |
|
97 | - */ |
|
98 | - public function setDefault($value) { |
|
99 | - $this->default = BuilderHelpers::normalizeValue($value); |
|
100 | - |
|
101 | - return $this; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Sets doc comment for the property. |
|
106 | - * |
|
107 | - * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
108 | - * |
|
109 | - * @return $this The builder instance (for fluid interface) |
|
110 | - */ |
|
111 | - public function setDocComment($docComment) { |
|
112 | - $this->attributes = [ |
|
113 | - 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
|
114 | - ]; |
|
115 | - |
|
116 | - return $this; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets the property type for PHP 7.4+. |
|
121 | - * |
|
122 | - * @param string|Name|Identifier|ComplexType $type |
|
123 | - * |
|
124 | - * @return $this |
|
125 | - */ |
|
126 | - public function setType($type) { |
|
127 | - $this->type = BuilderHelpers::normalizeType($type); |
|
128 | - |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Adds an attribute group. |
|
134 | - * |
|
135 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
136 | - * |
|
137 | - * @return $this The builder instance (for fluid interface) |
|
138 | - */ |
|
139 | - public function addAttribute($attribute) { |
|
140 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
141 | - |
|
142 | - return $this; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Returns the built class node. |
|
147 | - * |
|
148 | - * @return Stmt\Property The built property node |
|
149 | - */ |
|
150 | - public function getNode() : PhpParser\Node { |
|
151 | - return new Stmt\Property( |
|
152 | - $this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC, |
|
153 | - [ |
|
154 | - new Stmt\PropertyProperty($this->name, $this->default) |
|
155 | - ], |
|
156 | - $this->attributes, |
|
157 | - $this->type, |
|
158 | - $this->attributeGroups |
|
159 | - ); |
|
160 | - } |
|
15 | + protected $name; |
|
16 | + |
|
17 | + protected $flags = 0; |
|
18 | + protected $default = null; |
|
19 | + protected $attributes = []; |
|
20 | + |
|
21 | + /** @var null|Identifier|Name|NullableType */ |
|
22 | + protected $type; |
|
23 | + |
|
24 | + /** @var Node\AttributeGroup[] */ |
|
25 | + protected $attributeGroups = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * Creates a property builder. |
|
29 | + * |
|
30 | + * @param string $name Name of the property |
|
31 | + */ |
|
32 | + public function __construct(string $name) { |
|
33 | + $this->name = $name; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Makes the property public. |
|
38 | + * |
|
39 | + * @return $this The builder instance (for fluid interface) |
|
40 | + */ |
|
41 | + public function makePublic() { |
|
42 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
|
43 | + |
|
44 | + return $this; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Makes the property protected. |
|
49 | + * |
|
50 | + * @return $this The builder instance (for fluid interface) |
|
51 | + */ |
|
52 | + public function makeProtected() { |
|
53 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
|
54 | + |
|
55 | + return $this; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Makes the property private. |
|
60 | + * |
|
61 | + * @return $this The builder instance (for fluid interface) |
|
62 | + */ |
|
63 | + public function makePrivate() { |
|
64 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
|
65 | + |
|
66 | + return $this; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Makes the property static. |
|
71 | + * |
|
72 | + * @return $this The builder instance (for fluid interface) |
|
73 | + */ |
|
74 | + public function makeStatic() { |
|
75 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); |
|
76 | + |
|
77 | + return $this; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Makes the property readonly. |
|
82 | + * |
|
83 | + * @return $this The builder instance (for fluid interface) |
|
84 | + */ |
|
85 | + public function makeReadonly() { |
|
86 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_READONLY); |
|
87 | + |
|
88 | + return $this; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets default value for the property. |
|
93 | + * |
|
94 | + * @param mixed $value Default value to use |
|
95 | + * |
|
96 | + * @return $this The builder instance (for fluid interface) |
|
97 | + */ |
|
98 | + public function setDefault($value) { |
|
99 | + $this->default = BuilderHelpers::normalizeValue($value); |
|
100 | + |
|
101 | + return $this; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Sets doc comment for the property. |
|
106 | + * |
|
107 | + * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
108 | + * |
|
109 | + * @return $this The builder instance (for fluid interface) |
|
110 | + */ |
|
111 | + public function setDocComment($docComment) { |
|
112 | + $this->attributes = [ |
|
113 | + 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
|
114 | + ]; |
|
115 | + |
|
116 | + return $this; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets the property type for PHP 7.4+. |
|
121 | + * |
|
122 | + * @param string|Name|Identifier|ComplexType $type |
|
123 | + * |
|
124 | + * @return $this |
|
125 | + */ |
|
126 | + public function setType($type) { |
|
127 | + $this->type = BuilderHelpers::normalizeType($type); |
|
128 | + |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Adds an attribute group. |
|
134 | + * |
|
135 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
136 | + * |
|
137 | + * @return $this The builder instance (for fluid interface) |
|
138 | + */ |
|
139 | + public function addAttribute($attribute) { |
|
140 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
141 | + |
|
142 | + return $this; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Returns the built class node. |
|
147 | + * |
|
148 | + * @return Stmt\Property The built property node |
|
149 | + */ |
|
150 | + public function getNode() : PhpParser\Node { |
|
151 | + return new Stmt\Property( |
|
152 | + $this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC, |
|
153 | + [ |
|
154 | + new Stmt\PropertyProperty($this->name, $this->default) |
|
155 | + ], |
|
156 | + $this->attributes, |
|
157 | + $this->type, |
|
158 | + $this->attributeGroups |
|
159 | + ); |
|
160 | + } |
|
161 | 161 | } |
@@ -9,70 +9,70 @@ |
||
9 | 9 | |
10 | 10 | class Trait_ extends Declaration |
11 | 11 | { |
12 | - protected $name; |
|
13 | - protected $uses = []; |
|
14 | - protected $properties = []; |
|
15 | - protected $methods = []; |
|
12 | + protected $name; |
|
13 | + protected $uses = []; |
|
14 | + protected $properties = []; |
|
15 | + protected $methods = []; |
|
16 | 16 | |
17 | - /** @var Node\AttributeGroup[] */ |
|
18 | - protected $attributeGroups = []; |
|
17 | + /** @var Node\AttributeGroup[] */ |
|
18 | + protected $attributeGroups = []; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Creates an interface builder. |
|
22 | - * |
|
23 | - * @param string $name Name of the interface |
|
24 | - */ |
|
25 | - public function __construct(string $name) { |
|
26 | - $this->name = $name; |
|
27 | - } |
|
20 | + /** |
|
21 | + * Creates an interface builder. |
|
22 | + * |
|
23 | + * @param string $name Name of the interface |
|
24 | + */ |
|
25 | + public function __construct(string $name) { |
|
26 | + $this->name = $name; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Adds a statement. |
|
31 | - * |
|
32 | - * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
33 | - * |
|
34 | - * @return $this The builder instance (for fluid interface) |
|
35 | - */ |
|
36 | - public function addStmt($stmt) { |
|
37 | - $stmt = BuilderHelpers::normalizeNode($stmt); |
|
29 | + /** |
|
30 | + * Adds a statement. |
|
31 | + * |
|
32 | + * @param Stmt|PhpParser\Builder $stmt The statement to add |
|
33 | + * |
|
34 | + * @return $this The builder instance (for fluid interface) |
|
35 | + */ |
|
36 | + public function addStmt($stmt) { |
|
37 | + $stmt = BuilderHelpers::normalizeNode($stmt); |
|
38 | 38 | |
39 | - if ($stmt instanceof Stmt\Property) { |
|
40 | - $this->properties[] = $stmt; |
|
41 | - } elseif ($stmt instanceof Stmt\ClassMethod) { |
|
42 | - $this->methods[] = $stmt; |
|
43 | - } elseif ($stmt instanceof Stmt\TraitUse) { |
|
44 | - $this->uses[] = $stmt; |
|
45 | - } else { |
|
46 | - throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
47 | - } |
|
39 | + if ($stmt instanceof Stmt\Property) { |
|
40 | + $this->properties[] = $stmt; |
|
41 | + } elseif ($stmt instanceof Stmt\ClassMethod) { |
|
42 | + $this->methods[] = $stmt; |
|
43 | + } elseif ($stmt instanceof Stmt\TraitUse) { |
|
44 | + $this->uses[] = $stmt; |
|
45 | + } else { |
|
46 | + throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); |
|
47 | + } |
|
48 | 48 | |
49 | - return $this; |
|
50 | - } |
|
49 | + return $this; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Adds an attribute group. |
|
54 | - * |
|
55 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
56 | - * |
|
57 | - * @return $this The builder instance (for fluid interface) |
|
58 | - */ |
|
59 | - public function addAttribute($attribute) { |
|
60 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
52 | + /** |
|
53 | + * Adds an attribute group. |
|
54 | + * |
|
55 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
56 | + * |
|
57 | + * @return $this The builder instance (for fluid interface) |
|
58 | + */ |
|
59 | + public function addAttribute($attribute) { |
|
60 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
61 | 61 | |
62 | - return $this; |
|
63 | - } |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns the built trait node. |
|
67 | - * |
|
68 | - * @return Stmt\Trait_ The built interface node |
|
69 | - */ |
|
70 | - public function getNode() : PhpParser\Node { |
|
71 | - return new Stmt\Trait_( |
|
72 | - $this->name, [ |
|
73 | - 'stmts' => array_merge($this->uses, $this->properties, $this->methods), |
|
74 | - 'attrGroups' => $this->attributeGroups, |
|
75 | - ], $this->attributes |
|
76 | - ); |
|
77 | - } |
|
65 | + /** |
|
66 | + * Returns the built trait node. |
|
67 | + * |
|
68 | + * @return Stmt\Trait_ The built interface node |
|
69 | + */ |
|
70 | + public function getNode() : PhpParser\Node { |
|
71 | + return new Stmt\Trait_( |
|
72 | + $this->name, [ |
|
73 | + 'stmts' => array_merge($this->uses, $this->properties, $this->methods), |
|
74 | + 'attrGroups' => $this->attributeGroups, |
|
75 | + ], $this->attributes |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class Trait_ extends Declaration |
|
11 | -{ |
|
10 | +class Trait_ extends Declaration { |
|
12 | 11 | protected $name; |
13 | 12 | protected $uses = []; |
14 | 13 | protected $properties = []; |
@@ -9,37 +9,37 @@ |
||
9 | 9 | |
10 | 10 | class Namespace_ extends Declaration |
11 | 11 | { |
12 | - private $name; |
|
13 | - private $stmts = []; |
|
12 | + private $name; |
|
13 | + private $stmts = []; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Creates a namespace builder. |
|
17 | - * |
|
18 | - * @param Node\Name|string|null $name Name of the namespace |
|
19 | - */ |
|
20 | - public function __construct($name) { |
|
21 | - $this->name = null !== $name ? BuilderHelpers::normalizeName($name) : null; |
|
22 | - } |
|
15 | + /** |
|
16 | + * Creates a namespace builder. |
|
17 | + * |
|
18 | + * @param Node\Name|string|null $name Name of the namespace |
|
19 | + */ |
|
20 | + public function __construct($name) { |
|
21 | + $this->name = null !== $name ? BuilderHelpers::normalizeName($name) : null; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Adds a statement. |
|
26 | - * |
|
27 | - * @param Node|PhpParser\Builder $stmt The statement to add |
|
28 | - * |
|
29 | - * @return $this The builder instance (for fluid interface) |
|
30 | - */ |
|
31 | - public function addStmt($stmt) { |
|
32 | - $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
|
24 | + /** |
|
25 | + * Adds a statement. |
|
26 | + * |
|
27 | + * @param Node|PhpParser\Builder $stmt The statement to add |
|
28 | + * |
|
29 | + * @return $this The builder instance (for fluid interface) |
|
30 | + */ |
|
31 | + public function addStmt($stmt) { |
|
32 | + $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
|
33 | 33 | |
34 | - return $this; |
|
35 | - } |
|
34 | + return $this; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Returns the built node. |
|
39 | - * |
|
40 | - * @return Stmt\Namespace_ The built node |
|
41 | - */ |
|
42 | - public function getNode() : Node { |
|
43 | - return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Returns the built node. |
|
39 | + * |
|
40 | + * @return Stmt\Namespace_ The built node |
|
41 | + */ |
|
42 | + public function getNode() : Node { |
|
43 | + return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes); |
|
44 | + } |
|
45 | 45 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class Namespace_ extends Declaration |
|
11 | -{ |
|
10 | +class Namespace_ extends Declaration { |
|
12 | 11 | private $name; |
13 | 12 | private $stmts = []; |
14 | 13 |
@@ -13,136 +13,136 @@ |
||
13 | 13 | |
14 | 14 | class ClassConst implements PhpParser\Builder |
15 | 15 | { |
16 | - protected $flags = 0; |
|
17 | - protected $attributes = []; |
|
18 | - protected $constants = []; |
|
19 | - |
|
20 | - /** @var Node\AttributeGroup[] */ |
|
21 | - protected $attributeGroups = []; |
|
22 | - /** @var Identifier|Node\Name|Node\ComplexType */ |
|
23 | - protected $type; |
|
24 | - |
|
25 | - /** |
|
26 | - * Creates a class constant builder |
|
27 | - * |
|
28 | - * @param string|Identifier $name Name |
|
29 | - * @param Node\Expr|bool|null|int|float|string|array $value Value |
|
30 | - */ |
|
31 | - public function __construct($name, $value) { |
|
32 | - $this->constants = [new Const_($name, BuilderHelpers::normalizeValue($value))]; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Add another constant to const group |
|
37 | - * |
|
38 | - * @param string|Identifier $name Name |
|
39 | - * @param Node\Expr|bool|null|int|float|string|array $value Value |
|
40 | - * |
|
41 | - * @return $this The builder instance (for fluid interface) |
|
42 | - */ |
|
43 | - public function addConst($name, $value) { |
|
44 | - $this->constants[] = new Const_($name, BuilderHelpers::normalizeValue($value)); |
|
45 | - |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Makes the constant public. |
|
51 | - * |
|
52 | - * @return $this The builder instance (for fluid interface) |
|
53 | - */ |
|
54 | - public function makePublic() { |
|
55 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
|
56 | - |
|
57 | - return $this; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Makes the constant protected. |
|
62 | - * |
|
63 | - * @return $this The builder instance (for fluid interface) |
|
64 | - */ |
|
65 | - public function makeProtected() { |
|
66 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
|
67 | - |
|
68 | - return $this; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Makes the constant private. |
|
73 | - * |
|
74 | - * @return $this The builder instance (for fluid interface) |
|
75 | - */ |
|
76 | - public function makePrivate() { |
|
77 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
|
78 | - |
|
79 | - return $this; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Makes the constant final. |
|
84 | - * |
|
85 | - * @return $this The builder instance (for fluid interface) |
|
86 | - */ |
|
87 | - public function makeFinal() { |
|
88 | - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
|
89 | - |
|
90 | - return $this; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets doc comment for the constant. |
|
95 | - * |
|
96 | - * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
97 | - * |
|
98 | - * @return $this The builder instance (for fluid interface) |
|
99 | - */ |
|
100 | - public function setDocComment($docComment) { |
|
101 | - $this->attributes = [ |
|
102 | - 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
|
103 | - ]; |
|
104 | - |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Adds an attribute group. |
|
110 | - * |
|
111 | - * @param Node\Attribute|Node\AttributeGroup $attribute |
|
112 | - * |
|
113 | - * @return $this The builder instance (for fluid interface) |
|
114 | - */ |
|
115 | - public function addAttribute($attribute) { |
|
116 | - $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
117 | - |
|
118 | - return $this; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Sets the constant type. |
|
123 | - * |
|
124 | - * @param string|Node\Name|Identifier|Node\ComplexType $type |
|
125 | - * |
|
126 | - * @return $this |
|
127 | - */ |
|
128 | - public function setType($type) { |
|
129 | - $this->type = BuilderHelpers::normalizeType($type); |
|
130 | - |
|
131 | - return $this; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns the built class node. |
|
136 | - * |
|
137 | - * @return Stmt\ClassConst The built constant node |
|
138 | - */ |
|
139 | - public function getNode(): PhpParser\Node { |
|
140 | - return new Stmt\ClassConst( |
|
141 | - $this->constants, |
|
142 | - $this->flags, |
|
143 | - $this->attributes, |
|
144 | - $this->attributeGroups, |
|
145 | - $this->type |
|
146 | - ); |
|
147 | - } |
|
16 | + protected $flags = 0; |
|
17 | + protected $attributes = []; |
|
18 | + protected $constants = []; |
|
19 | + |
|
20 | + /** @var Node\AttributeGroup[] */ |
|
21 | + protected $attributeGroups = []; |
|
22 | + /** @var Identifier|Node\Name|Node\ComplexType */ |
|
23 | + protected $type; |
|
24 | + |
|
25 | + /** |
|
26 | + * Creates a class constant builder |
|
27 | + * |
|
28 | + * @param string|Identifier $name Name |
|
29 | + * @param Node\Expr|bool|null|int|float|string|array $value Value |
|
30 | + */ |
|
31 | + public function __construct($name, $value) { |
|
32 | + $this->constants = [new Const_($name, BuilderHelpers::normalizeValue($value))]; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Add another constant to const group |
|
37 | + * |
|
38 | + * @param string|Identifier $name Name |
|
39 | + * @param Node\Expr|bool|null|int|float|string|array $value Value |
|
40 | + * |
|
41 | + * @return $this The builder instance (for fluid interface) |
|
42 | + */ |
|
43 | + public function addConst($name, $value) { |
|
44 | + $this->constants[] = new Const_($name, BuilderHelpers::normalizeValue($value)); |
|
45 | + |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Makes the constant public. |
|
51 | + * |
|
52 | + * @return $this The builder instance (for fluid interface) |
|
53 | + */ |
|
54 | + public function makePublic() { |
|
55 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); |
|
56 | + |
|
57 | + return $this; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Makes the constant protected. |
|
62 | + * |
|
63 | + * @return $this The builder instance (for fluid interface) |
|
64 | + */ |
|
65 | + public function makeProtected() { |
|
66 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); |
|
67 | + |
|
68 | + return $this; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Makes the constant private. |
|
73 | + * |
|
74 | + * @return $this The builder instance (for fluid interface) |
|
75 | + */ |
|
76 | + public function makePrivate() { |
|
77 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); |
|
78 | + |
|
79 | + return $this; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Makes the constant final. |
|
84 | + * |
|
85 | + * @return $this The builder instance (for fluid interface) |
|
86 | + */ |
|
87 | + public function makeFinal() { |
|
88 | + $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); |
|
89 | + |
|
90 | + return $this; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Sets doc comment for the constant. |
|
95 | + * |
|
96 | + * @param PhpParser\Comment\Doc|string $docComment Doc comment to set |
|
97 | + * |
|
98 | + * @return $this The builder instance (for fluid interface) |
|
99 | + */ |
|
100 | + public function setDocComment($docComment) { |
|
101 | + $this->attributes = [ |
|
102 | + 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] |
|
103 | + ]; |
|
104 | + |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Adds an attribute group. |
|
110 | + * |
|
111 | + * @param Node\Attribute|Node\AttributeGroup $attribute |
|
112 | + * |
|
113 | + * @return $this The builder instance (for fluid interface) |
|
114 | + */ |
|
115 | + public function addAttribute($attribute) { |
|
116 | + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
|
117 | + |
|
118 | + return $this; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Sets the constant type. |
|
123 | + * |
|
124 | + * @param string|Node\Name|Identifier|Node\ComplexType $type |
|
125 | + * |
|
126 | + * @return $this |
|
127 | + */ |
|
128 | + public function setType($type) { |
|
129 | + $this->type = BuilderHelpers::normalizeType($type); |
|
130 | + |
|
131 | + return $this; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns the built class node. |
|
136 | + * |
|
137 | + * @return Stmt\ClassConst The built constant node |
|
138 | + */ |
|
139 | + public function getNode(): PhpParser\Node { |
|
140 | + return new Stmt\ClassConst( |
|
141 | + $this->constants, |
|
142 | + $this->flags, |
|
143 | + $this->attributes, |
|
144 | + $this->attributeGroups, |
|
145 | + $this->type |
|
146 | + ); |
|
147 | + } |
|
148 | 148 | } |
@@ -9,41 +9,41 @@ |
||
9 | 9 | |
10 | 10 | class Use_ implements Builder |
11 | 11 | { |
12 | - protected $name; |
|
13 | - protected $type; |
|
14 | - protected $alias = null; |
|
12 | + protected $name; |
|
13 | + protected $type; |
|
14 | + protected $alias = null; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Creates a name use (alias) builder. |
|
18 | - * |
|
19 | - * @param Node\Name|string $name Name of the entity (namespace, class, function, constant) to alias |
|
20 | - * @param int $type One of the Stmt\Use_::TYPE_* constants |
|
21 | - */ |
|
22 | - public function __construct($name, int $type) { |
|
23 | - $this->name = BuilderHelpers::normalizeName($name); |
|
24 | - $this->type = $type; |
|
25 | - } |
|
16 | + /** |
|
17 | + * Creates a name use (alias) builder. |
|
18 | + * |
|
19 | + * @param Node\Name|string $name Name of the entity (namespace, class, function, constant) to alias |
|
20 | + * @param int $type One of the Stmt\Use_::TYPE_* constants |
|
21 | + */ |
|
22 | + public function __construct($name, int $type) { |
|
23 | + $this->name = BuilderHelpers::normalizeName($name); |
|
24 | + $this->type = $type; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Sets alias for used name. |
|
29 | - * |
|
30 | - * @param string $alias Alias to use (last component of full name by default) |
|
31 | - * |
|
32 | - * @return $this The builder instance (for fluid interface) |
|
33 | - */ |
|
34 | - public function as(string $alias) { |
|
35 | - $this->alias = $alias; |
|
36 | - return $this; |
|
37 | - } |
|
27 | + /** |
|
28 | + * Sets alias for used name. |
|
29 | + * |
|
30 | + * @param string $alias Alias to use (last component of full name by default) |
|
31 | + * |
|
32 | + * @return $this The builder instance (for fluid interface) |
|
33 | + */ |
|
34 | + public function as(string $alias) { |
|
35 | + $this->alias = $alias; |
|
36 | + return $this; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns the built node. |
|
41 | - * |
|
42 | - * @return Stmt\Use_ The built node |
|
43 | - */ |
|
44 | - public function getNode() : Node { |
|
45 | - return new Stmt\Use_([ |
|
46 | - new Stmt\UseUse($this->name, $this->alias) |
|
47 | - ], $this->type); |
|
48 | - } |
|
39 | + /** |
|
40 | + * Returns the built node. |
|
41 | + * |
|
42 | + * @return Stmt\Use_ The built node |
|
43 | + */ |
|
44 | + public function getNode() : Node { |
|
45 | + return new Stmt\Use_([ |
|
46 | + new Stmt\UseUse($this->name, $this->alias) |
|
47 | + ], $this->type); |
|
48 | + } |
|
49 | 49 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class Use_ implements Builder |
|
11 | -{ |
|
10 | +class Use_ implements Builder { |
|
12 | 11 | protected $name; |
13 | 12 | protected $type; |
14 | 13 | protected $alias = null; |
@@ -9,56 +9,56 @@ |
||
9 | 9 | |
10 | 10 | class TraitUse implements Builder |
11 | 11 | { |
12 | - protected $traits = []; |
|
13 | - protected $adaptations = []; |
|
12 | + protected $traits = []; |
|
13 | + protected $adaptations = []; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Creates a trait use builder. |
|
17 | - * |
|
18 | - * @param Node\Name|string ...$traits Names of used traits |
|
19 | - */ |
|
20 | - public function __construct(...$traits) { |
|
21 | - foreach ($traits as $trait) { |
|
22 | - $this->and($trait); |
|
23 | - } |
|
24 | - } |
|
15 | + /** |
|
16 | + * Creates a trait use builder. |
|
17 | + * |
|
18 | + * @param Node\Name|string ...$traits Names of used traits |
|
19 | + */ |
|
20 | + public function __construct(...$traits) { |
|
21 | + foreach ($traits as $trait) { |
|
22 | + $this->and($trait); |
|
23 | + } |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Adds used trait. |
|
28 | - * |
|
29 | - * @param Node\Name|string $trait Trait name |
|
30 | - * |
|
31 | - * @return $this The builder instance (for fluid interface) |
|
32 | - */ |
|
33 | - public function and($trait) { |
|
34 | - $this->traits[] = BuilderHelpers::normalizeName($trait); |
|
35 | - return $this; |
|
36 | - } |
|
26 | + /** |
|
27 | + * Adds used trait. |
|
28 | + * |
|
29 | + * @param Node\Name|string $trait Trait name |
|
30 | + * |
|
31 | + * @return $this The builder instance (for fluid interface) |
|
32 | + */ |
|
33 | + public function and($trait) { |
|
34 | + $this->traits[] = BuilderHelpers::normalizeName($trait); |
|
35 | + return $this; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Adds trait adaptation. |
|
40 | - * |
|
41 | - * @param Stmt\TraitUseAdaptation|Builder\TraitUseAdaptation $adaptation Trait adaptation |
|
42 | - * |
|
43 | - * @return $this The builder instance (for fluid interface) |
|
44 | - */ |
|
45 | - public function with($adaptation) { |
|
46 | - $adaptation = BuilderHelpers::normalizeNode($adaptation); |
|
38 | + /** |
|
39 | + * Adds trait adaptation. |
|
40 | + * |
|
41 | + * @param Stmt\TraitUseAdaptation|Builder\TraitUseAdaptation $adaptation Trait adaptation |
|
42 | + * |
|
43 | + * @return $this The builder instance (for fluid interface) |
|
44 | + */ |
|
45 | + public function with($adaptation) { |
|
46 | + $adaptation = BuilderHelpers::normalizeNode($adaptation); |
|
47 | 47 | |
48 | - if (!$adaptation instanceof Stmt\TraitUseAdaptation) { |
|
49 | - throw new \LogicException('Adaptation must have type TraitUseAdaptation'); |
|
50 | - } |
|
48 | + if (!$adaptation instanceof Stmt\TraitUseAdaptation) { |
|
49 | + throw new \LogicException('Adaptation must have type TraitUseAdaptation'); |
|
50 | + } |
|
51 | 51 | |
52 | - $this->adaptations[] = $adaptation; |
|
53 | - return $this; |
|
54 | - } |
|
52 | + $this->adaptations[] = $adaptation; |
|
53 | + return $this; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns the built node. |
|
58 | - * |
|
59 | - * @return Node The built node |
|
60 | - */ |
|
61 | - public function getNode() : Node { |
|
62 | - return new Stmt\TraitUse($this->traits, $this->adaptations); |
|
63 | - } |
|
56 | + /** |
|
57 | + * Returns the built node. |
|
58 | + * |
|
59 | + * @return Node The built node |
|
60 | + */ |
|
61 | + public function getNode() : Node { |
|
62 | + return new Stmt\TraitUse($this->traits, $this->adaptations); |
|
63 | + } |
|
64 | 64 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt; |
9 | 9 | |
10 | -class TraitUse implements Builder |
|
11 | -{ |
|
10 | +class TraitUse implements Builder { |
|
12 | 11 | protected $traits = []; |
13 | 12 | protected $adaptations = []; |
14 | 13 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | class Throwing implements ErrorHandler |
14 | 14 | { |
15 | - public function handleError(Error $error) { |
|
16 | - throw $error; |
|
17 | - } |
|
15 | + public function handleError(Error $error) { |
|
16 | + throw $error; |
|
17 | + } |
|
18 | 18 | } |
@@ -10,8 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * This is the default strategy used by all components. |
12 | 12 | */ |
13 | -class Throwing implements ErrorHandler |
|
14 | -{ |
|
13 | +class Throwing implements ErrorHandler { |
|
15 | 14 | public function handleError(Error $error) { |
16 | 15 | throw $error; |
17 | 16 | } |
@@ -12,35 +12,35 @@ |
||
12 | 12 | */ |
13 | 13 | class Collecting implements ErrorHandler |
14 | 14 | { |
15 | - /** @var Error[] Collected errors */ |
|
16 | - private $errors = []; |
|
15 | + /** @var Error[] Collected errors */ |
|
16 | + private $errors = []; |
|
17 | 17 | |
18 | - public function handleError(Error $error) { |
|
19 | - $this->errors[] = $error; |
|
20 | - } |
|
18 | + public function handleError(Error $error) { |
|
19 | + $this->errors[] = $error; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Get collected errors. |
|
24 | - * |
|
25 | - * @return Error[] |
|
26 | - */ |
|
27 | - public function getErrors() : array { |
|
28 | - return $this->errors; |
|
29 | - } |
|
22 | + /** |
|
23 | + * Get collected errors. |
|
24 | + * |
|
25 | + * @return Error[] |
|
26 | + */ |
|
27 | + public function getErrors() : array { |
|
28 | + return $this->errors; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Check whether there are any errors. |
|
33 | - * |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function hasErrors() : bool { |
|
37 | - return !empty($this->errors); |
|
38 | - } |
|
31 | + /** |
|
32 | + * Check whether there are any errors. |
|
33 | + * |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function hasErrors() : bool { |
|
37 | + return !empty($this->errors); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Reset/clear collected errors. |
|
42 | - */ |
|
43 | - public function clearErrors() { |
|
44 | - $this->errors = []; |
|
45 | - } |
|
40 | + /** |
|
41 | + * Reset/clear collected errors. |
|
42 | + */ |
|
43 | + public function clearErrors() { |
|
44 | + $this->errors = []; |
|
45 | + } |
|
46 | 46 | } |
@@ -10,8 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * This allows graceful handling of errors. |
12 | 12 | */ |
13 | -class Collecting implements ErrorHandler |
|
14 | -{ |
|
13 | +class Collecting implements ErrorHandler { |
|
15 | 14 | /** @var Error[] Collected errors */ |
16 | 15 | private $errors = []; |
17 | 16 |