Use more canonical (object)[] instead of new stdClass

Both styles create the exact same object. Casting an array to an
object creates an stdClass object as well. The main benefit of this
syntax is that there is much less repetition. Everything is one
token instead of individual lines, where each line might contain a
typo.

Change-Id: Id43fa2c4b6bd5d9dbc60008427d4a9e14ae3811c
This commit is contained in:
Thiemo Kreuz 2020-08-10 12:55:36 +02:00 committed by Thiemo Kreuz (WMDE)
parent 9474b9c942
commit e5fead8b42
2 changed files with 19 additions and 18 deletions

View file

@ -392,24 +392,25 @@ class ApiEchoNotifications extends ApiQueryBase {
- (int)$timestampsByWiki[$a]->getTimestamp( TS_UNIX );
} );
$row = new stdClass;
$row->event_id = -1;
$row->event_type = 'foreign';
$row->event_variant = null;
$row->event_agent_id = $user->getId();
$row->event_agent_ip = null;
$row->event_page_id = null;
$row->event_extra = serialize( [
'section' => $section ?: 'all',
'wikis' => $wikis,
'count' => $count
] );
$row->event_deleted = 0;
$row = (object)[
'event_id' => -1,
'event_type' => 'foreign',
'event_variant' => null,
'event_agent_id' => $user->getId(),
'event_agent_ip' => null,
'event_page_id' => null,
'event_extra' => serialize( [
'section' => $section ?: 'all',
'wikis' => $wikis,
'count' => $count
] ),
'event_deleted' => 0,
$row->notification_user = $user->getId();
$row->notification_timestamp = $maxTimestamp;
$row->notification_read_timestamp = null;
$row->notification_bundle_hash = md5( 'bogus' );
'notification_user' => $user->getId(),
'notification_timestamp' => $maxTimestamp,
'notification_read_timestamp' => null,
'notification_bundle_hash' => md5( 'bogus' ),
];
// Format output like any other notification
$notif = EchoNotification::newFromRow( $row );

View file

@ -134,7 +134,7 @@ class NotificationControllerTest extends MediaWikiTestCase {
// expected result
[ 123 ],
// users returned from locator
[ null, 'foo', User::newFromId( 123 ), new stdClass, 456 ],
[ null, 'foo', User::newFromId( 123 ), (object)[], 456 ],
],
];
}