Ejemplo n.º 1
0
 /**
  * Accessor method for the tokens.
  *
  * It only tokenizes the file when the tokens are actually needed,
  * which increases performance in cases where you only need to
  * apply regex checks on the file. The result is cached afterwards.
  *
  * @return  array
  */
 public function tokens()
 {
     if ($this->_tokens === null) {
         $tokenized = Parser::tokenize($this->source(), $this->_config);
         $this->_tokens = $tokenized['tokens'];
         $this->_lineCache = $tokenized['lineCache'];
         $this->_typeCache = $tokenized['typeCache'];
     }
     return $this->_tokens;
 }
Ejemplo n.º 2
0
    public function testParseSwitchWithoutBreak()
    {
        $code = <<<EOD
switch (true) {
\tcase \$a:
\t\treturn \$value1;
\tcase \$b:
\t\treturn \$value2;
}
return false;
EOD;
        $tokenized = Parser::tokenize($code);
        $tokens = $tokenized['tokens'];
        $this->assertCount(34, $tokens);
        $this->assertIdentical('}', $tokens[28]['content']);
        $this->assertIdentical(0, $tokens[28]['nestLevel']);
    }