File tree Expand file tree Collapse file tree 4 files changed +26
-9
lines changed Expand file tree Collapse file tree 4 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -219,12 +219,12 @@ echo $printer->printClass($class); // 4 spaces indentation
219
219
Interface or Trait
220
220
------------------
221
221
222
- You can create interfaces and traits in a similar way, just change the type :
222
+ You can create interfaces and traits:
223
223
224
224
``` php
225
- $class = new Nette\PhpGenerator\ClassType('DemoInterface ');
226
- $class->setInterface( );
227
- // or $class->setTrait( );
225
+ $interface = Nette\PhpGenerator\ClassType::interface('MyInterface ');
226
+ $trait = Nette\PhpGenerator\ClassType::trait('MyTrait' );
227
+ // in a similar way $class = Nette\PhpGenerator\ClassType::class('MyClass' );
228
228
```
229
229
230
230
Literals
Original file line number Diff line number Diff line change @@ -68,6 +68,24 @@ final class ClassType
68
68
private $ methods = [];
69
69
70
70
71
+ public static function class (string $ name = null , PhpNamespace $ namespace = null ): self
72
+ {
73
+ return new self ($ name , $ namespace );
74
+ }
75
+
76
+
77
+ public static function interface (string $ name = null , PhpNamespace $ namespace = null ): self
78
+ {
79
+ return (new self ($ name , $ namespace ))->setType (self ::TYPE_INTERFACE );
80
+ }
81
+
82
+
83
+ public static function trait (string $ name = null , PhpNamespace $ namespace = null ): self
84
+ {
85
+ return (new self ($ name , $ namespace ))->setType (self ::TYPE_TRAIT );
86
+ }
87
+
88
+
71
89
/**
72
90
* @param string|object $class
73
91
*/
@@ -131,7 +149,7 @@ public function getName(): ?string
131
149
}
132
150
133
151
134
- /** @return static */
152
+ /** @deprecated */
135
153
public function setClass (): self
136
154
{
137
155
$ this ->type = self ::TYPE_CLASS ;
Original file line number Diff line number Diff line change @@ -179,13 +179,13 @@ public function addClass(string $name): ClassType
179
179
180
180
public function addInterface (string $ name ): ClassType
181
181
{
182
- return $ this ->addClass ($ name )->setInterface ( );
182
+ return $ this ->addClass ($ name )->setType (ClassType:: TYPE_INTERFACE );
183
183
}
184
184
185
185
186
186
public function addTrait (string $ name ): ClassType
187
187
{
188
- return $ this ->addClass ($ name )->setTrait ( );
188
+ return $ this ->addClass ($ name )->setType (ClassType:: TYPE_TRAIT );
189
189
}
190
190
191
191
Original file line number Diff line number Diff line change @@ -13,9 +13,8 @@ use Tester\Assert;
13
13
require __DIR__ . '/../bootstrap.php ' ;
14
14
15
15
16
- $ interface = new ClassType ('IExample ' );
16
+ $ interface = ClassType:: interface ('IExample ' );
17
17
$ interface
18
- ->setInterface ()
19
18
->addExtend ('IOne ' )
20
19
->addExtend ('ITwo ' )
21
20
->addComment ('Description of interface ' );
You can’t perform that action at this time.
0 commit comments