Type safety: strict_types, final class, return types, private state (roadmap #3)#14
Merged
Conversation
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
Roadmap item #3. - Add declare(strict_types=1). - Mark Inflect as final — the class was never designed to be extended, and locale support (roadmap §5a) will plug in via composition, not inheritance. - Add string/int param types and string return types to pluralize, singularize, pluralizeIf, and preserveFirstCase. - Make static rule tables (plural, singular, irregular, uncountable) and caches private — the extensibility API (roadmap §5) will own the supported ways to add rules. - Type the static property arrays with PHP 7.4+ typed-property syntax. - Convert array() to [] throughout the class. - Nullable input decision: accept string (not nullable), return empty string for empty input. Callers passing null now get a TypeError rather than a silent null return — acceptable for the v2.0 major bump. - Switch == to === in pluralizeIf count check. Tests: - Add explicit coverage for empty-string behavior on both methods. - Add a data-provider case set for pluralizeIf, including the zero case and an irregular (person, datum). 117 tests / 118 assertions pass on PHP 8.1 and 8.3. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses ROADMAP.md item #3. Stacked on #13 (which is stacked on #12).
Changes
declare(strict_types=1)at the top of the class.final class Inflect— the class was never designed for inheritance; locale support (roadmap §5a) will plug in via composition.pluralize(string $string): stringsingularize(string $string): stringpluralizeIf(int $count, string $string): stringpreserveFirstCase(string $source, string $replaced): string$plural,$singular,$irregular,$uncountable) and memoization caches are nowprivate. The extensibility API (roadmap §5) will own the supported ways to add rules.[]instead ofarray()).==→===inpluralizeIfcount check.Nullable input decision
Current behavior:
pluralize(null)silently returnednullvia the falsy-truthy check at the top;pluralize('')did the same.New behavior:
pluralize(null)/singularize(null)→TypeError. Callers withnullare now forced to handle it explicitly.pluralize('')/singularize('')→ returns''. No behavior surprise for empty-string inputs.This is a breaking change for callers relying on the silent-null behavior — acceptable for the v2.0 major bump.
Test plan
pluralizeandsingularize.pluralizeIfincluding the zero case and irregulars (person → people,datum → data).Stacking
This closes the v2.0 trio: #12 (PHP baseline) → #13 (GitHub Actions CI) → #14 (this). Suggest merging in that order.
🤖 Generated with Claude Code