本文整理汇总了PHP中Filter::isInstanceOf方法的典型用法代码示例。如果您正苦于以下问题:PHP Filter::isInstanceOf方法的具体用法?PHP Filter::isInstanceOf怎么用?PHP Filter::isInstanceOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filter
的用法示例。
在下文中一共展示了Filter::isInstanceOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
/**
* {@inheritdoc}
*/
public function convert(TargetInterface $target)
{
$unit_tests = [];
$test_files = $target->getIndexer('class')->getQuery(['file'])->condition('parent', 'DrupalUnitTestCase')->execute()->fetchCol();
foreach ($test_files as $test_file) {
/** @var \Pharborist\Objects\Classnode[] $tests */
$tests = $target->open($test_file)->find(Filter::isInstanceOf('\\Pharborist\\Objects\\SingleInheritanceNode'))->toArray();
foreach ($tests as $test) {
if ((string) $test->getExtends() === 'DrupalUnitTestCase') {
$unit_tests[] = $test;
}
}
}
/** @var \Pharborist\Objects\ClassNode $unit_test */
foreach ($unit_tests as $unit_test) {
$unit_test->setExtends('\\Drupal\\Tests\\UnitTestCase');
$comment_text = <<<END
@FIXME
Unit tests are now written for the PHPUnit framework. You will need to refactor
this test in order for it to work properly.
END;
$comment = DocCommentNode::create($comment_text);
$unit_test->setDocComment($comment);
$ns = 'Drupal\\Tests\\' . $target->id() . '\\Unit';
$doc = RootNode::create($ns)->getNamespace($ns)->append($unit_test->remove());
WhitespaceNode::create("\n\n")->insertBefore($unit_test);
$this->write($target, 'tests/src/Unit/' . $unit_test->getName() . '.php', "<?php\n\n{$doc}");
}
}
示例2: getLineCount
/**
* Gets the number of lines spanned by this statement.
*
* @return integer
* Always returns at least one, because any statement will be at least
* one line long.
*/
public function getLineCount()
{
$count = 1;
$this->find(Filter::isInstanceOf('\\Pharborist\\WhitespaceNode'))->each(function (WhitespaceNode $node) use(&$count) {
$count += $node->getNewlineCount();
});
return $count;
}
示例3: testCreate
public function testCreate()
{
$doc = RootNode::create();
$this->assertEquals("<?php\n", $doc->getText());
$doc = RootNode::create('Pharborist\\Test');
$this->assertEquals("<?php\nnamespace Pharborist\\Test;\n", $doc->getText());
$ns = $doc->children(Filter::isInstanceOf('\\Pharborist\\Namespaces\\NamespaceNode'))[0];
$this->assertEquals('\\Pharborist\\Test', $ns->getName()->getAbsolutePath());
}
示例4: testIsInstanceOf
public function testIsInstanceOf()
{
$source = <<<'END'
<?php
$foo = 'baz';
function a() {}
class B {}
END;
$doc = Parser::parseSource($source);
$stuff = $doc->find(Filter::isInstanceOf('\\Pharborist\\Variables\\VariableNode', '\\Pharborist\\Functions\\FunctionDeclarationNode', '\\Pharborist\\Objects\\ClassNode'));
$this->assertCount(3, $stuff);
$this->assertInstanceOf('\\Pharborist\\Variables\\VariableNode', $stuff[0]);
$this->assertEquals('$foo', $stuff[0]);
$this->assertInstanceOf('\\Pharborist\\Functions\\FunctionDeclarationNode', $stuff[1]);
$this->assertEquals('function a() {}', $stuff[1]);
$this->assertInstanceOf('\\Pharborist\\Objects\\ClassNode', $stuff[2]);
$this->assertEquals('class B {}', $stuff[2]);
}
示例5: addIndent
/**
* Add indent to comment.
*
* @param string $whitespace
* Additional whitespace to add.
* @return $this
*/
public function addIndent($whitespace)
{
$has_indent = $this->children(function (Node $node) {
return !$node instanceof CommentNode;
})->count() > 0;
if ($has_indent) {
$this->children(Filter::isInstanceOf('\\Pharborist\\WhitespaceNode'))->each(function (WhitespaceNode $ws_node) use($whitespace) {
$ws_node->setText($ws_node->getText() . $whitespace);
});
} else {
$this->children()->before(Token::whitespace($whitespace));
}
return $this;
}