phpShadowsDirname (#3298): whether an unqualified `dirname(...)` in this file reaches a function other than PHP's — one a `use function` imports under that name, or one the file declares when it has a namespace. Read once per file, from every node of the tree (descendantsOfType: named and anonymous, document order).
(&mut self)
| 1103 | /// namespace. Read once per file, from every node of the tree |
| 1104 | /// (descendantsOfType: named and anonymous, document order). |
| 1105 | fn php_shadows_dirname(&mut self) -> bool { |
| 1106 | if let Some(shadowed) = self.dirname_shadowed { |
| 1107 | return shadowed; |
| 1108 | } |
| 1109 | let mut uses: Vec<Node<'t>> = Vec::new(); |
| 1110 | let mut functions: Vec<Node<'t>> = Vec::new(); |
| 1111 | let mut has_namespace = false; |
| 1112 | let mut cursor = self.root.walk(); |
| 1113 | 'walk: loop { |
| 1114 | let n = cursor.node(); |
| 1115 | match n.kind() { |
| 1116 | "namespace_use_declaration" => uses.push(n), |
| 1117 | "namespace_definition" => has_namespace = true, |
| 1118 | "function_definition" => functions.push(n), |
| 1119 | _ => {} |
| 1120 | } |
| 1121 | if cursor.goto_first_child() { |
| 1122 | continue; |
| 1123 | } |
| 1124 | while !cursor.goto_next_sibling() { |
| 1125 | if !cursor.goto_parent() { |
| 1126 | break 'walk; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | let mut shadowed = uses.iter().any(|u| php_use_shadows_dirname(self.text(*u))); |
| 1131 | if !shadowed && has_namespace { |
| 1132 | shadowed = functions.iter().any(|f| { |
| 1133 | f.child_by_field_name("name") |
| 1134 | .is_some_and(|name| self.text(name).to_lowercase() == "dirname") |
| 1135 | }); |
| 1136 | } |
| 1137 | self.dirname_shadowed = Some(shadowed); |
| 1138 | shadowed |
| 1139 | } |
| 1140 | |
| 1141 | // --- calls --------------------------------------------------------------------- |
| 1142 |
no test coverage detected