Skip to content

Commit 7acafa2

Browse files
committed
fix copilot reviews and other fixes
1 parent 6cfa8ce commit 7acafa2

4 files changed

Lines changed: 25 additions & 24 deletions

File tree

system/CLI/AbstractCommand.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public function hasNegation(string $name): bool
358358
* 2. Otherwise, the command is interactive when STDIN is a TTY.
359359
*
360360
* Non-CLI contexts (e.g., a controller invoking `command()`) don't expose
361-
* `STDIN` at all those always resolve as non-interactive.
361+
* `STDIN` at all; those always resolve as non-interactive.
362362
*
363363
* Note: the `--no-interaction` / `-N` flag is folded into the explicit state
364364
* by `run()` before interactive hooks fire, so callers do not need to
@@ -417,12 +417,12 @@ public function setInteractive(bool $interactive): static
417417
*/
418418
final public function run(array $arguments, array $options): int
419419
{
420-
$this->initialize($arguments, $options);
421-
422420
if ($this->interactive === null && $this->hasUnboundOption('no-interaction', $options)) {
423421
$this->interactive = false;
424422
}
425423

424+
$this->initialize($arguments, $options);
425+
426426
if ($this->isInteractive()) {
427427
$this->interact($arguments, $options);
428428
}
@@ -498,9 +498,9 @@ abstract protected function execute(array $arguments, array $options): int;
498498
* @param array<string, list<string>|string|null> $options Parsed options from command line.
499499
* @param bool|null $noInteractionOverride `null` (default) propagates the parent's non-interactive state;
500500
* `true` forces the sub-command non-interactive by injecting
501-
* `--no-interaction`; `false` strips any inherited
502-
* `--no-interaction` so the sub-command resolves its own state
503-
* (TTY detection may still downgrade it).
501+
* `--no-interaction`; `false` removes any forwarded
502+
* `--no-interaction` from `$options` so the sub-command
503+
* resolves its own state (TTY detection may still downgrade it).
504504
*/
505505
protected function call(string $command, array $arguments = [], array $options = [], ?bool $noInteractionOverride = null): int
506506
{
@@ -693,9 +693,10 @@ protected function provideDefaultOptions(): void
693693
* aliases, their value is preserved.
694694
* - `true` forces the sub-command non-interactive regardless of the
695695
* parent, again deferring to a caller-supplied value if present.
696-
* - `false` strips any inherited or propagated `--no-interaction` so the
697-
* sub-command resolves its own state. TTY detection can still force
698-
* non-interactive if STDIN is not a TTY.
696+
* - `false` removes any `--no-interaction` from `$options` (whether
697+
* caller-supplied or inherited) so the sub-command resolves its own
698+
* state. TTY detection can still force non-interactive if STDIN is
699+
* not a TTY.
699700
*
700701
* @param array<string, list<string|null>|string|null> $options
701702
*

tests/_support/Commands/Modern/InteractiveStateProbeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
final class InteractiveStateProbeCommand extends AbstractCommand
2121
{
2222
/**
23-
* Records whether `interact()` fired during the last run a side-channel
23+
* Records whether `interact()` fired during the last run. This is a side-channel
2424
* for asserting on a child fixture created anonymously by `Commands::runCommand()`.
2525
*/
2626
public static bool $interactCalled = false;

tests/system/CLI/AbstractCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ public function testCallStripsInheritedNoInteractionWhenCallerAllowsInteraction(
803803
public function testCallPreservesCallerFlagWhenForcingNonInteractive(): void
804804
{
805805
// When $noInteractionOverride is true and the caller already supplied the flag,
806-
// the resolver must not touch the caller's entry — proved by the child
807-
// still seeing a non-interactive state.
806+
// the resolver must not touch the caller's entry. The child still sees a
807+
// non-interactive state.
808808

809809
$command = new ParentCallsInteractFixtureCommand(new Commands());
810810

user_guide_src/source/cli/cli_modern_commands.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ this order:
7575
3. ``interact(array &$arguments, array &$options): void`` also receives the
7676
raw arguments and options by reference. This is where you prompt the user
7777
for missing input, set values conditionally, or abort early. This hook is
78-
skipped when the command is non-interactive see :ref:`non-interactive-mode`.
78+
skipped when the command is non-interactive (see :ref:`non-interactive-mode`).
7979
4. **Bind & validate.** The framework maps the raw input to the definitions
8080
you declared in ``configure()``, applies defaults, and rejects input that
8181
violates the definitions (missing required argument, unknown option, array
@@ -189,20 +189,20 @@ Non-Interactive Mode
189189
====================
190190

191191
Every modern command accepts ``--no-interaction`` / ``-N`` out of the box.
192-
When the flag is presentor when the command is otherwise non-interactive
192+
When the flag is present, or when the command is otherwise non-interactive,
193193
the ``interact()`` hook is skipped entirely and the command proceeds straight
194194
to bind, validate, and ``execute()``.
195195

196196
Programmatically, the state is exposed through two public methods on
197197
``AbstractCommand``:
198198

199-
- ``isInteractive(): bool`` reports the current state.
200-
- ``setInteractive(bool $interactive): static`` pins the state, overriding
199+
- ``isInteractive(): bool``: reports the current state.
200+
- ``setInteractive(bool $interactive): static``: pins the state, overriding
201201
both the CLI flag and TTY detection. Returns ``$this`` for chaining.
202202

203203
The resolved state follows this precedence:
204204

205-
1. An explicit ``setInteractive(bool)`` call wins — useful when a command
205+
1. An explicit ``setInteractive(bool)`` call wins. Useful when a command
206206
must force a specific mode for safety.
207207
2. Otherwise, the CLI flag ``--no-interaction`` / ``-N`` forces non-interactive state.
208208
3. Otherwise, **STDIN** is probed: if it is not a TTY (piped input, cron,
@@ -217,11 +217,11 @@ sub-command's ``$options`` wins over that propagation.
217217
The propagation can be overridden with the ``$noInteractionOverride``
218218
parameter of ``call()``:
219219

220-
- ``null`` (default) propagate the parent's state.
221-
- ``true`` force the sub-command non-interactive regardless of the parent.
222-
- ``false`` — strip any inherited ``--no-interaction`` so the sub-command
223-
resolves its own state. Note: TTY detection can still downgrade the
224-
sub-command if STDIN is not a TTY.
220+
- ``null`` (default): propagate the parent's state.
221+
- ``true``: force the sub-command non-interactive regardless of the parent.
222+
- ``false``: remove any forwarded ``--no-interaction`` / ``-N`` from the
223+
child ``$options`` so the sub-command resolves its own state. Note: TTY
224+
detection can still downgrade the sub-command if STDIN is not a TTY.
225225

226226
******************
227227
Inside execute()
@@ -539,8 +539,8 @@ covered in the sections above and are not listed here.
539539
:param array $options: Options to forward, keyed by long name, shortcut, or negation.
540540
:param bool|null $noInteractionOverride: Override the sub-command's interactive state.
541541
``null`` propagates the parent's state (default);
542-
``true`` forces non-interactive; ``false`` strips
543-
any inherited ``--no-interaction`` flag.
542+
``true`` forces non-interactive; ``false`` removes
543+
any forwarded ``--no-interaction`` from ``$options``.
544544
:returns: The exit code returned by the called command.
545545

546546
Invokes another modern command. The arguments and options go through

0 commit comments

Comments
 (0)