-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: master
Are you sure you want to change the base?
Conversation
DikoIbragimov
commented
Dec 12, 2024
Q | A |
---|---|
Is bugfix? | ❌ |
New feature? | ✔️ |
Breaks BC? | ❌ |
Codecov ReportAttention: Patch coverage is
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. |
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.
Fix psalm errors
src/Rule/Uuid.php
Outdated
use Yiisoft\Validator\WhenInterface; | ||
|
||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] | ||
class Uuid implements DumpedRuleInterface, SkipOnErrorInterface, WhenInterface { |
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.
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.', |
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.
This property is not used.
src/Rule/UuidHandler.php
Outdated
* @return bool | ||
*/ | ||
protected function validateUuid(string $uuid): bool { | ||
$uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid); |
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.
I think it should be optional and disabled by default.
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.
Took it from the package ramsey/uuid
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.
It should be customizable in validation rule.
src/Rule/UuidHandler.php
Outdated
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'; |
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.
Use ^
, $
and i
modifier. It's allow to simplify regular expression.