Extract a top-level function definition.
(state: &mut ExtractionState, node: TsNode<'_>)
| 172 | |
| 173 | /// Extract a top-level function definition. |
| 174 | fn visit_function(state: &mut ExtractionState, node: TsNode<'_>) { |
| 175 | let name = find_direct_child_by_kind(node, "name") |
| 176 | .map_or_else(|| "<anonymous>".to_string(), |n| state.node_text(n)); |
| 177 | |
| 178 | let visibility = Visibility::Pub; |
| 179 | let signature = Some(Self::extract_function_signature(state, node)); |
| 180 | let docstring = Self::extract_docstring(state, node); |
| 181 | let start_line = node.start_position().row as u32; |
| 182 | let end_line = node.end_position().row as u32; |
| 183 | let start_column = node.start_position().column as u32; |
| 184 | let end_column = node.end_position().column as u32; |
| 185 | let qualified_name = format!("{}::{}", state.qualified_prefix(), name); |
| 186 | let id = generate_node_id(&state.file_path, &NodeKind::Function, &name, start_line); |
| 187 | let metrics = count_complexity(node, &PHP_COMPLEXITY, &state.source); |
| 188 | |
| 189 | let graph_node = Node { |
| 190 | id: id.clone(), |
| 191 | kind: NodeKind::Function, |
| 192 | name: name.clone(), |
| 193 | qualified_name, |
| 194 | file_path: state.file_path.clone(), |
| 195 | start_line, |
| 196 | attrs_start_line: start_line, |
| 197 | end_line, |
| 198 | start_column, |
| 199 | end_column, |
| 200 | signature, |
| 201 | docstring, |
| 202 | visibility, |
| 203 | is_async: false, |
| 204 | branches: metrics.branches, |
| 205 | loops: metrics.loops, |
| 206 | returns: metrics.returns, |
| 207 | max_nesting: metrics.max_nesting, |
| 208 | unsafe_blocks: metrics.unsafe_blocks, |
| 209 | unchecked_calls: metrics.unchecked_calls, |
| 210 | assertions: metrics.assertions, |
| 211 | updated_at: state.timestamp, |
| 212 | parent_id: None, |
| 213 | }; |
| 214 | state.nodes.push(graph_node); |
| 215 | |
| 216 | // Contains edge from parent. |
| 217 | if let Some(parent_id) = state.parent_node_id() { |
| 218 | state.edges.push(Edge { |
| 219 | source: parent_id.to_string(), |
| 220 | target: id.clone(), |
| 221 | kind: EdgeKind::Contains, |
| 222 | line: Some(start_line), |
| 223 | }); |
| 224 | } |
| 225 | |
| 226 | Self::extract_annotations(state, node, &id); |
| 227 | |
| 228 | // Extract call sites from the function body. |
| 229 | if let Some(body) = find_direct_child_by_kind(node, "compound_statement") { |
| 230 | Self::extract_call_sites(state, body, &id); |
| 231 | } |
nothing calls this directly
no test coverage detected