Skip to content

Commit 926480f

Browse files
committed
refactor(tests): 优化代码格式和函数调用逻辑
- 统一了 object.cpp 中的缩进格式 - 将 getCallArgNum 函数提取为内联函数以提高可读性 - 更新了 getCallArg 函数中的参数数量检查逻辑 - 简化了参数验证的代码结构
1 parent f2a053a commit 926480f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

include/phpx_helper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ static inline Variant getCallArg(uint32_t i) {
159159
return {ZEND_CALL_ARG(EG(current_execute_data), i + 1), Ctor::CopyRef};
160160
}
161161

162+
static inline uint32_t getCallArgNum() {
163+
return ZEND_CALL_NUM_ARGS(EG(current_execute_data));
164+
}
165+
162166
static inline Variant getCallArg(uint32_t i, const Variant &defaultValue) {
163-
if (i >= ZEND_CALL_NUM_ARGS(EG(current_execute_data))) {
167+
if (i >= getCallArgNum()) {
164168
return defaultValue;
165169
} else {
166170
return getCallArg(i);

tests/src/object.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,12 @@ TEST(object, enum_class) {
601601
}
602602

603603
TEST(object, exec) {
604-
auto obj = newObject("DateTime", "2000-01-01");
605-
auto fn = getMethod(obj.ce(), "format");
606-
auto rs = obj.exec(fn, {"Y-m-d H:i:s"});
604+
auto obj = newObject("DateTime", "2000-01-01");
605+
auto fn = getMethod(obj.ce(), "format");
606+
auto rs = obj.exec(fn, {"Y-m-d H:i:s"});
607607
ASSERT_STREQ(rs.toCString(), "2000-01-01 00:00:00");
608608

609-
auto fn2 = getMethod(obj.ce(), "getTimestamp");
610-
auto rs2 = obj.exec(fn2);
609+
auto fn2 = getMethod(obj.ce(), "getTimestamp");
610+
auto rs2 = obj.exec(fn2);
611611
ASSERT_GT(rs2.toInt(), 100000000);
612612
}

0 commit comments

Comments
 (0)