36
36
*/
37
37
namespace TheSeer \phpDox \Collector \Backend {
38
38
39
- use TheSeer \DirectoryScanner \Exception ;
40
39
use TheSeer \phpDox \Collector \AbstractUnitObject ;
41
40
use TheSeer \phpDox \Collector \AbstractVariableObject ;
42
41
use TheSeer \phpDox \Collector \InlineComment ;
@@ -92,13 +91,15 @@ public function __construct(DocBlockParser $parser, ParseResult $result) {
92
91
93
92
/**
94
93
* @param \PhpParser\Node $node
94
+ *
95
+ * @return int|null|\PhpParser\Node|void
95
96
*/
96
97
public function enterNode (\PhpParser \Node $ node ) {
97
98
if ($ node instanceof NodeType \Namespace_ && $ node ->name != NULL ) {
98
- $ this ->namespace = join ('\\' , $ node ->name ->parts );
99
+ $ this ->namespace = implode ('\\' , $ node ->name ->parts );
99
100
$ this ->aliasMap ['::context ' ] = $ this ->namespace ;
100
101
} else if ($ node instanceof NodeType \UseUse) {
101
- $ this ->aliasMap [$ node ->alias ] = join ('\\' , $ node ->name ->parts );
102
+ $ this ->aliasMap [$ node ->alias ] = implode ('\\' , $ node ->name ->parts );
102
103
} else if ($ node instanceof NodeType \Class_) {
103
104
$ this ->aliasMap ['::unit ' ] = (string )$ node ->namespacedName ;
104
105
$ this ->unit = $ this ->result ->addClass ((string )$ node ->namespacedName );
@@ -129,6 +130,8 @@ public function enterNode(\PhpParser\Node $node) {
129
130
130
131
/**
131
132
* @param \PhpParser\Node $node
133
+ *
134
+ * @return false|int|null|\PhpParser\Node|\PhpParser\Node[]|void
132
135
*/
133
136
public function leaveNode (\PhpParser \Node $ node ) {
134
137
if ($ node instanceof NodeType \Class_
@@ -159,20 +162,13 @@ private function processUnit($node) {
159
162
$ this ->unit ->setDocBlock ($ block );
160
163
}
161
164
162
- if ($ node ->getType () != 'Stmt_Trait ' && $ node ->extends != NULL ) {
163
- if (is_array ($ node ->extends )) {
164
- foreach ($ node ->extends as $ extends ) {
165
- $ this ->unit ->addExtends (join ('\\' , $ extends ->parts ));
166
- }
167
- } else {
168
- $ this ->unit ->addExtends (join ('\\' , $ node ->extends ->parts ));
169
- }
170
-
165
+ if ($ node ->getType () !== 'Stmt_Trait ' && $ node ->extends != NULL ) {
166
+ $ this ->unit ->addExtends (implode ('\\' , $ node ->extends ->parts ));
171
167
}
172
168
173
- if ($ node ->getType () == 'Stmt_Class ' ) {
169
+ if ($ node ->getType () === 'Stmt_Class ' ) {
174
170
foreach ($ node ->implements as $ implements ) {
175
- $ this ->unit ->addImplements (join ('\\' , $ implements ->parts ));
171
+ $ this ->unit ->addImplements (implode ('\\' , $ implements ->parts ));
176
172
}
177
173
}
178
174
}
@@ -345,22 +341,30 @@ private function processProperty(NodeType\Property $node) {
345
341
}
346
342
347
343
private function setVariableType (AbstractVariableObject $ variable , $ type = NULL ) {
344
+ if ($ type instanceof \PhpParser \Node \NullableType) {
345
+ $ variable ->setNullable (true );
346
+ $ type = $ type ->type ;
347
+ }
348
+
348
349
if ($ type === NULL ) {
349
350
$ variable ->setType ('{unknown} ' );
350
351
return ;
351
352
}
352
- if ($ type === 'array ' ) {
353
- $ variable ->setType ('array ' );
353
+
354
+ if ($ variable ->isInternalType ($ type )) {
355
+ $ variable ->setType ($ type );
354
356
return ;
355
357
}
358
+
356
359
if ($ type instanceof \PhpParser \Node \Name \FullyQualified) {
357
360
$ variable ->setType ( (string )$ type );
358
361
return ;
359
362
}
363
+
360
364
$ type = (string )$ type ;
361
365
if (isset ($ this ->aliasMap [$ type ])) {
362
366
$ type = $ this ->aliasMap [$ type ];
363
- } elseif ($ type [0 ]!='\\' ) {
367
+ } elseif ($ type [0 ]!== '\\' ) {
364
368
$ type = $ this ->namespace . '\\' . $ type ;
365
369
}
366
370
$ variable ->setType ($ type );
@@ -401,12 +405,17 @@ private function resolveExpressionValue(\PhpParser\Node\Expr $expr) {
401
405
return array (
402
406
'type ' => '{unknown} ' ,
403
407
'value ' => '' ,
404
- 'constant ' => join ('\\' , $ expr ->class ->parts ) . ':: ' . $ expr ->name
408
+ 'constant ' => implode ('\\' , $ expr ->class ->parts ) . ':: ' . $ expr ->name
405
409
);
406
410
}
407
411
408
412
if ($ expr instanceof \PhpParser \Node \Expr \ConstFetch) {
409
- $ reference = join ('\\' , $ expr ->name ->parts );
413
+ $ reference = implode ('\\' , $ expr ->name ->parts );
414
+ if (strtolower ($ reference ) === 'null ' ) {
415
+ return array (
416
+ 'value ' => 'NULL '
417
+ );
418
+ }
410
419
if (in_array (strtolower ($ reference ), array ('true ' , 'false ' ))) {
411
420
return array (
412
421
'type ' => 'boolean ' ,
@@ -416,7 +425,7 @@ private function resolveExpressionValue(\PhpParser\Node\Expr $expr) {
416
425
return array (
417
426
'type ' => '{unknown} ' ,
418
427
'value ' => '' ,
419
- 'constant ' => join ('\\' , $ expr ->name ->parts )
428
+ 'constant ' => implode ('\\' , $ expr ->name ->parts )
420
429
);
421
430
}
422
431
@@ -452,9 +461,14 @@ private function setVariableDefaultValue(AbstractVariableObject $variable, \PhpP
452
461
if ($ default === NULL ) {
453
462
return ;
454
463
}
464
+
455
465
$ resolved = $ this ->resolveExpressionValue ($ default );
456
- $ variable ->setType ($ resolved ['type ' ]);
457
466
$ variable ->setDefault ($ resolved ['value ' ]);
467
+
468
+ if (isset ($ resolved ['type ' ])) {
469
+ $ variable ->setType ($ resolved ['type ' ]);
470
+ }
471
+
458
472
if (isset ($ resolved ['constant ' ])) {
459
473
$ variable ->setConstant ($ resolved ['constant ' ]);
460
474
}
0 commit comments