probe_code/language/
php.rs1use super::language_trait::LanguageImpl;
2use tree_sitter::{Language as TSLanguage, Node};
3
4pub struct PhpLanguage;
6
7impl Default for PhpLanguage {
8 fn default() -> Self {
9 Self::new()
10 }
11}
12
13impl PhpLanguage {
14 pub fn new() -> Self {
15 PhpLanguage
16 }
17}
18
19impl LanguageImpl for PhpLanguage {
20 fn get_tree_sitter_language(&self) -> TSLanguage {
21 tree_sitter_php::LANGUAGE_PHP.into()
22 }
23
24 fn get_extension(&self) -> &'static str {
25 "php"
26 }
27
28 fn is_acceptable_parent(&self, node: &Node) -> bool {
29 matches!(
30 node.kind(),
31 "function_definition"
32 | "method_declaration"
33 | "class_declaration"
34 | "interface_declaration"
35 | "trait_declaration"
36 )
37 }
38
39 fn is_test_node(&self, node: &Node, source: &[u8]) -> bool {
40 let debug_mode = std::env::var("DEBUG").unwrap_or_default() == "1";
41 let node_type = node.kind();
42
43 if node_type == "method_declaration" {
45 let mut cursor = node.walk();
46 for child in node.children(&mut cursor) {
47 if child.kind() == "name" {
48 let name = child.utf8_text(source).unwrap_or("");
49 if name.starts_with("test") {
50 if debug_mode {
51 println!("DEBUG: Test node detected (PHP): test method");
52 }
53 return true;
54 }
55 } else if child.kind() == "comment" {
56 let comment = child.utf8_text(source).unwrap_or("");
57 if comment.contains("@test") {
58 if debug_mode {
59 println!("DEBUG: Test node detected (PHP): @test annotation");
60 }
61 return true;
62 }
63 }
64 }
65 }
66
67 false
68 }
69}