Like IBufferingStatsdDataFactory, we need an interface that can be used to type-hint and provide the contract to various StatsFactory objects that can be passed around in live code and tests.
IBufferingStatsdDataFactory is implemented by NullStatsdDataFactory (value object) and BufferingStatsdDataFactory (via MW services) which can be used depending on the scenario at hand. When we're dealing with real metrics that we want to buffer and send over the wire, we get an instance of BufferingStatsdDataFactory (via MW services mostly injected). But sometimes consumer code just needs something to deal with (not a hard requirement - like a NULL value object) and we don't want to pass in a full stats data factory (in places we want a default or don't have access to MW services), we just provide a NULL value object (NullStatsdDataFactory) especially in tests etc.
This task is to provide an interface (proposed name: IStatsFactory) that can be implemented by various concrete use cases for the afore mentioned purpose. BagOStuff for example needs a StatsFactory object injected:
public function __construct( array $params = [] ) {
$this->keyspace = $params['keyspace'] ?? 'local';
$this->stats = $params['stats'] ?? new NullStatsFactory();
$this->setLogger( $params['logger'] ?? new NullLogger() );
$asyncHandler = $params['asyncHandler'] ?? null;
if ( is_callable( $asyncHandler ) ) {
$this->asyncHandler = $asyncHandler;
}
}when creating the various caching backends but if not specified in $params, fallback back to a NULL object but we don't yet have this in StatsLib and the NullEmitter won't do the trick or will it? So I propose we introduce an interface for this and have various concrete cases implement it including the null case.