Skip to content

Commit 7a54a7a

Browse files
committed
cargo fmt
1 parent ccd4a94 commit 7a54a7a

File tree

4 files changed

+455
-233
lines changed

4 files changed

+455
-233
lines changed

phper/src/functions.rs

Lines changed: 104 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,22 @@ impl FunctionEntry {
192192
IS_OBJECT,
193193
return_type.allow_null,
194194
)),
195-
ReturnTypeHint::Callable => Some(phper_zend_begin_arg_with_return_type_info_ex(
196-
return_type.ret_by_ref,
197-
require_arg_count,
198-
IS_CALLABLE,
199-
return_type.allow_null,
200-
)),
201-
ReturnTypeHint::Iterable => Some(phper_zend_begin_arg_with_return_type_info_ex(
202-
return_type.ret_by_ref,
203-
require_arg_count,
204-
IS_ITERABLE,
205-
return_type.allow_null,
206-
)),
195+
ReturnTypeHint::Callable => {
196+
Some(phper_zend_begin_arg_with_return_type_info_ex(
197+
return_type.ret_by_ref,
198+
require_arg_count,
199+
IS_CALLABLE,
200+
return_type.allow_null,
201+
))
202+
}
203+
ReturnTypeHint::Iterable => {
204+
Some(phper_zend_begin_arg_with_return_type_info_ex(
205+
return_type.ret_by_ref,
206+
require_arg_count,
207+
IS_ITERABLE,
208+
return_type.allow_null,
209+
))
210+
}
207211
ReturnTypeHint::Mixed => {
208212
if PHP_MAJOR_VERSION < 8 {
209213
None
@@ -217,7 +221,9 @@ impl FunctionEntry {
217221
}
218222
}
219223
ReturnTypeHint::Never => {
220-
if PHP_MAJOR_VERSION < 8 || (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION <= 1) {
224+
if PHP_MAJOR_VERSION < 8
225+
|| (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION <= 1)
226+
{
221227
None
222228
} else {
223229
Some(phper_zend_begin_arg_with_return_type_info_ex(
@@ -249,10 +255,10 @@ impl FunctionEntry {
249255
None
250256
};
251257

252-
infos.push(return_info.unwrap_or_else(|| {
253-
phper_zend_begin_arg_info_ex(false, require_arg_count)
254-
}));
255-
258+
infos.push(
259+
return_info
260+
.unwrap_or_else(|| phper_zend_begin_arg_info_ex(false, require_arg_count)),
261+
);
256262

257263
for arg in arguments {
258264
let default_value_ptr = arg
@@ -262,57 +268,105 @@ impl FunctionEntry {
262268
.unwrap_or(std::ptr::null());
263269
let arg_info = if let Some(ref type_hint) = arg.type_hint {
264270
match type_hint {
265-
ArgumentTypeHint::Null => Some(
266-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_NULL, true, default_value_ptr)
267-
),
268-
ArgumentTypeHint::Bool => Some(
269-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), _IS_BOOL, arg.nullable, default_value_ptr)
270-
),
271-
ArgumentTypeHint::Int => Some(
272-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_LONG, arg.nullable, default_value_ptr)
273-
),
274-
ArgumentTypeHint::Float => Some(
275-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_DOUBLE, arg.nullable, default_value_ptr)
276-
),
277-
ArgumentTypeHint::String => Some(
278-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_STRING, arg.nullable, default_value_ptr)
279-
),
280-
ArgumentTypeHint::Array => Some(
281-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_ARRAY, arg.nullable, default_value_ptr)
282-
),
271+
ArgumentTypeHint::Null => Some(phper_zend_arg_info_with_type(
272+
arg.pass_by_ref,
273+
arg.name.as_ptr(),
274+
IS_NULL,
275+
true,
276+
default_value_ptr,
277+
)),
278+
ArgumentTypeHint::Bool => Some(phper_zend_arg_info_with_type(
279+
arg.pass_by_ref,
280+
arg.name.as_ptr(),
281+
_IS_BOOL,
282+
arg.nullable,
283+
default_value_ptr,
284+
)),
285+
ArgumentTypeHint::Int => Some(phper_zend_arg_info_with_type(
286+
arg.pass_by_ref,
287+
arg.name.as_ptr(),
288+
IS_LONG,
289+
arg.nullable,
290+
default_value_ptr,
291+
)),
292+
ArgumentTypeHint::Float => Some(phper_zend_arg_info_with_type(
293+
arg.pass_by_ref,
294+
arg.name.as_ptr(),
295+
IS_DOUBLE,
296+
arg.nullable,
297+
default_value_ptr,
298+
)),
299+
ArgumentTypeHint::String => Some(phper_zend_arg_info_with_type(
300+
arg.pass_by_ref,
301+
arg.name.as_ptr(),
302+
IS_STRING,
303+
arg.nullable,
304+
default_value_ptr,
305+
)),
306+
ArgumentTypeHint::Array => Some(phper_zend_arg_info_with_type(
307+
arg.pass_by_ref,
308+
arg.name.as_ptr(),
309+
IS_ARRAY,
310+
arg.nullable,
311+
default_value_ptr,
312+
)),
283313
ArgumentTypeHint::Object => Some(
284-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_OBJECT, arg.nullable, std::ptr::null()) //default value not supported
314+
phper_zend_arg_info_with_type(
315+
arg.pass_by_ref,
316+
arg.name.as_ptr(),
317+
IS_OBJECT,
318+
arg.nullable,
319+
std::ptr::null(),
320+
), // default value not supported
285321
),
286322
ArgumentTypeHint::Callable => Some(
287-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_CALLABLE, arg.nullable, std::ptr::null()) //default value not supported
288-
),
289-
ArgumentTypeHint::Iterable => Some(
290-
phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_ITERABLE, arg.nullable, default_value_ptr)
323+
phper_zend_arg_info_with_type(
324+
arg.pass_by_ref,
325+
arg.name.as_ptr(),
326+
IS_CALLABLE,
327+
arg.nullable,
328+
std::ptr::null(),
329+
), // default value not supported
291330
),
331+
ArgumentTypeHint::Iterable => Some(phper_zend_arg_info_with_type(
332+
arg.pass_by_ref,
333+
arg.name.as_ptr(),
334+
IS_ITERABLE,
335+
arg.nullable,
336+
default_value_ptr,
337+
)),
292338
ArgumentTypeHint::Mixed => {
293339
if PHP_MAJOR_VERSION < 8 {
294340
None
295341
} else {
296-
Some(phper_zend_arg_info_with_type(arg.pass_by_ref, arg.name.as_ptr(), IS_MIXED, true, default_value_ptr))
342+
Some(phper_zend_arg_info_with_type(
343+
arg.pass_by_ref,
344+
arg.name.as_ptr(),
345+
IS_MIXED,
346+
true,
347+
default_value_ptr,
348+
))
297349
}
298-
},
350+
}
299351
ArgumentTypeHint::ClassEntry(class_name) => {
300-
let c_class_name = CString::new(class_name.clone()).expect("CString::new failed");
352+
let c_class_name =
353+
CString::new(class_name.clone()).expect("CString::new failed");
301354
Some(phper_zend_arg_obj_info(
302355
arg.pass_by_ref,
303356
arg.name.as_ptr(),
304357
c_class_name.as_ptr(),
305-
arg.nullable
358+
arg.nullable,
306359
))
307-
},
360+
}
308361
}
309362
} else {
310363
None
311364
};
312365

