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

Method extract_import

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

Source from the content-addressed store, hash-verified

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