Repository navigation
Honour prefixes in the Str macros, fix Configs::make() and read config lazily - #7
Merged
Merged
Conversation
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.
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.
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
Strmacros pass$prefixthrough for SKUs and ticket numbers. The scopedStr::simtabiLacommerceSku()/Str::simtabiLacommerceTicketNumber()and the deprecated bareStr::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')returnedLAR-…and now returnsPFX-LAR-…. The pinning tests from Vendor-scope the Str macros and add a registry-free Identifiers API #5 are updated deliberately.Configs::make()resolvesstatic::class. On the base class it resolvedConfigs, which the container cannot build. It now throwsInvalidOptionExceptionnaming the subclasses there, and a subclass that inheritsmake()resolves itself.setPrefix(?string)on bothConfigsInterfaceandConfigs. The interface tookstring, the classmixed. A third-partyConfigsInterfaceimplementation must widen its parameter; a numeric config prefix still works.InvalidOptionExceptiondeclares@phpstan-consistent-constructor. It stays non-final, so a subclass still gets an instance of itself frominvalidArgument(). Nothing in the package extends it.bindGenerator()andbindConfigs()captured the config at boot. A runtimeconfig()->set('simtabi.lacommerce.generator.…')now applies to the next value generated.Generator::makeValue()passes the prefix to a custom$strMixinmacro as a third argument, ornull.CHANGELOG
[Unreleased]and UPGRADING record each behaviour change.docs/tools/generators.mdanddocs/configuration.mdare 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).srcandtests/Fixtures:new.staticis gone. Level 4 is clean except for threestaticMethod.notFounderrors onStrMacros::forwardDeprecated()'s dynamic macro call. Those are already onmaster. Level 5 adds three more that are also onmaster: static closures passed toStr::macro().