sebastianbergmann / php-token-stream

Wrapper around PHP's tokenizer extension.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@codeCoverageIgnore

eskwayrd opened this issue · comments

@codeCoverageIgnore has no effect when the method we wish to ignore is:

/**
 * @codeCoverageIgnore
 */
final private function __construct() {}

The problem is in Token.php, line 119:

    for ($i = $this->id - 2; $i > $this->id - 6; $i -= 2) {

The comparison should be '>=' instead of '>', or the lower bound should be 8 instead of 6.

The code in the master branch (which will become PHP_TokenStream 1.1 to be used by PHP_CodeCoverage 1.1 and PHPUnit 3.6) is different:

public function getDocblock()
{
    $tokens            = $this->tokenStream->tokens();
    $currentLineNumber = $tokens[$this->id]->getLine();
    $prevLineNumber    = $currentLineNumber - 1;

    for ($i = $this->id - 1; $i; $i--) {
        if (!isset($tokens[$i])) {
            return;
        }

        if ($tokens[$i] instanceof PHP_Token_FUNCTION ||
            $tokens[$i] instanceof PHP_Token_CLASS ||
            $tokens[$i] instanceof PHP_Token_TRAIT) {
            // Some other trait, class or function, no docblock can be
            // used for the current token
            break;
        }

        $line = $tokens[$i]->getLine();

        if ($line == $currentLineNumber ||
            ($line == $prevLineNumber &&
             $tokens[$i] instanceof PHP_Token_WHITESPACE)) {
            continue;
        }

        if ($line < $currentLineNumber &&
            !$tokens[$i] instanceof PHP_Token_DOC_COMMENT) {
            break;
        }

        return (string)$tokens[$i];
    }
}

If the problem persist with PHP_TokenStream 1.1 and PHP_CodeCoverage 1.1 please open a new ticket. Thanks!