Skip rector visibility rule on PolicyCommand (fix cs-stan)#333
Merged
Conversation
Cake\Console\Command declares buildOptionParser() as protected; the override on PolicyCommand was public. Rector's MakeInheritedMethodVisibilitySameAsParentRector flags this and the cs-stan workflow is currently red on master. Drop the override visibility to protected to match the parent. Behavior is unchanged for callers, since the Bake/Command runner invokes the parent's protected getOptionParser() pipeline.
Merged
The previous protected-visibility change on PolicyCommand::buildOptionParser fails the (8.2, lowest) matrix: cakephp/bake < 3.6.4 still declares SimpleBakeCommand::buildOptionParser as public, and PHP forbids narrowing visibility in a subclass. Bake 3.6.4 (the same release that introduced its own rector setup) switched the parent to protected; align our lowest bound accordingly so both ends of the matrix are consistent.
…ng visibility The earlier two commits on this branch narrowed PolicyCommand::buildOptionParser to protected and bumped cakephp/bake's minimum to ^3.6.4 to keep CI green. That introduces a real (if narrow) BC break: users on cakephp/bake 3.2 - 3.6.3 who upgrade authorization to this revision hit a PHP fatal when loading PolicyCommand, because PHP forbids narrowing a parent's visibility. Revert both code changes and instead add a per-file skip to rector.php for MakeInheritedMethodVisibilitySameAsParentRector on src/Command/PolicyCommand.php. The override stays public, which is forward- and backward-compatible against any bake version - widening is always allowed. Net diff vs 3.x is a single addition to rector.php.
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.
Cake\Console\Command::buildOptionParser()isprotectedbut the override onAuthorization\Command\PolicyCommandispublic, which Rector'sMakeInheritedMethodVisibilitySameAsParentRectorflags. As of the recent rector setup work on3.x, thecs-stanworkflow is red on master and every open PR inherits the failure.Why not just narrow the override?
The straightforward fix — making the override
protected— looks safe locally but breaks the(8.2, lowest)matrix and, more importantly, breaks real-world installs on older bake. PHP forbids narrowing a parent's visibility;Bake\Command\SimpleBakeCommand::buildOptionParser()waspublicincakephp/bake < 3.6.4(which only tagged on 2026-05-08) andprotectedfrom 3.6.4 onward:PHP Fatal error: Access level … must be publicNarrowing the override would have meant either a coordinated
cakephp/bake: ^3.6.4bump (BC-breaking for the narrow audience of users on bake 3.2–3.6.3 who runbin/cake bake policy) or moving bake fromrequire-devtorequire(larger change, deserves its own discussion).Refs https://github.com/cakephp/bake/pull/1077/changes#r3227429622
What this PR does instead
Adds a per-file skip in
rector.phpforMakeInheritedMethodVisibilitySameAsParentRectoronsrc/Command/PolicyCommand.php. The override stayspublic, which is forward- and backward-compatible against any supported bake version — widening is always allowed.Net diff vs
3.xis a single addition torector.php.