File tree Expand file tree Collapse file tree 3 files changed +17
-11
lines changed
Expand file tree Collapse file tree 3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -64,13 +64,13 @@ public static function fromCode(string $code): static
6464 }
6565
6666
67- public function __construct (string $ name, ? PhpNamespace $ namespace = null )
67+ public function __construct (string $ name )
6868 {
6969 if (str_contains ($ name , '\\' )) {
7070 $ this ->namespace = new PhpNamespace (Helpers::extractNamespace ($ name ));
7171 $ this ->setName (Helpers::extractShortName ($ name ));
7272 } else {
73- $ this ->namespace = $ namespace ;
73+ $ this ->namespace = func_num_args () > 1 ? func_get_arg ( 1 ) : null ; // backward compatibility
7474 $ this ->setName ($ name );
7575 }
7676 }
@@ -82,7 +82,15 @@ public function __toString(): string
8282 }
8383
8484
85- /** @deprecated an object can be in multiple namespaces */
85+ /** @internal */
86+ public function setNamespace (?PhpNamespace $ namespace ): static
87+ {
88+ $ this ->namespace = $ namespace ;
89+ return $ this ;
90+ }
91+
92+
93+ /** @internal */
8694 public function getNamespace (): ?PhpNamespace
8795 {
8896 return $ this ->namespace ;
Original file line number Diff line number Diff line change @@ -39,13 +39,11 @@ final class ClassType extends ClassLike
3939 private array $ implements = [];
4040
4141
42- public function __construct (?string $ name = null , ? PhpNamespace $ namespace = null )
42+ public function __construct (?string $ name = null )
4343 {
44+ parent ::__construct ($ name ?? 'foo ' , func_num_args () > 1 ? func_get_arg (1 ) : null ); // backward compatibility
4445 if ($ name === null ) {
45- parent ::__construct ('foo ' , $ namespace );
4646 $ this ->setName (null );
47- } else {
48- parent ::__construct ($ name , $ namespace );
4947 }
5048 }
5149
Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ public function add(ClassType|InterfaceType|TraitType|EnumType $class): static
280280 */
281281 public function addClass (string $ name ): ClassType
282282 {
283- $ this ->add ($ class = new ClassType ($ name, $ this ));
283+ $ this ->add ($ class = ( new ClassType ($ name))-> setNamespace ( $ this ));
284284 return $ class ;
285285 }
286286
@@ -290,7 +290,7 @@ public function addClass(string $name): ClassType
290290 */
291291 public function addInterface (string $ name ): InterfaceType
292292 {
293- $ this ->add ($ iface = new InterfaceType ($ name, $ this ));
293+ $ this ->add ($ iface = ( new InterfaceType ($ name))-> setNamespace ( $ this ));
294294 return $ iface ;
295295 }
296296
@@ -300,7 +300,7 @@ public function addInterface(string $name): InterfaceType
300300 */
301301 public function addTrait (string $ name ): TraitType
302302 {
303- $ this ->add ($ trait = new TraitType ($ name, $ this ));
303+ $ this ->add ($ trait = ( new TraitType ($ name))-> setNamespace ( $ this ));
304304 return $ trait ;
305305 }
306306
@@ -310,7 +310,7 @@ public function addTrait(string $name): TraitType
310310 */
311311 public function addEnum (string $ name ): EnumType
312312 {
313- $ this ->add ($ enum = new EnumType ($ name, $ this ));
313+ $ this ->add ($ enum = ( new EnumType ($ name))-> setNamespace ( $ this ));
314314 return $ enum ;
315315 }
316316
You can’t perform that action at this time.
0 commit comments