@@ -30,7 +30,7 @@ class ClassType
30
30
/** @var PhpNamespace|NULL */
31
31
private $ namespace ;
32
32
33
- /** @var string */
33
+ /** @var string|NULL */
34
34
private $ name ;
35
35
36
36
/** @var string class|interface|trait */
@@ -72,7 +72,7 @@ public static function from($from)
72
72
{
73
73
$ from = $ from instanceof \ReflectionClass ? $ from : new \ReflectionClass ($ from );
74
74
if (PHP_VERSION_ID >= 70000 && $ from ->isAnonymous ()) {
75
- $ class = new static ( ' anonymous ' ) ;
75
+ $ class = new static ;
76
76
} else {
77
77
$ class = new static ($ from ->getShortName (), new PhpNamespace ($ from ->getNamespaceName ()));
78
78
}
@@ -99,7 +99,7 @@ public static function from($from)
99
99
}
100
100
101
101
102
- public function __construct ($ name = '' , PhpNamespace $ namespace = NULL )
102
+ public function __construct ($ name = NULL , PhpNamespace $ namespace = NULL )
103
103
{
104
104
$ this ->setName ($ name );
105
105
$ this ->namespace = $ namespace ;
@@ -134,18 +134,17 @@ public function __toString()
134
134
Helpers::formatDocComment ($ this ->comment . "\n" )
135
135
. ($ this ->abstract ? 'abstract ' : '' )
136
136
. ($ this ->final ? 'final ' : '' )
137
- . $ this ->type . ' '
138
- . $ this ->name . ' '
137
+ . ($ this ->name ? "$ this ->type $ this ->name " : '' )
139
138
. ($ this ->extends ? 'extends ' . implode (', ' , $ mapper ((array ) $ this ->extends )) . ' ' : '' )
140
139
. ($ this ->implements ? 'implements ' . implode (', ' , $ mapper ($ this ->implements )) . ' ' : '' )
141
- . "\n{ \n"
140
+ . ( $ this -> name ? "\n" : '' ) . " { \n"
142
141
. Strings::indent (
143
142
($ this ->traits ? 'use ' . implode ("; \nuse " , $ mapper ($ this ->traits )) . "; \n\n" : '' )
144
143
. ($ this ->consts ? implode ('' , $ consts ) . "\n" : '' )
145
144
. ($ this ->properties ? implode ("\n" , $ properties ) . "\n" : '' )
146
145
. ($ this ->methods ? "\n" . implode ("\n\n\n" , $ this ->methods ) . "\n\n" : '' ), 1 )
147
146
. '} '
148
- ) . "\n" ;
147
+ ) . ( $ this -> name ? "\n" : '' ) ;
149
148
}
150
149
151
150
@@ -159,18 +158,18 @@ public function getNamespace()
159
158
160
159
161
160
/**
162
- * @param string
161
+ * @param string|NULL
163
162
* @return static
164
163
*/
165
164
public function setName ($ name )
166
165
{
167
- $ this ->name = ( string ) $ name ;
166
+ $ this ->name = $ name ;
168
167
return $ this ;
169
168
}
170
169
171
170
172
171
/**
173
- * @return string
172
+ * @return string|NULL
174
173
*/
175
174
public function getName ()
176
175
{
0 commit comments