Extract the `from` / `to` version range from a `#[PhpStormStubsElementAvailable(...)]` attribute, if present. Supports both named and positional argument forms: - `#[PhpStormStubsElementAvailable(from: '8.0')]` - `#[PhpStormStubsElementAvailable(from: '8.0', to: '8.4')]` - `#[PhpStormStubsElementAvailable(to: '7.4')]` - `#[PhpStormStubsElementAvailable('8.1')]` (positional → treated as `from`) A
(
attribute_lists: &Sequence<'_, attribute::AttributeList<'_>>,
ctx: &DocblockCtx<'_>,
)
| 195 | /// |
| 196 | /// Returns `None` when the attribute is not present. |
| 197 | fn extract_version_availability( |
| 198 | attribute_lists: &Sequence<'_, attribute::AttributeList<'_>>, |
| 199 | ctx: &DocblockCtx<'_>, |
| 200 | ) -> Option<VersionAvailability> { |
| 201 | for attr_list in attribute_lists.iter() { |
| 202 | for attr in attr_list.attributes.iter() { |
| 203 | if !ctx.is_element_available_attr(attr.name.last_segment()) { |
| 204 | continue; |
| 205 | } |
| 206 | |
| 207 | let arg_list = attr.argument_list.as_ref()?; |
| 208 | let mut from: Option<PhpVersion> = None; |
| 209 | let mut to: Option<PhpVersion> = None; |
| 210 | |
| 211 | for arg in arg_list.arguments.iter() { |
| 212 | match arg { |
| 213 | argument::Argument::Named(named) => { |
| 214 | let name = named.name.value.to_string(); |
| 215 | let value = extract_string_literal_value(named.value, ctx.content); |
| 216 | if let Some(ver_str) = value { |
| 217 | let ver = PhpVersion::from_composer_constraint(&ver_str); |
| 218 | match name.as_str() { |
| 219 | "from" => from = ver, |
| 220 | "to" => to = ver, |
| 221 | _ => {} |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | argument::Argument::Positional(positional) => { |
| 226 | // Positional argument is treated as `from`. |
| 227 | let value = extract_string_literal_value(positional.value, ctx.content); |
| 228 | if let Some(ver_str) = value { |
| 229 | from = PhpVersion::from_composer_constraint(&ver_str); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return Some(VersionAvailability { from, to }); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | None |
| 240 | } |
| 241 | |
| 242 | // ─── LanguageLevelTypeAware Attribute Parsing ─────────────────────────────── |
| 243 |
no test coverage detected