Skip to content

[5.x] Remove the static $defaultName property from AbstractCommand - #43

Open
Hackwar wants to merge 5 commits into
joomla-framework:5.x-devfrom
Hackwar:5.x-remove-default-name
Open

Hackwar wants to merge 5 commits into
joomla-framework:5.x-devfrom
Hackwar:5.x-remove-default-name

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Removes the static AbstractCommand::$defaultName property, deprecated in 4.x (#40) in favour of Symfony's #[AsCommand] attribute, which replaced the property in Symfony 7.0 and which AbstractCommand reads since #38.

Depends on #38 and #40 (4.x) and on #41/#42 (5.x): this branch is stacked on the native-types branch and contains cherry-picks of the #38 and #40 commits, so it builds and tests on its own. Please review only the last commit ("Remove the static $defaultName property from AbstractCommand"). When 4.x-dev is merged into 5.x-dev after #38/#40, those cherry-picks drop out; check that AbstractCommand::getDefaultName(), the constructor and composer.json end up as in this PR (no $defaultName, no symfony/deprecation-contracts).

Testing Instructions

vendor/bin/phpunit, phpcs and PHPStan pass. AbstractCommandTest::testTheDefaultNamePropertyIsNotRead checks that a class declaring $defaultName gets no name; the attribute tests from #38 still pass, and every other test now names its commands with the attribute.

Documentation Changes Required

  • docs/v4-to-v5-update.md: new section "AbstractCommand::$defaultName removed" with a before/after example; the native-types section no longer mentions the property.
  • docs/overview.md: the paragraph on naming commands describes the attribute only.

🤖 Generated with Claude Code

Hackwar and others added 5 commits November 13, 2026 01:03
Two 5.x changes add entries to it; creating the file once keeps them
from conflicting over its creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Several public signatures were typed only in doc blocks:
AbstractCommand::addOption() and addArgument() defaults,
AbstractCommand::setDefinition(), LoaderInterface::has(),
DescriptorHelper::describe() and Application::execute(). Add the native
types and type all private properties. Adding types to interface and
overridable methods breaks implementers, so this goes to 5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AbstractCommand does not extend Symfony's Command, so a command written
the way the Symfony 7 documentation describes, with #[AsCommand] instead
of the static $defaultName removed from Symfony, had no name and could
not be registered.

getDefaultName() now falls back to the attribute when the class does
not declare $defaultName, and the constructor applies the attribute's
aliases, hidden flag, description and help. $defaultName keeps
precedence. The reflection result is cached per class instead of being
rebuilt on every getDefaultName() call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Symfony removed Command::$defaultName in 7.0 in favour of #[AsCommand],
which AbstractCommand now reads as well. Deprecate the property for
removal in 5.0: getDefaultName() triggers a deprecation when a class
names itself through it. The help and list commands use the attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Naming a command through $defaultName was deprecated in 4.1 in favour
of Symfony's #[AsCommand] attribute, which replaced the property in
Symfony 7.0. AbstractCommand now reads the attribute only, so the
deprecation layer and symfony/deprecation-contracts go as well. The
test commands use the attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

I would not remove this in 5.0.

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