Skip to content

Honour prefixes in the Str macros, fix Configs::make() and read config lazily - #7

Merged
imanimanyara merged 6 commits into
masterfrom
fix/follow-ups-prefix-configs-bindings
Oct 7, 2026
Merged

imanimanyara merged 6 commits into
masterfrom
fix/follow-ups-prefix-configs-bindings

Conversation

@imanimanyara

Copy link
Copy Markdown
Member

Closes the six follow-ups from the review of #6. One commit per item; each new test was run against the code before its fix and failed.

Changes

  1. Str macros pass $prefix through for SKUs and ticket numbers. The scoped Str::simtabiLacommerceSku() / Str::simtabiLacommerceTicketNumber() and the deprecated bare Str::sku() / Str::ticketNumber() accepted a prefix and dropped it, a leftover of 5a0461b (2022). Output changes for a caller that passed one: Str::sku('laravel', '-', 'pfx') returned LAR-… and now returns PFX-LAR-…. The pinning tests from Vendor-scope the Str macros and add a registry-free Identifiers API #5 are updated deliberately.
  2. Configs::make() resolves static::class. On the base class it resolved Configs, which the container cannot build. It now throws InvalidOptionException naming the subclasses there, and a subclass that inherits make() resolves itself.
  3. setPrefix(?string) on both ConfigsInterface and Configs. The interface took string, the class mixed. A third-party ConfigsInterface implementation must widen its parameter; a numeric config prefix still works.
  4. InvalidOptionException declares @phpstan-consistent-constructor. It stays non-final, so a subclass still gets an instance of itself from invalidArgument(). Nothing in the package extends it.
  5. Bindings read config when they resolve. bindGenerator() and bindConfigs() captured the config at boot. A runtime config()->set('simtabi.lacommerce.generator.…') now applies to the next value generated.
  6. Generator::makeValue() passes the prefix to a custom $strMixin macro as a third argument, or null.

CHANGELOG [Unreleased] and UPGRADING record each behaviour change. docs/tools/generators.md and docs/configuration.md are updated to match.

Verification

  • vendor/bin/phpunit: 80 tests, 192 assertions, all passing. The 2 deprecations come from vendor code (symfony/translation, testbench's database config on PHP 8.5).
  • PHPStan 2.3 with Larastan 3.12 on src and tests/Fixtures: new.static is gone. Level 4 is clean except for three staticMethod.notFound errors on StrMacros::forwardDeprecated()'s dynamic macro call. Those are already on master. Level 5 adds three more that are also on master: static closures passed to Str::macro().

The scoped and deprecated bare macros accepted a $prefix argument and
dropped it, a leftover of the 2022 move of their bodies into Helpers.
They now forward it to Identifiers, so a caller passing a prefix gets it
as the leading segment. Calls without one are unchanged.
On the base class it resolved Configs itself, which the container cannot
build, so it failed with an unresolvable-dependency error; a subclass
inheriting make() failed the same way. It now resolves static::class and
throws an InvalidOptionException naming the subclasses on the base.
The interface took string, refusing the null getPrefix() returns, while
the class took mixed. Both now take ?string.
invalidArgument() builds new static on a non-final class, which PHPStan
reports as unsafe. The class stays open so subclasses keep returning
themselves, and @phpstan-consistent-constructor makes PHPStan check that
a subclass keeps a compatible constructor.
bindGenerator() and bindConfigs() closed over the config read during
boot, so a later config() change never reached a generator. The closures
now read it on each resolve; they were already non-singleton binds.
Generator::makeValue() called a custom $strMixin macro with the source
and separator only, so a configured prefix never reached it while the
shipped generators honoured it. It now passes the prefix, or null, as a
third argument.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 13:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@imanimanyara
imanimanyara merged commit 70913b0 into master Oct 7, 2026
6 checks passed
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.

2 participants