예제 #1
0
 public function testToken()
 {
     $token = new Token('T_STRING', 'The string value', 100);
     $this->assertEquals('T_STRING', $token->getType());
     $this->assertEquals('The string value', $token->getValue());
     $this->assertEquals(100, $token->getLine());
     $this->assertEquals(16, $token->getLength());
     $this->assertTrue($token->is('T_STRING'));
     $this->assertFalse($token->is('T_ARRAY'));
     $this->assertEquals('The string value', (string) $token);
 }
예제 #2
0
 /**
  * Parses method tokens
  *
  * @param TokenStream $stream     TokenStream object
  * @param Token       $visibility Token <TOKEN_PUBL> or <TOKEN_PROT> or <TOKEN_PRIV>
  * @param Token       $name       Token <TOKEN_NODE>
  */
 protected function parseMethod(TokenStream $stream, $visibility, $name)
 {
     switch ($visibility->getValue()) {
         case '+':
             $this->nodes[] = new Node(self::NODE_PUBLIC_METHOD, $name->getValue());
             break;
         case '#':
             $this->nodes[] = new Node(self::NODE_PROTECTED_METHOD, $name->getValue());
             break;
         case '-':
             $this->nodes[] = new Node(self::NODE_PRIVATE_METHOD, $name->getValue());
             break;
     }
     $stream->next();
     while (!$this->skip($stream)->is(Lexer::TOKEN_METC)) {
         $token = $stream->expect(Lexer::TOKEN_NODE);
         $this->nodes[] = new Node(self::NODE_ARGUMENT, $token->getValue());
         if ($this->skip($stream)->is(Lexer::TOKEN_TYPE)) {
             $stream->next();
             $token = $stream->expect(Lexer::TOKEN_NODE);
             $this->nodes[] = new Node(self::NODE_ARGUMENT_TYPE, $token->getValue());
         }
     }
     $stream->next();
     if ($this->skip($stream)->is(Lexer::TOKEN_TYPE)) {
         $stream->next();
         $token = $this->skip($stream)->expect(Lexer::TOKEN_NODE);
         $this->nodes[] = new Node(self::NODE_RETURN_TYPE, $token->getValue());
     }
     $this->parseComment($stream, self::NODE_METHOD_COMMENT);
 }