Issue #3619901: Document the negotiated domain as nullable, because it is NULL until something negotiates one

DomainNegotiationContext::$domain starts as NULL and is only ever set by setDomain(), so everything that hands it back can return NULL: on the CLI, during cron, and whenever no domain matches the request. The class says so itself one method below the getter, where hasDomain() is $this->domain !== NULL.

Four docblocks claimed otherwise, and this corrects them:

  • DomainNegotiationContext::$domain, the property the rest of the chain returns.
  • DomainNegotiationContext::getDomain(), which returns that property directly.
  • DomainNegotiatorInterface::getActiveDomain(), which is what a consumer type hints against.
  • DomainSourcePathProcessor::getActiveDomain(), which reads the same context.

No behavior change and no signature change. The callers in this project already treat the value as nullable, and DomainTestTrait::getActiveDomain() has documented it as nullable all along.

Why it matters to a consumer

A module running static analysis is told its null guard is dead code. Against domain 3.0.1 PHPStan reports instanceof.alwaysTrue on such a guard and against the 3.x branch it does not, for the same consumer code. Deleting the guard on that advice produces a fatal the first time the code runs on the CLI or against an unmatched host.

Branches

The correction to DomainNegotiatorInterface::getActiveDomain() is already on 3.x; this brings it to 3.0.x. The other three are wrong on both branches, so 3.x wants the same change: happy to open that MR too, or fold it in, whichever you prefer.

Merge request reports

Loading
Loading