Conversation
ControllerAllCommand, ModelAllCommand and TemplateAllCommand declared their
wrapped subcommand as a non-nullable typed property and assigned it in
initialize(). On CakePHP 5.4 BaseCommand::run() builds the option parser
before calling initialize(), so buildOptionParser() reads the property while
it is still uninitialized:
Typed property Bake\Command\ControllerAllCommand::$controllerCommand
must not be accessed before initialization
Move the assignment into the constructor so the subcommand is available
regardless of the lifecycle ordering. The override of initialize() is dropped;
the inherited BakeCommand::initialize() (table-locator fallback) still runs.
TemplateAllCommand never read the property in buildOptionParser(), so its
breakage was latent; the change keeps the three commands consistent.
The constructor approach broke on cakephp/cakephp 5.1, where BaseCommand has no constructor yet (Error: Cannot call constructor via parent::__construct()). Bake supports ^5.1. Assign the wrapped subcommand lazily in buildOptionParser() with ??= instead. buildOptionParser() always runs before execute() on every supported version, and on 5.4 it runs before initialize() too, so the property is always set before use regardless of lifecycle ordering. ??= is safe on an uninitialized typed property and idempotent across repeated parser builds.
…bcommand Assign AllCommand subcommands in the constructor (fix uninitialized typed property on CakePHP 5.4)
* Generate enums with EnumLabelTrait * update phpstan ignores
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.
No description provided.