File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ public static function fromNodes(Node ...$nodes): self
8080 }
8181
8282 public static function fromScratch (
83- string $ className ,
83+ ? string $ className ,
8484 string $ namespace = null ,
8585 bool $ typed = true ,
8686 bool $ strict = true
@@ -196,6 +196,11 @@ public function getNamespace(): ?string
196196 return $ this ->namespace ;
197197 }
198198
199+ public function setName (?string $ name ): void
200+ {
201+ $ this ->name = $ name ;
202+ }
203+
199204 public function getName (): ?string
200205 {
201206 return $ this ->name ;
Original file line number Diff line number Diff line change 1010
1111namespace OpenCodeModeling \CodeAst \Code ;
1212
13- use PhpParser \Builder ;
1413use PhpParser \Node \Stmt \Class_ ;
1514
1615/**
@@ -37,11 +36,11 @@ final class ClassGenerator implements StatementGenerator
3736 private $ flags = 0 ;
3837
3938 /**
40- * @param string $name
39+ * @param string|null $name
4140 * @param array|string $flags
4241 */
4342 public function __construct (
44- $ name ,
43+ ? string $ name ,
4544 $ flags = null
4645 ) {
4746 $ this ->setName ($ name );
@@ -53,19 +52,15 @@ public function __construct(
5352
5453 public function generate (): Class_
5554 {
56- $ classBuilder = new Builder \ Class_ ($ this -> name );
57- $ node = $ classBuilder -> getNode ();
58-
59- $ node -> flags = $ this ->flags ;
60-
61- return $ node ;
55+ return new Class_ (
56+ $ this -> name ,
57+ [
58+ ' flags ' => $ this ->flags ,
59+ ]
60+ ) ;
6261 }
6362
64- /**
65- * @param string $name
66- * @return self
67- */
68- public function setName (string $ name ): self
63+ public function setName (?string $ name ): self
6964 {
7065 $ this ->name = $ name ;
7166
You can’t perform that action at this time.
0 commit comments