@@ -88,7 +88,7 @@ private function tname(array $tokens, $idx) {
88
88
if ($ tconst === T_STRING ) {
89
89
$ name = $ this ->tstring ($ token );
90
90
break ;
91
- } elseif ($ tconst === T_STRING && $ tclass === 'PHP_Token_AMPERSAND ' && $ this ->tconst ($ tokens [$ i +1 ]) === T_STRING ) {
91
+ } elseif ($ tclass === 'PHP_Token_AMPERSAND ' && $ this ->tconst ($ tokens [$ i +1 ]) === T_STRING ) {
92
92
$ name = $ this ->tstring ($ tokens [$ i +1 ]);
93
93
break ;
94
94
} elseif ($ tclass === 'PHP_Token_OPEN_BRACKET ' ) {
@@ -105,7 +105,7 @@ private function tname(array $tokens, $idx) {
105
105
break ;
106
106
}
107
107
108
- if ($ tconst === T_INTERFACE ) {
108
+ if ($ tconst === T_INTERFACE || $ tconst === T_CLASS || $ tconst === T_TRAIT ) {
109
109
break ;
110
110
}
111
111
}
@@ -114,7 +114,7 @@ private function tname(array $tokens, $idx) {
114
114
return $ name ;
115
115
}
116
116
117
- if ($ tconst === T_CLASS || $ tconst === T_TRAIT ) {
117
+ if ($ tconst === T_INTERFACE || $ tconst === T_CLASS || $ tconst === T_TRAIT ) {
118
118
return $ this ->tstring ($ tokens [$ idx + 2 ]);
119
119
}
120
120
@@ -262,7 +262,7 @@ private function getDocblock(array $tokens, $idx) {
262
262
continue ;
263
263
}
264
264
265
- if ($ line < $ currentLineNumber && $ tconst = == T_DOC_COMMENT ) {
265
+ if ($ line < $ currentLineNumber && $ tconst ! == T_DOC_COMMENT ) {
266
266
break ;
267
267
}
268
268
@@ -390,7 +390,7 @@ private function getSignature(array $tokens, $idx)
390
390
$ i = $ idx + 2 ;
391
391
}
392
392
393
- while (isset ($ tokens [$ i ]) && $ tclass = $ this ->tclass ($ tokens [$ i ]) &&
393
+ while (isset ($ tokens [$ i ]) && ( $ tclass = $ this ->tclass ($ tokens [$ i ]) ) &&
394
394
$ tclass !== 'PHP_Token_OPEN_CURLY ' &&
395
395
$ tclass !== 'PHP_Token_SEMICOLON ' ) {
396
396
$ signature .= $ this ->tstring ($ tokens [$ i ++]);
@@ -459,6 +459,12 @@ public function tokenize() {
459
459
$ line += $ lines ;
460
460
}
461
461
462
+ $ class = false ;
463
+ $ classEndLine = false ;
464
+ $ trait = false ;
465
+ $ traitEndLine = false ;
466
+ $ interface = false ;
467
+ $ interfaceEndLine = false ;
462
468
$ line = 1 ;
463
469
for ($ i = 0 ; $ i < $ numTokens ; ++$ i ) {
464
470
$ token = $ tokens [$ i ];
@@ -473,8 +479,27 @@ public function tokenize() {
473
479
$ tokenClass = self ::$ customTokens [$ token ];
474
480
}
475
481
482
+ $ lines = substr_count ($ text , "\n" );
483
+ $ line += $ lines ;
484
+
476
485
switch ($ tokenClass ) {
477
486
case 'PHP_Token_HALT_COMPILER ' :
487
+ break 2 ;
488
+
489
+ case 'PHP_Token_INTERFACE ' :
490
+ $ interface = $ this ->tname ($ tokens , $ i );
491
+ $ interfaceEndLine = $ this ->getEndLine ($ tokens , $ i );
492
+
493
+ $ this ->interfaces [$ interface ] = array (
494
+ 'methods ' => array (),
495
+ 'parent ' => $ this ->getParent ($ tokens , $ i ),
496
+ 'keywords ' => $ this ->getKeywords ($ tokens , $ i ),
497
+ 'docblock ' => $ this ->getDocblock ($ tokens , $ i ),
498
+ 'startLine ' => $ this ->tline ($ i ),
499
+ 'endLine ' => $ interfaceEndLine ,
500
+ 'package ' => $ this ->getPackage ($ tokens , $ i ),
501
+ 'file ' => $ this ->filename
502
+ );
478
503
break ;
479
504
480
505
case 'PHP_Token_CLASS ' :
@@ -493,19 +518,20 @@ public function tokenize() {
493
518
'file ' => $ this ->filename
494
519
);
495
520
496
- if ($ this ->tconst ($ token ) === T_CLASS ) {
497
- $ class = $ this ->tname ($ tokens , $ i + 2 );
521
+ $ tclass = $ this ->tclass ($ token );
522
+ if ($ tclass === 'PHP_Token_CLASS ' ) {
523
+ $ class = $ this ->tname ($ tokens , $ i );
498
524
$ classEndLine = $ endLine ;
499
525
$ this ->classes [$ class ] = $ tmp ;
500
526
} else {
501
- $ trait = $ this ->tname ($ tokens , $ i + 2 );
527
+ $ trait = $ this ->tname ($ tokens , $ i );
502
528
$ traitEndLine = $ endLine ;
503
529
$ this ->traits [$ trait ] = $ tmp ;
504
530
}
505
531
break ;
506
532
507
533
case 'PHP_Token_FUNCTION ' :
508
- $ tname = $ this ->tname ($ tokens , $ idx );
534
+ $ tname = $ this ->tname ($ tokens , $ i );
509
535
$ tmp = array (
510
536
'docblock ' => $ this ->getDocblock ($ tokens , $ i ),
511
537
'keywords ' => $ this ->getKeywords ($ tokens , $ i ),
@@ -547,14 +573,10 @@ public function tokenize() {
547
573
$ this ->linesOfCode ['cloc ' ] += $ lines + 1 ;
548
574
break ;
549
575
}
550
-
551
- $ lines = substr_count ($ text , "\n" );
552
- $ line += $ lines ;
553
576
}
554
577
555
578
$ this ->linesOfCode ['loc ' ] = substr_count ($ sourceCode , "\n" );
556
- $ this ->linesOfCode ['ncloc ' ] = $ this ->linesOfCode ['loc ' ] -
557
- $ this ->linesOfCode ['cloc ' ];
579
+ $ this ->linesOfCode ['ncloc ' ] = $ this ->linesOfCode ['loc ' ] - $ this ->linesOfCode ['cloc ' ];
558
580
}
559
581
560
582
public function getLinesOfCode () {
0 commit comments