Skip to content

[4.x] Trigger deprecation notices in Inflector and reuse the Doctrine inflector - #83

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-inflector-deprecations
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-inflector-deprecations

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Joomla\String\Inflector is marked @deprecated 5.0, but users get no notice before it is removed. Its rules() and reset() are empty methods kept "to suffice the former interface", so custom inflection rules are accepted and silently ignored. The upgrade guide points to Doctrine\Common\Inflector\Inflector::rules(), which does not exist in doctrine/inflector 2.x. Every proxy call also builds a new Doctrine inflector with InflectorFactory::create()->build(), which is expensive.

This PR:

  • triggers a deprecation notice (trigger_deprecation('joomla/string', '__DEPLOY_VERSION__', …)) in every public method of Inflector;
  • gives rules() and reset() their own message: they have no effect, and rules belong in InflectorFactory::create()->withSingularRules() / withPluralRules(). They are also marked @deprecated 5.0 in the docblock. The private addRule() reaches rules() for non-countable types and so triggers the same notice;
  • builds the Doctrine inflector once and keeps it in a private static property. isPlural() and isSingular() call it directly, so each call triggers one notice instead of three;
  • corrects the replacement list in docs/v3-to-v4-update.md to the doctrine/inflector 2.x API, with a tested example of configuring rules.

Results do not change, apart from the notices.

Testing Instructions

New tests in InflectorTest: testPluralizeTriggersDeprecation, testRulesTriggersDeprecation (which also checks that a rule passed to rules() has no effect), testResetTriggersDeprecation (all with expectUserDeprecationMessage()), and testDoctrineInflectorIsReused. All four fail before the change and pass after it, and the existing Inflector tests still pass. The docs example was run against doctrine/inflector 2.1. vendor/bin/phpunit is green, phpcs is clean, and PHPStan reports no errors locally. The PHPStan job in CI fails on 4.x-dev as well (mb_trim and the other PHP 8.4 polyfill functions are not found), and #66 fixes that.

Documentation Changes Required

docs/v3-to-v4-update.md: the Doctrine replacements for the removed methods are corrected, a paragraph on rules()/reset() is added, and the deprecation section says that the class now triggers notices. Removing the class is a separate 5.x PR, which adds the 5.0 update guide entry.

The owner's docs PR #72 also edits docs/v3-to-v4-update.md (it appends sections at the end) and has an "Inflector — deprecated" section in docs/overview.md with the correct InflectorFactory usage. That section should mention the deprecation notices once both are merged. Expect a small conflict at the end of docs/v3-to-v4-update.md.

🤖 Generated with Claude Code

…ctor

Inflector is marked @deprecated 5.0 but gave users no notice before
the removal. rules() and reset() are empty methods kept for the former
interface, so custom inflection rules were accepted and silently
ignored. Every call also built a new Doctrine inflector.

Trigger a deprecation notice in every public method, with a specific
message for rules() and reset(), and build the Doctrine inflector
only once. Fix the upgrade guide, which pointed to the
Doctrine\Common\Inflector API that doctrine/inflector 2.x no longer
has.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant