function testIs() { $token = new Token('$'); $this->assertTrue($token->is('$')); $this->assertTrue($token->is('$', ':', '!')); $this->assertTrue($token->is('!', '?', ':', '$')); $this->assertFalse($token->is('!', '?', ':')); $this->assertFalse($token->is('$!')); $token = new Token(T_STRING); $this->assertFalse($token->is(T_OPEN_TAG, T_YIELD)); $this->assertTrue($token->is(T_STRING)); $token = new Token(T_STRING, '"value"', null); $this->assertFalse($token->is(T_OPEN_TAG, T_YIELD)); $this->assertTrue($token->is(T_CLOSE_TAG, T_STRING)); }
public function addToken(Token $token) { switch ($token->getType()) { // This block is basically a whitelist of token types permissible before // seeing a T_FUNCTION. If we hit anything else, the docblock isn't // attached to something we care about. case T_DOC_COMMENT: $this->docblock = $token; // fall through // fall through case T_WHITESPACE: case T_PUBLIC: case T_PROTECTED: case T_PRIVATE: case T_STATIC: case T_ABSTRACT: break; case Token::SINGLE_CHARACTER: if ($token->is('{')) { $this->has_started = true; $this->depth++; } elseif ($token->is('}')) { $this->depth--; } break; case T_FUNCTION: $this->track = false; break; case T_STRING: if (!$this->has_started) { $this->name = $token->getValue(); } // fall through // fall through default: if ($this->track) { $this->no_op = true; } break; } if ($this->has_started) { $this->body[] = $token; } else { $this->head[] = $token; } return $this; }
public function addToken(Token $token) { switch ($token->getType()) { case T_WHITESPACE: break; case T_VARIABLE: if ($this->current_th) { } else { $this->addProvidedTypehint(); } break; default: $this->current_th .= $token; break; } $this->tokens[] = $token; if ($token->is(',')) { $this->argno++; $this->current_th = ''; } }
/** * @internal */ protected function compareType(Token $token, $type) { if (!is_array($type)) { $type = array($type); } foreach ($type as $name) { if ($token->is($name)) { return true; } } return false; }