@@ -30,7 +30,7 @@ class ClassType
3030 /** @var PhpNamespace|NULL */
3131 private $ namespace ;
3232
33- /** @var string */
33+ /** @var string|NULL */
3434 private $ name ;
3535
3636 /** @var string class|interface|trait */
@@ -72,7 +72,7 @@ public static function from($from)
7272 {
7373 $ from = $ from instanceof \ReflectionClass ? $ from : new \ReflectionClass ($ from );
7474 if (PHP_VERSION_ID >= 70000 && $ from ->isAnonymous ()) {
75- $ class = new static ( ' anonymous ' ) ;
75+ $ class = new static ;
7676 } else {
7777 $ class = new static ($ from ->getShortName (), new PhpNamespace ($ from ->getNamespaceName ()));
7878 }
@@ -99,7 +99,7 @@ public static function from($from)
9999 }
100100
101101
102- public function __construct ($ name = '' , PhpNamespace $ namespace = NULL )
102+ public function __construct ($ name = NULL , PhpNamespace $ namespace = NULL )
103103 {
104104 $ this ->setName ($ name );
105105 $ this ->namespace = $ namespace ;
@@ -134,18 +134,17 @@ public function __toString()
134134 Helpers::formatDocComment ($ this ->comment . "\n" )
135135 . ($ this ->abstract ? 'abstract ' : '' )
136136 . ($ this ->final ? 'final ' : '' )
137- . $ this ->type . ' '
138- . $ this ->name . ' '
137+ . ($ this ->name ? "$ this ->type $ this ->name " : '' )
139138 . ($ this ->extends ? 'extends ' . implode (', ' , $ mapper ((array ) $ this ->extends )) . ' ' : '' )
140139 . ($ this ->implements ? 'implements ' . implode (', ' , $ mapper ($ this ->implements )) . ' ' : '' )
141- . "\n{ \n"
140+ . ( $ this -> name ? "\n" : '' ) . " { \n"
142141 . Strings::indent (
143142 ($ this ->traits ? 'use ' . implode ("; \nuse " , $ mapper ($ this ->traits )) . "; \n\n" : '' )
144143 . ($ this ->consts ? implode ('' , $ consts ) . "\n" : '' )
145144 . ($ this ->properties ? implode ("\n" , $ properties ) . "\n" : '' )
146145 . ($ this ->methods ? "\n" . implode ("\n\n\n" , $ this ->methods ) . "\n\n" : '' ), 1 )
147146 . '} '
148- ) . "\n" ;
147+ ) . ( $ this -> name ? "\n" : '' ) ;
149148 }
150149
151150
@@ -159,18 +158,18 @@ public function getNamespace()
159158
160159
161160 /**
162- * @param string
161+ * @param string|NULL
163162 * @return static
164163 */
165164 public function setName ($ name )
166165 {
167- $ this ->name = ( string ) $ name ;
166+ $ this ->name = $ name ;
168167 return $ this ;
169168 }
170169
171170
172171 /**
173- * @return string
172+ * @return string|NULL
174173 */
175174 public function getName ()
176175 {
0 commit comments