Skip to content

fix(legacy): handle null input in interactive prompt validators#86

Open
pjcdawkins wants to merge 2 commits into
mainfrom
fix/legacy-interactive-validator-null
Open

fix(legacy): handle null input in interactive prompt validators#86
pjcdawkins wants to merge 2 commits into
mainfrom
fix/legacy-interactive-validator-null

Conversation

@pjcdawkins
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #85 — fixes five more interactive prompts in the legacy CLI that crashed with a TypeError when the user pressed Enter to accept a null default. Tracked in CLI-143.

File What crashed
legacy/src/Selector/Selector.php (offerProjectChoice) explode(' - ', null) on the project-by-ID prompt
legacy/src/Selector/Selector.php (offerEnvironmentChoice) Closure typed (string $value) with nullable $defaultEnvironmentId
legacy/src/Command/Organization/OrganizationCommandBase.php Closure typed (string $email) with null default
legacy/src/Command/Team/User/TeamUserAddCommand.php Closure typed (string $value) with null default
legacy/src/Command/Organization/User/OrganizationUserAddCommand.php ArrayArgument::split([null])preg_split(..., null) on optional permissions prompt

Root cause is the same as #85: QuestionHelper::askInput() returns mixed, and Symfony passes null to the validator when the question's default is null. Per the long-term fix shape discussed on CLI-143, validator closures are now typed as ?string with explicit null handling.

In Selector::offerProjectChoice, also switched to [$id] = explode(' - ', …, 2) to avoid an "undefined array key 1" warning when a project has no title (same improvement that addresses Copilot's comment on #85; the same pattern is fixed there in a follow-up).

Several interactive validator closures crashed with a TypeError when the
user pressed Enter to accept a null default:

- Selector::offerProjectChoice: explode(' - ', null) on the project-by-ID
  prompt
- Selector::offerEnvironmentChoice: closure typed (string $value) with
  nullable default $defaultEnvironmentId
- OrganizationCommandBase user picker: closure typed (string $email)
  with null default
- TeamUserAddCommand: closure typed (string $value) with null default
- OrganizationUserAddCommand: optional permissions prompt calling
  ArrayArgument::split([null]) -> preg_split(..., null)

Root cause: QuestionHelper::askInput returns mixed, and Symfony passes
null to the validator when the question's default is null. Type each
closure parameter as ?string and guard null explicitly.

In Selector::offerProjectChoice, also switch to
[$id] = explode(' - ', ..., 2) to avoid an "undefined array key 1"
warning when a project has no title (autocomplete value has no ' - ').

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 23:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens several legacy CLI interactive prompt validators against Symfony passing null when the question default is null and the user presses Enter, preventing TypeErrors in PHP 8+.

Changes:

  • Update multiple askInput() validator closures to accept ?string and explicitly handle null.
  • Avoid explode() warnings in project selection by limiting splits and safely handling null input.
  • Prevent ArrayArgument::split() from receiving null on optional permissions prompts.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
legacy/src/Selector/Selector.php Makes project/environment prompt validators nullable-safe; improves project ID parsing.
legacy/src/Command/Team/User/TeamUserAddCommand.php Makes interactive email validator nullable-safe.
legacy/src/Command/Organization/User/OrganizationUserAddCommand.php Handles null optional permissions input safely before splitting.
legacy/src/Command/Organization/OrganizationCommandBase.php Makes interactive email selection validator nullable-safe.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread legacy/src/Command/Team/User/TeamUserAddCommand.php Outdated
Comment thread legacy/src/Selector/Selector.php Outdated
Distinguish "no input" from "invalid input" in two validators flagged
by review on the parent PR:

- TeamUserAddCommand: when the user presses Enter (null), report
  "An email address is required" instead of "Invalid email address:"
  (the original message also had no space after the colon).
- Selector::offerEnvironmentChoice: when the user presses Enter and
  the default is null, report "An environment ID is required" instead
  of "Environment not found: " (empty).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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