-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
feature: Support addExtensions for validated-dto
.
#839
feature: Support addExtensions for validated-dto
.
#839
Conversation
validated-dto
.
Warning Rate limit exceeded@huangdijia has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 56 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
""" Walkthrough此次变更在 Changes
Sequence Diagram(s)sequenceDiagram
participant Client as 客户端
participant DTO as ValidatedDTO
participant Validator as Validator
Client->>DTO: 调用 isValidData / validationPasses
DTO->>Validator: 创建验证器实例
DTO->>DTO: 调用 extensions()
DTO->>Validator: 执行验证操作
Validator-->>DTO: 返回验证结果
DTO-->>Client: 返回验证结果
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/validated-dto/src/ValidatedDTO.php (1)
147-163
: 建议重构重复的验证逻辑
isValidData
和validationPasses
方法中存在大量重复代码,包括验证器的创建和初始化逻辑。建议将这些共同的逻辑提取到一个私有方法中。建议应用以下重构:
+ private function createAndInitValidator(): ValidatorInterface + { + $container = ApplicationContext::getContainer(); + $validator = $container->get(ValidatorFactoryInterface::class) + ->make( + $this->dtoData, + $this->rulesList(), + $this->messagesList(), + $this->attributes() + ); + + $this->initValidator($validator); + $validator->after(fn ($validator) => $this->after($validator)); + + return $validator; + } + protected function isValidData(): bool { - $container = ApplicationContext::getContainer(); - $this->validator = $container->get(ValidatorFactoryInterface::class) - ->make( - $this->dtoData, - $this->rulesList(), - $this->messagesList(), - $this->attributes() - ); - - $this->initValidator($this->validator); - - $this->validator->after(fn ($validator) => $this->after($validator)); + $this->validator = $this->createAndInitValidator(); return ! $this->validator->fails(); } private function validationPasses(): bool { - $container = ApplicationContext::getContainer(); - $this->validator = $container->get(ValidatorFactoryInterface::class) - ->make( - $this->dtoData, - $this->rulesList(), - $this->messagesList(), - $this->attributes() - ); - - $this->initValidator($this->validator); - - $this->validator->after(fn (ValidatorInterface $validator) => $this->after($validator)); + $this->validator = $this->createAndInitValidator(); return ! $this->validator->fails(); }Also applies to: 196-212
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/validated-dto/src/ValidatedDTO.php
(3 hunks)
🔇 Additional comments (1)
src/validated-dto/src/ValidatedDTO.php (1)
64-67
: 新增的initValidator
方法提供了良好的扩展点该方法为验证器的初始化提供了一个清晰的扩展点,符合开闭原则。子类可以通过重写此方法来自定义验证器的初始化行为。
validated-dto
.validated-dto
.
* Update ValidatedDTO.php * Update ValidatedDTO.php * refactor: rename addExtensions to extensions and update validator extension logic * refactor: improve validator extension logic in ValidatedDTO * refactor: replace extensions method with afterValidatorResolving for improved validator handling --------- Co-authored-by: Deeka Wong <[email protected]>
Summary by CodeRabbit