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

Add UUID validation rule, and test #754

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DikoIbragimov
Copy link

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 26 lines in your changes missing coverage. Please review.

Project coverage is 9.97%. Comparing base (fe63447) to head (754bd34).
Report is 61 commits behind head on master.

Files with missing lines Patch % Lines
src/Rule/UuidHandler.php 0.00% 14 Missing ⚠️
src/Rule/Uuid.php 0.00% 12 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (fe63447) and HEAD (754bd34). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (fe63447) HEAD (754bd34)
6 3
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #754       +/-   ##
============================================
- Coverage     94.40%   9.97%   -84.43%     
- Complexity      953    1031       +78     
============================================
  Files           108     122       +14     
  Lines          3018    3317      +299     
============================================
- Hits           2849     331     -2518     
- Misses          169    2986     +2817     

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

Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix psalm errors

use Yiisoft\Validator\WhenInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
class Uuid implements DumpedRuleInterface, SkipOnErrorInterface, WhenInterface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add implementation of SkipOnEmptyInterface

*/
public function __construct(
private string $message = 'The value of {property} does not conform to the UUID format.',
private string $notPassedMessage = '{Property} not passed.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is not used.

* @return bool
*/
protected function validateUuid(string $uuid): bool {
$uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be optional and disabled by default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took it from the package ramsey/uuid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be customizable in validation rule.

use Yiisoft\Validator\ValidationContext;

class UuidHandler implements RuleHandlerInterface {
private const PATTERN = '\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\z';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ^, $ and i modifier. It's allow to simplify regular expression.

@vjik vjik added the status:under development Someone is working on a pull request. label Dec 15, 2024
@samdark samdark marked this pull request as draft December 16, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants