Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Resonance
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
distantmagic
Resonance
Commits
f16f149e
Commit
f16f149e
authored
1 year ago
by
Mateusz Charytoniuk
Browse files
Options
Downloads
Patches
Plain Diff
chore: validate mail
parent
5ef610ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Constraint/StringConstraint.php
+14
-12
14 additions, 12 deletions
src/Constraint/StringConstraint.php
src/Constraint/StringConstraintTest.php
+8
-0
8 additions, 0 deletions
src/Constraint/StringConstraintTest.php
with
22 additions
and
12 deletions
src/Constraint/StringConstraint.php
+
14
−
12
View file @
f16f149e
...
@@ -86,24 +86,26 @@ final readonly class StringConstraint extends Constraint
...
@@ -86,24 +86,26 @@ final readonly class StringConstraint extends Constraint
);
);
}
}
if
(
ConstraintStringFormat
::
Uuid
===
$this
->
format
)
{
$isFormatValid
=
match
(
$this
->
format
)
{
if
(
uuid_is_valid
(
$notValidatedData
))
{
ConstraintStringFormat
::
Mail
=>
false
!==
filter_var
(
$notValidatedData
,
FILTER_VALIDATE_EMAIL
),
return
new
ConstraintResult
(
ConstraintStringFormat
::
Uuid
=>
uuid_is_valid
(
$notValidatedData
),
castedData
:
$notValidatedData
,
default
=>
throw
new
RuntimeException
(
'Unknown string format'
),
path
:
$path
,
};
reason
:
ConstraintReason
::
Ok
,
status
:
ConstraintResultStatus
::
Valid
,
);
}
if
(
$isFormatValid
)
{
return
new
ConstraintResult
(
return
new
ConstraintResult
(
castedData
:
$notValidatedData
,
castedData
:
$notValidatedData
,
path
:
$path
,
path
:
$path
,
reason
:
ConstraintReason
::
InvalidFormat
,
reason
:
ConstraintReason
::
Ok
,
status
:
ConstraintResultStatus
::
Inv
alid
,
status
:
ConstraintResultStatus
::
V
alid
,
);
);
}
}
throw
new
RuntimeException
(
'Unknown string format'
);
return
new
ConstraintResult
(
castedData
:
$notValidatedData
,
path
:
$path
,
reason
:
ConstraintReason
::
InvalidFormat
,
status
:
ConstraintResultStatus
::
Invalid
,
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Constraint/StringConstraintTest.php
+
8
−
0
View file @
f16f149e
...
@@ -52,6 +52,14 @@ final class StringConstraintTest extends TestCase
...
@@ -52,6 +52,14 @@ final class StringConstraintTest extends TestCase
self
::
assertTrue
(
$constraint
->
validate
(
'hi'
)
->
status
->
isValid
());
self
::
assertTrue
(
$constraint
->
validate
(
'hi'
)
->
status
->
isValid
());
}
}
public
function
test_validates_mail
():
void
{
$constraint
=
new
StringConstraint
(
format
:
ConstraintStringFormat
::
Mail
);
self
::
assertFalse
(
$constraint
->
validate
(
'hi'
)
->
status
->
isValid
());
self
::
assertTrue
(
$constraint
->
validate
(
'test@example.com'
)
->
status
->
isValid
());
}
public
function
test_validates_uuid
():
void
public
function
test_validates_uuid
():
void
{
{
$constraint
=
new
StringConstraint
(
format
:
ConstraintStringFormat
::
Uuid
);
$constraint
=
new
StringConstraint
(
format
:
ConstraintStringFormat
::
Uuid
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment