Skip to content

Conversation

KristianH
Copy link
Contributor

Pull Request Description

This PR adds an optional $regex parameter to the methods: ValueObjectTrait::nullOrString & ValueObjectTrait::string .

Changes:

  • The string method now accepts an optional ?string $regex parameter.
  • If regex is set, the value is validated against the given regex.
  • Corresponding unit tests ensures that an \InvalidArgumentException is thrown when regex is empty or the value not matches the expression.

Motivation:
StoryBlok provides an regex validation for string fields.

@codecov-commenter
Copy link

codecov-commenter commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.88%. Comparing base (a3bf476) to head (e688273).

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #59      +/-   ##
============================================
+ Coverage     93.86%   93.88%   +0.02%     
- Complexity      459      461       +2     
============================================
  Files            72       72              
  Lines          1614     1620       +6     
============================================
+ Hits           1515     1521       +6     
  Misses           99       99              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@silasjoisten
Copy link
Collaborator

Once PHPStan is green. LGTM 👍

@silasjoisten silasjoisten self-assigned this Jul 17, 2025
@silasjoisten silasjoisten requested a review from OskarStark July 18, 2025 06:34
@silasjoisten silasjoisten merged commit 94970c3 into storyblok:master Jul 18, 2025
4 checks passed
@KristianH KristianH deleted the feature/add-regex-to-trait branch July 18, 2025 06:47
}

if (null !== $regex) {
Assert::stringNotEmpty($regex);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use trimmed non empty string here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

if (null !== $regex) {
Assert::stringNotEmpty($regex);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

4 participants