Page MenuHomePhabricator

StatusValue should support fluent interface
Closed, ResolvedPublic

Description

StatusValue is a wrapper over a value with optional errors/warnings. It should support fluent interface so that instead of

$status = StatusValue::newGood();
// Some time later
$status->fatal( 'blablabla' );
return $status;

We could do

$status = StatusValue::newGood();
// Some time later
return $status->fatal( 'blablabla' );

Theres a lot of other usage patterns that would benefit from StatusValue being fluent.

This tasks consists of 3 parts:

  • Identify which methods of the StatusValue class are setters
  • Convert it to fluent interface
  • Find some usages in core where we could benefit from it being fluent and replace them.

Event Timeline

If its just changing a good status to a fatal one and returning, that should be done with return StatusValue::newFatal( 'blablabla' );. A fluent interface would make sense if you are setting multiple errors at the same time, but I haven't seen that done.

Our usual pattern with $status in large methods is to create a $result = StatusValue::newGood() in the beginning, and then modify it throughout method execution. With this pattern if you do return StatusValue::newFatal( 'blablabla' ); - you loose all the warnings that have been accumulated over the method execution.

Change 709490 had a related patch set uploaded (by TChin; author: TChin):

[mediawiki/core@master] Support fluent interface for StatusValue

https://gerrit.wikimedia.org/r/709490

Change 709490 merged by jenkins-bot:

[mediawiki/core@master] Support fluent interface for StatusValue

https://gerrit.wikimedia.org/r/709490