本文整理汇总了PHP中Parser::parseSnippet方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::parseSnippet方法的具体用法?PHP Parser::parseSnippet怎么用?PHP Parser::parseSnippet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::parseSnippet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInvalidCommentAbove
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidCommentAbove()
{
$original = '$value = variable_get("my_variable", NULL);';
/** @var StatementNode $statement_node */
$statement_node = Parser::parseSnippet($original);
$statement_node->addCommentAbove(NULL);
}
示例2: testCatches
public function testCatches()
{
/** @var \Pharborist\Exceptions\TryCatchNode $tryCatch */
$tryCatch = Parser::parseSnippet('try { foo(); } catch (\\InvalidArgumentException $e) {}');
$this->assertTrue($tryCatch->catches('\\InvalidArgumentException'));
$this->assertFalse($tryCatch->catches('\\DomainException'));
}
示例3: formatSnippet
protected function formatSnippet($snippet)
{
/** @var ParentNode $node */
$node = Parser::parseSnippet($snippet);
$this->formatter->format($node);
return $node->getText();
}
示例4: formatSnippet
protected function formatSnippet($snippet)
{
/** @var ParentNode $node */
$node = Parser::parseSnippet($snippet);
$formatter = FormatterFactory::getDrupalFormatter();
$formatter->format($node);
return $node->getText();
}
示例5: testGetPreviousCall
public function testGetPreviousCall()
{
$call = Parser::parseSnippet('\\Drupal::database()->insert("razmatazz");')->firstChild();
$this->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $call);
$this->assertInstanceOf('\\Pharborist\\Objects\\ClassMethodCallNode', $call->getPreviousCall());
$call = Parser::parseSnippet('$raz->matazz();')->firstChild();
$this->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $call);
$this->assertNull($call->getPreviousCall());
}
示例6: testSetName
public function testSetName()
{
/** @var \Pharborist\Objects\ClassNode $class */
$class = Parser::parseSnippet('class Foo { public function baz() {} }');
/** @var \Pharborist\Objects\ClassMethodNode $method */
$method = $class->getMethod('baz');
$method->setName('bar');
$this->assertEquals('bar', $method->getName()->getText());
$this->assertEquals('public function bar() {}', $method->getText());
}
示例7: testAppendStatement
public function testAppendStatement()
{
/** @var \Pharborist\ControlStructures\IfNode $ifNode */
$ifNode = Parser::parseSnippet('if (TRUE) { hello(); }');
/** @var StatementBlockNode $statementBlock */
$statementBlock = $ifNode->getThen();
$this->assertInstanceOf('\\Pharborist\\StatementBlockNode', $statementBlock);
$this->assertEquals('{ hello(); }', $statementBlock->getText());
$statementBlock->appendStatement(Parser::parseSnippet('world();'));
$this->assertEquals('{ hello(); world();}', $statementBlock->getText());
}
示例8: testGetConstants
public function testGetConstants()
{
/** @var \Pharborist\Objects\InterfaceNode $interface */
$interface = Parser::parseSnippet('interface Foo { const ANSWER = 42; }');
$constants = $interface->getConstants();
$this->assertCount(1, $constants);
/** @var \Pharborist\Constants\ConstantDeclarationNode $constant */
$constant = $constants[0];
$this->assertInstanceOf('\\Pharborist\\Constants\\ConstantDeclarationNode', $constant);
$this->assertEquals('ANSWER', $constant->getName());
$this->assertEquals('42', $constant->getValue()->getText());
}
示例9: testInvalid
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalid()
{
$snippet = <<<'EOF'
namespace Test {
function hello_world() {
echo 'hello world!', PHP_EOL;
}
}
EOF;
/** @var \Pharborist\Namespaces\NamespaceNode $namespace_node */
$namespace_node = Parser::parseSnippet($snippet);
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $namespace_node->getBody()->children(Filter::isFunction('hello_world'))[0];
$this->assertTrue($function->inNamespace(new \stdClass()));
}
示例10: uncomment
/**
* Uncomments the contents of this comment.
*
* @return Node
*/
public function uncomment()
{
/** @var CommentNode|LineCommentBlockNode $this */
return Parser::parseSnippet($this->getCommentText());
}
示例11: testSetImplementsStringArray
public function testSetImplementsStringArray()
{
/** @var \Pharborist\Objects\ClassNode $class */
$class = Parser::parseSnippet('class Foo {}');
$class->setImplements(['\\IteratorAggregate', '\\ArrayAccess']);
$implements = $class->getImplementList();
$this->assertInstanceOf('\\Pharborist\\CommaListNode', $implements);
$items = $implements->getItems();
$this->assertCount(2, $items);
$this->assertEquals('\\IteratorAggregate, \\ArrayAccess', $implements->getText());
}