File tree Expand file tree Collapse file tree 2 files changed +59
-10
lines changed Expand file tree Collapse file tree 2 files changed +59
-10
lines changed Original file line number Diff line number Diff line change @@ -351,17 +351,23 @@ public function getNumTestedFunctions()
351
351
*/
352
352
protected function calculateStatistics ()
353
353
{
354
- if ($ this ->cacheTokens ) {
355
- $ tokens = PHP_Token_Stream_CachingFactory::get ($ this ->getPath ());
356
- } else {
357
- $ tokens = new PHP_Token_Stream ($ this ->getPath ());
354
+ $ tokenizer = new Tokenizer ($ this ->getPath ());
355
+ $ classes = $ traits = $ functions = array ();
356
+ foreach ($ tokenizer as $ tokenName => $ token ) {
357
+ switch ($ tokenName ) {
358
+ case "class " :
359
+ $ classes [] = $ token ;
360
+ break ;
361
+ case "trait " :
362
+ $ traits [] = $ token ;
363
+ break ;
364
+ case "function " :
365
+ $ functions [] = $ token ;
366
+ break ;
367
+ }
358
368
}
359
-
360
- $ this ->processClasses ($ tokens ->getClasses ());
361
- $ this ->processTraits ($ tokens ->getTraits ());
362
- $ this ->processFunctions ($ tokens ->getFunctions ());
363
- $ this ->linesOfCode = $ tokens ->getLinesOfCode ();
364
- unset($ tokens );
369
+ $ this ->linesOfCode = $ tokenizer ->getLinesOfCode ();
370
+ unset($ tokenizer );
365
371
366
372
for ($ lineNumber = 1 ; $ lineNumber <= $ this ->linesOfCode ['loc ' ]; $ lineNumber ++) {
367
373
if (isset ($ this ->startLines [$ lineNumber ])) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class Tokenizer {
4
+ private $ tokens ;
5
+ private $ linesOfCode = array ('loc ' => 0 , 'cloc ' => 0 , 'ncloc ' => 0 );
6
+
7
+ public function __construct ($ filename ) {
8
+ $ this ->tokens = token_get_all ($ filename );
9
+ }
10
+
11
+ public function next () {
12
+ $ numTokens = count ($ this ->tokens );
13
+
14
+ for ($ i = 0 ; $ i < $ numTokens ; ++$ i ) {
15
+ if (is_array ($ token )) {
16
+ $ name = substr (token_name ($ token [0 ]), 2 );
17
+ $ text = $ token [1 ];
18
+
19
+ if ($ lastNonWhitespaceTokenWasDoubleColon && $ name == 'CLASS ' ) {
20
+ $ name = 'CLASS_NAME_CONSTANT ' ;
21
+ }
22
+
23
+ $ tokenClass = 'PHP_Token_ ' . $ name ;
24
+
25
+ } else {
26
+ $ text = $ token ;
27
+ $ tokenClass = self ::$ customTokens [$ token ];
28
+ }
29
+
30
+ if (false ) {
31
+ yield "class " => [];
32
+ } else if (false ) {
33
+ yield "trait " => [];
34
+ } else if (false ) {
35
+ yield "function " => [];
36
+ }
37
+ }
38
+ }
39
+
40
+ public function getLinesOfCode () {
41
+ return $ this ->linesOfCode ;
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments