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

Method extract_import

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

Source from the content-addressed store, hash-verified

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