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)
| 1117 | /// namespace. Read once per file, from every node of the tree |
| 1118 | /// (descendantsOfType: named and anonymous, document order). |
| 1119 | fn php_shadows_dirname(&mut self) -> bool { |
| 1120 | if let Some(shadowed) = self.dirname_shadowed { |
| 1121 | return shadowed; |
| 1122 | } |
| 1123 | let mut uses: Vec<Node<'t>> = Vec::new(); |
| 1124 | let mut functions: Vec<Node<'t>> = Vec::new(); |
| 1125 | let mut has_namespace = false; |
| 1126 | let mut cursor = self.root.walk(); |
| 1127 | 'walk: loop { |
| 1128 | let n = cursor.node(); |
| 1129 | match n.kind() { |
| 1130 | "namespace_use_declaration" => uses.push(n), |
| 1131 | "namespace_definition" => has_namespace = true, |
| 1132 | "function_definition" => functions.push(n), |
| 1133 | _ => {} |
| 1134 | } |
| 1135 | if cursor.goto_first_child() { |
| 1136 | continue; |
| 1137 | } |
| 1138 | while !cursor.goto_next_sibling() { |
| 1139 | if !cursor.goto_parent() { |
| 1140 | break 'walk; |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | let mut shadowed = uses.iter().any(|u| php_use_shadows_dirname(self.text(*u))); |
| 1145 | if !shadowed && has_namespace { |
| 1146 | shadowed = functions.iter().any(|f| { |
| 1147 | f.child_by_field_name("name") |
| 1148 | .is_some_and(|name| self.text(name).to_lowercase() == "dirname") |
| 1149 | }); |
| 1150 | } |
| 1151 | self.dirname_shadowed = Some(shadowed); |
| 1152 | shadowed |
| 1153 | } |
| 1154 | |
| 1155 | // --- calls --------------------------------------------------------------------- |
| 1156 |
no test coverage detected