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

Method extract_import

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

Source from the content-addressed store, hash-verified

869 }
870
871 fn extract_import(&mut self, node: Node<'t>) {
872 let kind = node.kind();
873 let import_text = self.text(node).trim().to_string();
874 let imports_kind = edge_kind_index("imports").unwrap();
875
876 if matches!(
877 kind,
878 "include_expression" | "include_once_expression" | "require_expression"
879 | "require_once_expression"
880 ) {
881 // phpStaticIncludePath: static string literals only; dynamic
882 // forms (`__DIR__ . '/x'`, interpolation) emit NOTHING.
883 let mut arg = node.named_child(0);
884 if let Some(a) = arg {
885 if a.kind() == "parenthesized_expression" {
886 arg = a.named_child(0);
887 }
888 }
889 let Some(arg) = arg else { return };
890 if !matches!(arg.kind(), "string" | "encapsed_string") {
891 return;
892 }
893 let mut content: Option<Node> = None;
894 for i in 0..arg.named_child_count() {
895 let Some(c) = arg.named_child(i) else { continue };
896 if c.kind() != "string_content" {
897 return; // interpolation/escape → not a static path
898 }
899 if content.is_none() {
900 content = Some(c);
901 }
902 }
903 let Some(content) = content else { return };
904 let module_name = self.text(content).to_string();
905 if module_name.is_empty() {
906 return;
907 }
908 self.create_node(
909 "import",
910 &module_name,
911 node,
912 Extra { signature: Some(import_text), ..Extra::default() },
913 );
914 let parent = self.top_row();
915 self.push_ref_at(parent, &module_name.clone(), imports_kind, node);
916 return;
917 }
918
919 // namespace_use_declaration.
920 let ns_prefix = (0..node.named_child_count())
921 .filter_map(|i| node.named_child(i))
922 .find(|c| c.kind() == "namespace_name");
923 let use_group = (0..node.named_child_count())
924 .filter_map(|i| node.named_child(i))
925 .find(|c| c.kind() == "namespace_use_group");
926 if let (Some(ns_prefix), Some(use_group)) = (ns_prefix, use_group) {
927 // Grouped `use A\{B, C as D, Sub\E}` — hook declines, the inline
928 // branch emits per-member nodes named `A\B` (first `name` child =

Callers 1

visit_nodeMethod · 0.45

Calls 8

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