MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_import

Method extract_import

codegraph-kernel/src/php.rs:873–979  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

871 }
872
873 fn extract_import(&mut self, node: Node<'t>) {
874 let kind = node.kind();
875 let import_text = self.text(node).trim().to_string();
876 let imports_kind = edge_kind_index("imports").unwrap();
877
878 if matches!(
879 kind,
880 "include_expression" | "include_once_expression" | "require_expression"
881 | "require_once_expression"
882 ) {
883 // phpStaticIncludePath: a string literal, or literals appended to
884 // the file's own directory or to `$_SERVER['DOCUMENT_ROOT']`
885 // (#3298); every other dynamic form (`$base . '/x'`, `$var`,
886 // interpolation) emits NOTHING.
887 let Some(module_name) = self.php_static_include_path(node) else { return };
888 if module_name.is_empty() {
889 return;
890 }
891 self.create_node(
892 "import",
893 &module_name,
894 node,
895 Extra { signature: Some(import_text), ..Extra::default() },
896 );
897 let parent = self.top_row();
898 self.push_ref_at(parent, &module_name.clone(), imports_kind, node);
899 return;
900 }
901
902 // namespace_use_declaration.
903 let ns_prefix = (0..node.named_child_count())
904 .filter_map(|i| node.named_child(i))
905 .find(|c| c.kind() == "namespace_name");
906 let use_group = (0..node.named_child_count())
907 .filter_map(|i| node.named_child(i))
908 .find(|c| c.kind() == "namespace_use_group");
909 if let (Some(ns_prefix), Some(use_group)) = (ns_prefix, use_group) {
910 // Grouped `use A\{B, C as D, Sub\E}` — hook declines, the inline
911 // branch emits per-member nodes named `A\B` (first `name` child =
912 // the SOURCE name; a nested `Sub\E` clause has a qualified_name,
913 // no direct `name` → SKIPPED, grammar-bump delta #2). All nodes
914 // and refs sit at the whole declaration's position.
915 let prefix = self.text(ns_prefix).to_string();
916 let clauses: Vec<Node> = (0..use_group.named_child_count())
917 .filter_map(|i| use_group.named_child(i))
918 .filter(|c| {
919 matches!(c.kind(), "namespace_use_group_clause" | "namespace_use_clause")
920 })
921 .collect();
922 for clause in clauses {
923 let ns_name = (0..clause.named_child_count())
924 .filter_map(|i| clause.named_child(i))
925 .find(|c| c.kind() == "namespace_name");
926 let name = match ns_name {
927 Some(nn) => (0..nn.named_child_count())
928 .filter_map(|i| nn.named_child(i))
929 .find(|c| c.kind() == "name"),
930 None => (0..clause.named_child_count())

Callers 2

visit_nodeMethod · 0.45

Calls 9

edge_kind_indexFunction · 0.85
push_php_use_refMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
create_nodeMethod · 0.45
top_rowMethod · 0.45
push_ref_atMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected