Page MenuHomePhabricator

Result of EventFactory in EventBus extension is passed to undeclared arrays
Closed, ResolvedPublic

Description

https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/EventBus/+/498393/ - T204575 - refactors the EventBus code, since that patch set many $events variable are used as array in EventBusHooks.php, but are not declared before use.

<file name="includes\EventBusHooks.php">
  <error line="82" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="115" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="154" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="192" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="256" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="331" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="393" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="424" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="482" severity="info" message="Variable $propEvents was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="503" severity="info" message="Variable $linkEvents was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="542" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
  <error line="601" severity="info" message="Variable $events was undeclared, but array fields are being added to it." source="PhanUndeclaredVariableDim"/>
</file>

The variable is often set by the return value of factory functions like createRevisionCreateEvent which are itself declared to return arrays.

It is correct that EventBus::send needs an array of arrays or plain array?

It would be nice to declare the array before use or to set the return value as variable

		$events[] = $eventBus->getFactory()->createRevisionCreateEvent(
			$stream,
			$revision->getRevisionRecord()
		);

		DeferredUpdates::addCallableUpdate(
			function () use ( $eventBus, $events ) {
				$eventBus->send( $events );
			}
		);

Event Timeline

Restricted Application added a project: Analytics. · View Herald TranscriptMay 25 2019, 8:43 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
fdans added a subscriber: fdans.Jun 3 2019, 3:49 PM

We'll be deprecating EventBus pretty soon, so we'll apply this to our current event platform work.

fdans triaged this task as Low priority.Jun 3 2019, 3:49 PM
fdans moved this task from Incoming to Event Platform on the Analytics board.