Skip to content

Commit

Permalink
Merge pull request #624 from kkoomen/feature/php-use-statement-case
Browse files Browse the repository at this point in the history
PHP single name use statement case
  • Loading branch information
kkoomen authored Sep 19, 2023
2 parents 1f2d247 + 693bcc4 commit 686d889
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions helper/src/php/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,28 @@ impl<'a> PhpParser<'a> {
.count() > 0;

if !is_alias {
// Get the `qualified_name` node kind, which are
// usages like: `use Foo\Bar;`. We might also run
// into `use Foo;` which has the node kind `name`,
// which we ignore.
let fqn_node = child_node
.children(&mut child_node.walk())
.filter(|node| node.kind() == "qualified_name")
.next()
.unwrap();
.next();

if !fqn_node.is_some() {
continue;
}

let fqn_name = fqn_node
.children(&mut fqn_node.walk())
.unwrap()
.children(&mut fqn_node.unwrap().walk())
.filter(|node| node.kind() == "name")
.next()
.and_then(|node| Some(self.get_node_text(&node)));

if fqn_name.unwrap() == property_type {
let mut fqn_text = self.get_node_text(&fqn_node);
let mut fqn_text = self.get_node_text(&fqn_node.unwrap());

// Make sure FQN always starts with a backslash.
if !fqn_text.starts_with('\\') {
Expand Down
6 changes: 5 additions & 1 deletion test/filetypes/php/functions-with-namespaces.vader
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@

Given php (function where the type should result in its FQN):
<?php
use Closure;
use Exception;
use Symfony\Component\HttpFoundation\Response;

function myFunction(Response $p1): Response {}

Do (trigger doge):
:4\<CR>
:6\<CR>
\<C-d>

Expect php (generated comment containing the FQN):
<?php
use Closure;
use Exception;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down

0 comments on commit 686d889

Please sign in to comment.