313-
infos.push(arg_info.unwrap_or_else(|| {
314-
phper_zend_arg_info(arg.pass_by_ref, arg.name.as_ptr())
315-
}));
366+
infos
367+
.push(arg_info.unwrap_or_else(|| {
368+
phper_zend_arg_info(arg.pass_by_ref, arg.name.as_ptr())
369+
}));
316370
}
317371

318372
infos.push(zeroed::<zend_internal_arg_info>());
@@ -540,7 +594,8 @@ impl Argument {
540594
self
541595
}
542596

543-
/// Argument default value. Example: "'a-string'", "A_CONST", "42", "[0=>'zero']"
597+
/// Argument default value. Example: "'a-string'", "A_CONST", "42",
598+
/// "[0=>'zero']"
544599
pub fn with_default_value(mut self, default_value: CString) -> Self {
545600
self.default_value = Some(default_value);
546601
self.required = false; // arg with default value does not count towards required arg count

tests/integration/src/classes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use phper::{
1515
},
1616
functions::Argument,
1717
modules::Module,
18-
values::ZVal,
1918
types::ReturnTypeHint,
19+
values::ZVal,
2020
};
2121
use std::{collections::HashMap, convert::Infallible};
2222

@@ -204,7 +204,7 @@ fn integrate_static_props(module: &mut Module) {
204204

205205
#[cfg(phper_major_version = "8")]
206206
fn integrate_stringable(module: &mut Module) {
207-
use phper::{functions::ReturnType};
207+
use phper::functions::ReturnType;
208208

209209
let mut cls = ClassEntity::new(r"IntegrationTest\FooString");
210210
cls.implements(|| ClassEntry::from_globals("Stringable").unwrap());

tests/integration/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mod ini;
2020
mod objects;
2121
mod references;
2222
mod strings;
23-
mod values;
2423
mod typehints;
24+
mod values;
2525

2626
use phper::{modules::Module, php_get_module};
2727

0 commit comments

Comments
 (0)