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
219219Interface or Trait
220220------------------
221221
222- You can create interfaces and traits in a similar way, just change the type :
222+ You can create interfaces and traits:
223223
224224``` 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' );
228228```
229229
230230Literals
Original file line number Diff line number Diff line change @@ -68,6 +68,24 @@ final class ClassType
6868 private $ methods = [];
6969
7070
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+
7189 /**
7290 * @param string|object $class
7391 */
@@ -131,7 +149,7 @@ public function getName(): ?string
131149 }
132150
133151
134- /** @return static */
152+ /** @deprecated */
135153 public function setClass (): self
136154 {
137155 $ 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
179179
180180 public function addInterface (string $ name ): ClassType
181181 {
182- return $ this ->addClass ($ name )->setInterface ( );
182+ return $ this ->addClass ($ name )->setType (ClassType:: TYPE_INTERFACE );
183183 }
184184
185185
186186 public function addTrait (string $ name ): ClassType
187187 {
188- return $ this ->addClass ($ name )->setTrait ( );
188+ return $ this ->addClass ($ name )->setType (ClassType:: TYPE_TRAIT );
189189 }
190190
191191
Original file line number Diff line number Diff line change @@ -13,9 +13,8 @@ use Tester\Assert;
1313require __DIR__ . '/../bootstrap.php ' ;
1414
1515
16- $ interface = new ClassType ('IExample ' );
16+ $ interface = ClassType:: interface ('IExample ' );
1717$ interface
18- ->setInterface ()
1918 ->addExtend ('IOne ' )
2019 ->addExtend ('ITwo ' )
2120 ->addComment ('Description of interface ' );
You can’t perform that action at this time.
0 commit comments