Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] 实现模型字段类型转换的统一接口 #592

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

NHZEX
Copy link
Member

@NHZEX NHZEX commented Jul 25, 2024

使模型能友好复用DTO对象支持各种场景

resolve #587

@NHZEX NHZEX requested a review from liu21st July 25, 2024 06:22
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Project coverage is 17.34%. Comparing base (e35f497) to head (0b608a0).
Report is 33 commits behind head on 3.0.

Files Patch % Lines
src/model/concern/Attribute.php 83.33% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##                3.0     #592      +/-   ##
============================================
+ Coverage     12.24%   17.34%   +5.10%     
- Complexity     2965     2988      +23     
============================================
  Files            64       64              
  Lines          7129     7171      +42     
============================================
+ Hits            873     1244     +371     
+ Misses         6256     5927     -329     
Flag Coverage Δ
unittests 17.34% <83.33%> (+5.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@liu21st
Copy link
Member

liu21st commented Aug 15, 2024

其实可以 简化下方法名 用get set就行了

@NHZEX
Copy link
Member Author

NHZEX commented Aug 15, 2024

其实可以 简化下方法名 用get set就行了

说是模型的 getXxxAttr, setXxxAttr
还是接口方法名称简化?(用通用方法名称容易与业务代码冲突)

  • 感觉声明起来并不方便呢,占用模型行数相对多,复用定义相对麻烦些,用type只需要一行代码就轻松复用,还比较强的规范性(而且模型本身type就有对类的支持,但是默认实现扩展性不够友好)
  • 还有一个小痛点是我用attr一般习惯设置为protected,会导致ide误报方法没有任何地方调用(不是啥大问题)

@liu21st
Copy link
Member

liu21st commented Aug 16, 2024

modelReadValue 和 modelWriteValue

@NHZEX
Copy link
Member Author

NHZEX commented Aug 16, 2024

modelReadValue 和 modelWriteValue

modelGetValue,modelSetValue 这样?

PS: 一不小心点错按钮把你回答给编辑一次了😂

@liu21st
Copy link
Member

liu21st commented Aug 16, 2024

modelReadValue 和 modelWriteValue

modelGetValue,modelSetValue 这样?

PS: 一不小心点错按钮把你回答给编辑一次了😂

直接就用get set就行了吧

@NHZEX
Copy link
Member Author

NHZEX commented Aug 16, 2024

modelReadValue 和 modelWriteValue模型读取值和模型写入值

modelGetValue,modelSetValue 这样?
PS: 一不小心点错按钮把你回答给编辑一次了😂

直接就用get set就行了吧

get、set我还倾向于尽量少用,因为感觉没有约束力,只用于轻量级数据的处理。
这些DTO场景还是认为type合理些(其实更想要是类似于别的ORM提供的字段定义约束能力)。

PS:如果你觉得不合适就 close 吧,目前是通过重新 writeTransform、readTransform 能在项目端实现(就是有一点维护成本)。

@liu21st
Copy link
Member

liu21st commented Aug 16, 2024

我的意思是 modelReadValue =》 get modelWriteValue => set 这样简化下

@NHZEX
Copy link
Member Author

NHZEX commented Aug 16, 2024

还是接口方法名称简化?(用通用方法名称容易与业务代码冲突)

理解了😂,简化是简化方法名对吧。不怕容易与用户代码产生冲突么?

@liu21st liu21st merged commit ca1f2ef into top-think:3.0 Aug 16, 2024
0 of 6 checks passed
@liu21st
Copy link
Member

liu21st commented Aug 16, 2024

还是接口方法名称简化?(用通用方法名称容易与业务代码冲突)

理解了😂,简化是简化方法名对吧。不怕容易与用户代码产生冲突么?

冲突可能性不大吧 一般都是setXXX getXXX为主 直接使用get set为方法名的场景不多

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[特性] 提供模型字段类型转换的统一接口
3 participants