@@ -70,8 +70,8 @@ class PHP_CodeCoverage_Util
7070 * @var array
7171 */
7272 protected static $ cache = array (
73- 'classesFunctionsCache ' => array (),
74- 'getLinesToBeIgnored ' => array ()
73+ 'classesFunctions ' => array (),
74+ 'ignoredLines ' => array ()
7575 );
7676
7777 /**
@@ -237,11 +237,11 @@ public static function getDirectory($directory)
237237 public static function getClassesInFile ($ filename , $ useCache = TRUE )
238238 {
239239 if (!$ useCache ||
240- !isset (self ::$ cache ['classesFunctionsCache ' ][$ filename ])) {
240+ !isset (self ::$ cache ['classesFunctions ' ][$ filename ])) {
241241 self ::parseFile ($ filename );
242242 }
243243
244- return self ::$ cache ['classesFunctionsCache ' ][$ filename ]['classes ' ];
244+ return self ::$ cache ['classesFunctions ' ][$ filename ]['classes ' ];
245245 }
246246
247247 /**
@@ -254,11 +254,11 @@ public static function getClassesInFile($filename, $useCache = TRUE)
254254 public static function getFunctionsInFile ($ filename , $ useCache = TRUE )
255255 {
256256 if (!$ useCache ||
257- !isset (self ::$ cache ['classesFunctionsCache ' ][$ filename ])) {
257+ !isset (self ::$ cache ['classesFunctions ' ][$ filename ])) {
258258 self ::parseFile ($ filename );
259259 }
260260
261- return self ::$ cache ['classesFunctionsCache ' ][$ filename ]['functions ' ];
261+ return self ::$ cache ['classesFunctions ' ][$ filename ]['functions ' ];
262262 }
263263
264264 /**
@@ -326,8 +326,10 @@ public static function getLinesToBeCovered($className, $methodName)
326326 */
327327 public static function getLinesToBeIgnored ($ filename )
328328 {
329- if (!isset (self ::$ cache ['getLinesToBeIgnored ' ][$ filename ])) {
330- self ::$ cache ['getLinesToBeIgnored ' ][$ filename ] = array ();
329+ $ cache = &self ::$ cache ['ignoredLines ' ];
330+
331+ if (!isset ($ cache [$ filename ])) {
332+ $ cache [$ filename ] = array ();
331333
332334 $ ignore = FALSE ;
333335 $ lineNum = 1 ;
@@ -340,7 +342,7 @@ public static function getLinesToBeIgnored($filename)
340342 }
341343
342344 if ($ ignore ) {
343- self :: $ cache[ ' getLinesToBeIgnored ' ] [$ filename ][$ lineNum ] = TRUE ;
345+ $ cache [$ filename ][$ lineNum ] = TRUE ;
344346
345347 if ($ trimmedLine == '// @codeCoverageIgnoreEnd ' ) {
346348 $ ignore = FALSE ;
@@ -351,7 +353,7 @@ public static function getLinesToBeIgnored($filename)
351353 }
352354 }
353355
354- return self :: $ cache[ ' getLinesToBeIgnored ' ] [$ filename ];
356+ return $ cache [$ filename ];
355357 }
356358
357359 /**
@@ -568,50 +570,48 @@ protected static function arrayToName(array $parts, $join = '\\')
568570 */
569571 protected static function parseFile ($ filename )
570572 {
571- self ::$ cache ['classesFunctionsCache ' ][$ filename ] = array (
573+ self ::$ cache ['classesFunctions ' ][$ filename ] = array (
572574 'classes ' => array (), 'functions ' => array ()
573575 );
574576
575- $ tokens = token_get_all (
576- file_get_contents ($ filename )
577- );
578- $ numTokens = count ($ tokens );
579- $ blocks = array ();
580- $ line = 1 ;
581- $ currentBlock = FALSE ;
582- $ currentNamespace = FALSE ;
583- $ currentClass = FALSE ;
584- $ currentFunction = FALSE ;
585- $ currentFunctionCCN = 1 ;
586- $ currentFunctionStartLine = FALSE ;
587- $ currentDocComment = FALSE ;
588- $ currentSignature = FALSE ;
589- $ currentSignatureStartToken = FALSE ;
577+ $ cache = &self ::$ cache ['classesFunctions ' ][$ filename ];
578+ $ tokens = token_get_all (file_get_contents ($ filename ));
579+ $ numTokens = count ($ tokens );
580+ $ blocks = array ();
581+ $ line = 1 ;
582+ $ currentBlock = FALSE ;
583+ $ namespace = FALSE ;
584+ $ class = FALSE ;
585+ $ function = FALSE ;
586+ $ functionCCN = 1 ;
587+ $ functionStartLine = FALSE ;
588+ $ currentDocComment = FALSE ;
589+ $ signature = FALSE ;
590+ $ signatureStartToken = FALSE ;
590591
591592 for ($ i = 0 ; $ i < $ numTokens ; $ i ++) {
592593 if (is_string ($ tokens [$ i ])) {
593594 $ token = trim ($ tokens [$ i ]);
594595
595596 if ($ token == '{ ' ) {
596597 if ($ currentBlock == T_CLASS ) {
597- $ block = $ currentClass ;
598+ $ block = $ class ;
598599 }
599600
600601 else if ($ currentBlock == T_FUNCTION ) {
601- $ currentSignature = '' ;
602+ $ signature = '' ;
602603
603- for ($ j = $ currentSignatureStartToken ; $ j < $ i ; $ j ++) {
604+ for ($ j = $ signatureStartToken ; $ j < $ i ; $ j ++) {
604605 if (is_string ($ tokens [$ j ])) {
605- $ currentSignature .= $ tokens [$ j ];
606+ $ signature .= $ tokens [$ j ];
606607 } else {
607- $ currentSignature .= $ tokens [$ j ][1 ];
608+ $ signature .= $ tokens [$ j ][1 ];
608609 }
609610 }
610611
611- $ currentSignature = trim ($ currentSignature );
612-
613- $ block = $ currentFunction ;
614- $ currentSignatureStartToken = FALSE ;
612+ $ block = $ function ;
613+ $ signatureStartToken = FALSE ;
614+ $ signature = trim ($ signature );
615615 }
616616
617617 else {
@@ -627,7 +627,7 @@ protected static function parseFile($filename)
627627 $ block = array_pop ($ blocks );
628628
629629 if ($ block !== FALSE && $ block !== NULL ) {
630- if ($ block == $ currentFunction ) {
630+ if ($ block == $ function ) {
631631 if ($ currentDocComment !== FALSE ) {
632632 $ docComment = $ currentDocComment ;
633633 $ currentDocComment = FALSE ;
@@ -637,47 +637,46 @@ protected static function parseFile($filename)
637637
638638 $ tmp = array (
639639 'docComment ' => $ docComment ,
640- 'signature ' => $ currentSignature ,
641- 'startLine ' => $ currentFunctionStartLine ,
640+ 'signature ' => $ signature ,
641+ 'startLine ' => $ functionStartLine ,
642642 'endLine ' => $ line ,
643- 'ccn ' => $ currentFunctionCCN
643+ 'ccn ' => $ functionCCN
644644 );
645645
646- if ($ currentClass === FALSE ) {
647- self :: $ cache ['classesFunctionsCache ' ][ $ filename ][ ' functions ' ][$ currentFunction ] = $ tmp ;
646+ if ($ class === FALSE ) {
647+ $ cache ['functions ' ][$ function ] = $ tmp ;
648648 } else {
649- self :: $ cache ['classesFunctionsCache ' ][ $ filename ][ ' classes ' ][$ currentClass ]['methods ' ][$ currentFunction ] = $ tmp ;
649+ $ cache ['classes ' ][$ class ]['methods ' ][$ function ] = $ tmp ;
650650 }
651651
652- $ currentFunction = FALSE ;
653- $ currentFunctionCCN = 1 ;
654- $ currentFunctionStartLine = FALSE ;
655- $ currentSignature = FALSE ;
652+ $ function = FALSE ;
653+ $ functionCCN = 1 ;
654+ $ functionStartLine = FALSE ;
655+ $ signature = FALSE ;
656656 }
657657
658- else if ($ block == $ currentClass ) {
659- self ::$ cache ['classesFunctionsCache ' ][$ filename ]['classes ' ][$ currentClass ]['endLine ' ] = $ line ;
660-
661- $ currentClass = FALSE ;
662- $ currentClassStartLine = FALSE ;
658+ else if ($ block == $ class ) {
659+ $ cache ['classes ' ][$ class ]['endLine ' ] = $ line ;
660+ $ class = FALSE ;
661+ $ classStartLine = FALSE ;
663662 }
664663 }
665664 }
666665
667666 else if ($ token == '? ' ) {
668- $ currentFunctionCCN ++;
667+ $ functionCCN ++;
669668 }
670669
671670 continue ;
672671 }
673672
674673 switch ($ tokens [$ i ][0 ]) {
675674 case T_NAMESPACE : {
676- $ currentNamespace = $ tokens [$ i +2 ][1 ];
675+ $ namespace = $ tokens [$ i +2 ][1 ];
677676
678677 for ($ j = $ i +3 ; $ j < $ numTokens ; $ j += 2 ) {
679678 if ($ tokens [$ j ][0 ] == T_NS_SEPARATOR ) {
680- $ currentNamespace .= '\\' . $ tokens [$ j +1 ][1 ];
679+ $ namespace .= '\\' . $ tokens [$ j +1 ][1 ];
681680 } else {
682681 break ;
683682 }
@@ -700,11 +699,10 @@ protected static function parseFile($filename)
700699 case T_CLASS : {
701700 $ currentBlock = T_CLASS ;
702701
703- if ($ currentNamespace === FALSE ) {
704- $ currentClass = $ tokens [$ i +2 ][1 ];
702+ if ($ namespace === FALSE ) {
703+ $ class = $ tokens [$ i +2 ][1 ];
705704 } else {
706- $ currentClass = $ currentNamespace . '\\' .
707- $ tokens [$ i +2 ][1 ];
705+ $ class = $ namespace . '\\' . $ tokens [$ i +2 ][1 ];
708706 }
709707
710708 if ($ currentDocComment !== FALSE ) {
@@ -714,7 +712,7 @@ protected static function parseFile($filename)
714712 $ docComment = '' ;
715713 }
716714
717- self :: $ cache ['classesFunctionsCache ' ][ $ filename ][ ' classes ' ][$ currentClass ] = array (
715+ $ cache ['classes ' ][$ class ] = array (
718716 'methods ' => array (),
719717 'docComment ' => $ docComment ,
720718 'startLine ' => $ line
@@ -732,27 +730,26 @@ protected static function parseFile($filename)
732730 continue ;
733731 }
734732
735- $ currentBlock = T_FUNCTION ;
736- $ currentFunctionStartLine = $ line ;
737-
738- $ done = FALSE ;
739- $ currentSignatureStartToken = $ i - 1 ;
733+ $ currentBlock = T_FUNCTION ;
734+ $ functionStartLine = $ line ;
735+ $ done = FALSE ;
736+ $ signatureStartToken = $ i - 1 ;
740737
741738 do {
742- switch ($ tokens [$ currentSignatureStartToken ][0 ]) {
739+ switch ($ tokens [$ signatureStartToken ][0 ]) {
743740 case T_ABSTRACT :
744741 case T_FINAL :
745742 case T_PRIVATE :
746743 case T_PUBLIC :
747744 case T_PROTECTED :
748745 case T_STATIC :
749746 case T_WHITESPACE : {
750- $ currentSignatureStartToken --;
747+ $ signatureStartToken --;
751748 }
752749 break ;
753750
754751 default : {
755- $ currentSignatureStartToken ++;
752+ $ signatureStartToken ++;
756753 $ done = TRUE ;
757754 }
758755 }
@@ -767,11 +764,10 @@ protected static function parseFile($filename)
767764 $ functionName = $ tokens [$ i +3 ][1 ];
768765 }
769766
770- if ($ currentNamespace === FALSE ) {
771- $ currentFunction = $ functionName ;
767+ if ($ namespace === FALSE ) {
768+ $ function = $ functionName ;
772769 } else {
773- $ currentFunction = $ currentNamespace . '\\' .
774- $ functionName ;
770+ $ function = $ namespace . '\\' . $ functionName ;
775771 }
776772 }
777773 break ;
@@ -792,7 +788,7 @@ protected static function parseFile($filename)
792788 case T_LOGICAL_AND :
793789 case T_BOOLEAN_OR :
794790 case T_LOGICAL_OR : {
795- $ currentFunctionCCN ++;
791+ $ functionCCN ++;
796792 }
797793 break ;
798794 }
0 commit comments