Skip to content

Commit b5788e1

Browse files
committed
chore: Clean from duplicated code
1 parent 2e2adec commit b5788e1

File tree

7 files changed

+15
-78
lines changed

7 files changed

+15
-78
lines changed

crates/macros/src/interface.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ impl ToTokens for InterfaceData<'_> {
5454
let name = &self.name;
5555
let implements = &self.attrs.extends;
5656
let methods_sig = &self.methods;
57-
let path = &self.path;
5857
let constants = &self.constants;
5958

60-
let constructor = self.constructor
59+
let _constructor = self.constructor
6160
.as_ref()
62-
.map(|func| func.constructor_meta(&path))
61+
.map(|func| func.constructor_meta(&self.path))
6362
.option_tokens();
6463

6564
quote! {
@@ -209,15 +208,7 @@ impl<'a> Parse<'a, InterfaceData<'a>> for ItemTrait {
209208
let interface_name = format_ident!("PhpInterface{ident}");
210209
let ts = quote! { #interface_name };
211210
let path: Path = syn::parse2(ts)?;
212-
let mut data = InterfaceData::new(
213-
ident,
214-
name,
215-
path,
216-
attrs,
217-
None,
218-
Vec::new(),
219-
Vec::new()
220-
);
211+
let mut data = InterfaceData::new(ident, name, path, attrs, None, Vec::new(), Vec::new());
221212

222213
for item in &mut self.items {
223214
match item {
@@ -230,7 +221,7 @@ impl<'a> Parse<'a, InterfaceData<'a>> for ItemTrait {
230221
}
231222
}
232223
};
233-
},
224+
}
234225
TraitItem::Const(c) => data.constants.push(c.parse()?),
235226
_ => {}
236227
}
@@ -265,15 +256,10 @@ impl<'a> Parse<'a, MethodKind<'a>> for TraitItemFn {
265256
bail!(self => "Interface could not have default impl");
266257
}
267258

268-
let php_attr = PhpFunctionInterfaceAttribute::from_attributes(
269-
&self.attrs
270-
)?;
259+
let php_attr = PhpFunctionInterfaceAttribute::from_attributes(&self.attrs)?;
271260
self.attrs.clean_php();
272261

273-
let mut args = Args::parse_from_fnargs(
274-
self.sig.inputs.iter(),
275-
php_attr.defaults
276-
)?;
262+
let mut args = Args::parse_from_fnargs(self.sig.inputs.iter(), php_attr.defaults)?;
277263

278264
let docs = get_docs(&php_attr.attrs)?;
279265

src/builders/class.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ impl ClassBuilder {
258258
},
259259
MethodFlags::Public,
260260
)
261-
262261
}
263262

264263
/// Function to register the class with PHP. This function is called after

src/builders/interface.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/builders/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod enum_builder;
77
mod function;
88
#[cfg(all(php82, feature = "embed"))]
99
mod ini;
10-
mod interface;
1110
mod module;
1211
#[cfg(feature = "embed")]
1312
mod sapi;

src/builders/module.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use super::{ClassBuilder, FunctionBuilder};
44
#[cfg(feature = "enum")]
55
use crate::{builders::enum_builder::EnumBuilder, enum_::RegisteredEnum};
66
use crate::{
7-
builders::interface::InterfaceBuilder,
87
class::RegisteredClass,
98
constant::IntoConst,
109
describe::DocComments,
1110
error::Result,
1211
ffi::{ext_php_rs_php_build_id, ZEND_MODULE_API_NO},
12+
flags::ClassFlags,
1313
zend::{FunctionEntry, ModuleEntry},
1414
PHP_DEBUG, PHP_ZTS,
1515
};
@@ -201,7 +201,7 @@ impl ModuleBuilder<'_> {
201201
/// * Panics if a constant could not be registered.
202202
pub fn interface<T: RegisteredClass>(mut self) -> Self {
203203
self.interfaces.push(|| {
204-
let mut builder = InterfaceBuilder::new(T::CLASS_NAME);
204+
let mut builder = ClassBuilder::new(T::CLASS_NAME);
205205
for (method, flags) in T::method_builders() {
206206
builder = builder.method(method, flags);
207207
}
@@ -214,13 +214,12 @@ impl ModuleBuilder<'_> {
214214
.expect("Failed to register constant");
215215
}
216216

217-
let mut class_builder = builder.builder();
218-
219217
if let Some(modifier) = T::BUILDER_MODIFIER {
220-
class_builder = modifier(class_builder);
218+
builder = modifier(builder);
221219
}
222220

223-
class_builder
221+
builder = builder.flags(ClassFlags::Interface);
222+
builder
224223
.object_override::<T>()
225224
.registration(|ce| {
226225
T::get_metadata().set_ce(ce);

src/describe/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl Class {
227227
}),
228228
r#static: false,
229229
visibility: Visibility::Public,
230-
r#abstract: false
230+
r#abstract: false,
231231
}]
232232
.into(),
233233
constants: StdVec::new().into(),
@@ -274,7 +274,7 @@ impl From<ClassBuilder> for Class {
274274
.map(Constant::from)
275275
.collect::<StdVec<_>>()
276276
.into(),
277-
flags: flags
277+
flags: flags,
278278
}
279279
}
280280
}

tests/src/integration/interface/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use ext_php_rs::types::ZendClassObject;
2-
use ext_php_rs::zend::ce;
31
use ext_php_rs::php_interface;
42
use ext_php_rs::prelude::ModuleBuilder;
3+
use ext_php_rs::types::ZendClassObject;
4+
use ext_php_rs::zend::ce;
55

66
#[php_interface]
77
#[php(extends(ce = ce::throwable, stub = "\\Throwable"))]

0 commit comments

Comments
 (0)