Documentation

DoctorCommand
in package

Read onlyYes
FinalYes

WP-CLI `doctor` command: prints the boot report and exits non-zero when something is broken, so health checks and pipelines can gate on it.

Exit codes: BootReport::EXIT_HEALTHY (0) when healthy, BootReport::EXIT_BROKEN (1) when a check failed, an expected package is missing or, with --strict, a check warned, and self::EXIT_USAGE (2) on invalid arguments.

The logic lives in run(), which returns the exit code and writes through an injected writer; __invoke() is the thin WP-CLI glue that halts with that code. Register it with DoctorCommandRegistrar.

A health gate should pass the full list of packages it expects with --expect. The constructor list belongs to the package that registered the command: if that package fails to load, its list never runs, and a sibling's registration of the same root may answer instead. So a constructor list should name the sibling packages too.

Table of Contents

Constants

EXIT_USAGE  : int = 2
FORMATS  : array<string|int, mixed> = ['text', 'json']

Properties

$expected  : array<string|int, mixed>
$registry  : DiagnosticsRegistry
$writer  : Closure

Methods

__construct()  : mixed
__invoke()  : void
Print the boot report of the registered packages and exit non-zero when one is broken.
run()  : int
Collect, print and grade the report.
defaultWriter()  : callable(string): void
expectedNames()  : array<int, string>
isFlagSet()  : bool
print()  : bool
write()  : void

Constants

FORMATS

private array<string|int, mixed> FORMATS = ['text', 'json']

Properties

Methods

__construct()

public __construct(DiagnosticsRegistry $registry[, array<int, string> $expected = [] ][, null|callable(string): void $writer = null ]) : mixed
Parameters
$registry : DiagnosticsRegistry
$expected : array<int, string> = []

package names that must always be registered; merged with the --expect option

$writer : null|callable(string): void = null

line sink; defaults to WP-CLI output

__invoke()

Print the boot report of the registered packages and exit non-zero when one is broken.

public __invoke(array<int, string> $args, array<string, bool|string> $assocArgs) : void

OPTIONS

[--expect=] : Comma-separated package names that must be registered.

[--strict] : Treat warnings as failures.

[--format=] : Output format.

default: text options:

  • text
  • json

Parameters
$args : array<int, string>

positional arguments (unused)

$assocArgs : array<string, bool|string>

options

run()

Collect, print and grade the report.

public run([array<string, bool|string> $assocArgs = [] ]) : int
Parameters
$assocArgs : array<string, bool|string> = []

expect, strict and format options

Return values
int

defaultWriter()

private defaultWriter() : callable(string): void
Return values
callable(string): void

expectedNames()

private expectedNames(bool|string|null $option) : array<int, string>
Parameters
$option : bool|string|null
Return values
array<int, string>

isFlagSet()

private isFlagSet(bool|string $value) : bool
Parameters
$value : bool|string
Return values
bool

write()

private write(string $line) : void
Parameters
$line : string
On this page

Search results