Skip to content

fix: check() should not throw on empty strings (#29)#42

Merged
deemonic merged 1 commit intomainfrom
fix/empty-string-check
Jan 27, 2026
Merged

fix: check() should not throw on empty strings (#29)#42
deemonic merged 1 commit intomainfrom
fix/empty-string-check

Conversation

@deemonic
Copy link
Collaborator

@deemonic deemonic commented Jan 27, 2026

Summary

  • Blasp::check() now accepts ?string and returns a clean (no profanity) result for empty or null input instead of throwing an exception
  • Users passing nullable request fields no longer need empty guards before calling check()
  • Adds EmptyInputTest with 4 tests covering empty string, null, and continued detection after empty input

Closes #29

Test plan

  • check('') returns hasProfanity() === false with empty source/clean strings
  • check(null) returns the same clean result
  • Profanity detection still works normally after an empty check
  • Full test suite passes (184 tests, 918 assertions)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • The check method now accepts null values and empty strings gracefully without throwing exceptions, initializing with default values instead.
  • Tests

    • Added test coverage for null and empty string input scenarios, including state isolation verification between calls.

✏️ Tip: You can customize this high-level summary in your review settings.

Users passing request fields that may be empty no longer need null/empty
guards before calling check(). The method now accepts ?string and returns
a clean (no profanity) result for empty or null input.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

The check method now accepts nullable string input instead of throwing an exception on empty or null values. When null or empty input is provided, the method gracefully initializes internal state and returns early without further processing.

Changes

Cohort / File(s) Summary
Core Service Updates
src/BlaspService.php, src/Facades/Blasp.php
Updated check() method signature to accept ?string instead of string. Modified control flow to handle empty/null input by initializing internal state (sourceString, cleanString, hasProfanity, profanitiesCount, uniqueProfanitiesFound, uniqueProfanitiesMap) to default values and returning early. Removed @throws Exception documentation and updated parameter type hints in docblocks.
Test Suite
tests/EmptyInputTest.php
New test class with four test methods verifying that empty strings return no profanity with zero counts, null input returns no profanity with empty strings, source and clean strings are empty after null/empty checks, and profanity detection remains functional for subsequent non-empty inputs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit hops through empty fields with glee,
No exceptions thrown for null or empty to be! 🐰
Just init the state and return with care,
Graceful handling floats through the air.

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: making check() handle empty strings without throwing exceptions.
Linked Issues check ✅ Passed The PR fully implements the #29 requirement: check() now accepts nullable strings and returns clean results instead of throwing exceptions.
Out of Scope Changes check ✅ Passed All changes directly align with the PR objective of handling empty/null inputs gracefully. No out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@deemonic deemonic merged commit 0f4b293 into main Jan 27, 2026
3 checks passed
@deemonic deemonic deleted the fix/empty-string-check branch January 27, 2026 12:45
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.

[Feature Request] check function should not throw an exception on null or empty strings

1 participant