• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

davidcole1340 / ext-php-rs / 15715261521

17 Jun 2025 06:27PM UTC coverage: 22.034% (-0.04%) from 22.076%
15715261521

Pull #436

github

Xenira
chore(macro)!: change rename defaults to match psr

BREAKING CHANGE: Methods and Properties are renamed to camelCase by default. Classes to PascalCase and constants to UPPER_CASE.

Refs: #189
Pull Request #436: chore(macro)!: change rename defaults to match psr

16 of 35 new or added lines in 5 files covered. (45.71%)

2 existing lines in 2 files now uncovered.

871 of 3953 relevant lines covered (22.03%)

2.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/macros/src/constant.rs
1
use darling::FromAttributes;
2
use proc_macro2::TokenStream;
3
use quote::{format_ident, quote};
4
use syn::ItemConst;
5

6
use crate::helpers::get_docs;
7
use crate::parsing::{PhpRename, RenameRule};
8
use crate::prelude::*;
9

10
const INTERNAL_CONST_DOC_PREFIX: &str = "_internal_const_docs_";
11
const INTERNAL_CONST_NAME_PREFIX: &str = "_internal_const_name_";
12

13
#[derive(FromAttributes, Default, Debug)]
14
#[darling(default, attributes(php), forward_attrs(doc))]
15
pub(crate) struct PhpConstAttribute {
16
    #[darling(flatten)]
17
    pub(crate) rename: PhpRename,
18
    // TODO: Implement const Visibility
19
    // pub(crate) vis: Option<Visibility>,
20
    pub(crate) attrs: Vec<syn::Attribute>,
21
}
22

23
pub fn parser(mut item: ItemConst) -> Result<TokenStream> {
×
24
    let attr = PhpConstAttribute::from_attributes(&item.attrs)?;
×
25

NEW
26
    let name = attr
×
NEW
27
        .rename
×
NEW
28
        .rename(item.ident.to_string(), RenameRule::ScreamingSnake);
×
UNCOV
29
    let name_ident = format_ident!("{INTERNAL_CONST_NAME_PREFIX}{}", item.ident);
×
30

31
    let docs = get_docs(&attr.attrs)?;
×
32
    let docs_ident = format_ident!("{INTERNAL_CONST_DOC_PREFIX}{}", item.ident);
×
33
    item.attrs.retain(|attr| !attr.path().is_ident("php"));
×
34

35
    Ok(quote! {
×
36
        #item
×
37
        #[allow(non_upper_case_globals)]
×
38
        const #docs_ident: &[&str] = &[#(#docs),*];
×
39
        #[allow(non_upper_case_globals)]
×
40
        const #name_ident: &str = #name;
×
41
    })
42
}
43

44
pub fn wrap(input: &syn::Path) -> Result<TokenStream> {
×
45
    let Some(const_name) = input.get_ident().map(ToString::to_string) else {
×
46
        bail!(input => "Pass a PHP const into `wrap_constant!()`.");
×
47
    };
48
    let doc_const = format_ident!("{INTERNAL_CONST_DOC_PREFIX}{const_name}");
×
49
    let const_name = format_ident!("{INTERNAL_CONST_NAME_PREFIX}{const_name}");
×
50

51
    Ok(quote! {
×
52
        (#const_name, #input, #doc_const)
×
53
    })
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc