Extract all docblock-derived metadata from a class-like AST node. Returns [`ClassDocblockInfo::default()`] when no docblock context is available or when the node has no preceding doc comment.
(
node: &impl HasSpan,
doc_ctx: Option<&DocblockCtx<'a>>,
)
| 200 | /// Returns [`ClassDocblockInfo::default()`] when no docblock context is |
| 201 | /// available or when the node has no preceding doc comment. |
| 202 | fn extract_class_docblock<'a>( |
| 203 | node: &impl HasSpan, |
| 204 | doc_ctx: Option<&DocblockCtx<'a>>, |
| 205 | ) -> ClassDocblockInfo { |
| 206 | let Some(ctx) = doc_ctx else { |
| 207 | return ClassDocblockInfo::default(); |
| 208 | }; |
| 209 | let Some(doc_text) = docblock::get_docblock_text_for_node(ctx.trivias, ctx.content, node) |
| 210 | else { |
| 211 | return ClassDocblockInfo::default(); |
| 212 | }; |
| 213 | let Some(info) = docblock::parse_docblock_for_tags(doc_text) else { |
| 214 | return ClassDocblockInfo::default(); |
| 215 | }; |
| 216 | |
| 217 | let params_full = docblock::extract_template_params_full_from_info(&info); |
| 218 | let template_params: Vec<Atom> = params_full.iter().map(|(n, _, _, _)| atom(n)).collect(); |
| 219 | let template_param_bounds: AtomMap<PhpType> = params_full |
| 220 | .iter() |
| 221 | .filter_map(|(name, bound, _, _)| bound.as_ref().map(|b| (atom(name), b.clone()))) |
| 222 | .collect(); |
| 223 | let template_param_defaults: AtomMap<PhpType> = params_full |
| 224 | .into_iter() |
| 225 | .filter_map(|(name, _, _, default)| default.map(|d| (atom(&name), d))) |
| 226 | .collect(); |
| 227 | |
| 228 | let mixin_data = docblock::extract_mixin_tags_from_info(&info); |
| 229 | let mixins: Vec<Atom> = mixin_data.iter().map(|(name, _)| atom(name)).collect(); |
| 230 | let mixin_generics: Vec<(Atom, Vec<PhpType>)> = mixin_data |
| 231 | .into_iter() |
| 232 | .filter(|(_, args)| !args.is_empty()) |
| 233 | .map(|(name, args)| (atom(&name), args)) |
| 234 | .collect(); |
| 235 | |
| 236 | ClassDocblockInfo { |
| 237 | deprecation_message: docblock::extract_deprecation_message_from_info(&info), |
| 238 | template_params, |
| 239 | template_param_bounds, |
| 240 | template_param_defaults, |
| 241 | extends_generics: docblock::extract_generics_tag_from_info(&info, "@extends") |
| 242 | .into_iter() |
| 243 | .map(|(n, args)| (atom(&n), args)) |
| 244 | .collect(), |
| 245 | implements_generics: docblock::extract_generics_tag_from_info(&info, "@implements") |
| 246 | .into_iter() |
| 247 | .map(|(n, args)| (atom(&n), args)) |
| 248 | .collect(), |
| 249 | use_generics: docblock::extract_generics_tag_from_info(&info, "@use") |
| 250 | .into_iter() |
| 251 | .map(|(n, args)| (atom(&n), args)) |
| 252 | .collect(), |
| 253 | type_aliases: docblock::extract_type_aliases_from_info(&info) |
| 254 | .into_iter() |
| 255 | .map(|(k, v)| (atom(&k), v)) |
| 256 | .collect(), |
| 257 | mixins, |
| 258 | mixin_generics, |
| 259 | links: docblock::extract_link_urls_from_info(&info), |
no test coverage detected