From 1ac1db6173d76f00ffd21db43c1f9ac5daf32ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 25 Jul 2022 16:48:04 +0200 Subject: [PATCH 1/2] Changed: - rewrote to almost one block of array initialization --- src/Model/Event.php | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Model/Event.php b/src/Model/Event.php index 74bf3bd9c0..f289fd4e4f 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -243,27 +243,29 @@ class Event */ public static function store(array $arr): int { - $event = []; - $event['id'] = intval($arr['id'] ?? 0); - $event['uid'] = intval($arr['uid'] ?? 0); - $event['cid'] = intval($arr['cid'] ?? 0); - $event['guid'] = ($arr['guid'] ?? '') ?: System::createUUID(); - $event['uri'] = ($arr['uri'] ?? '') ?: Item::newURI($event['guid']); - $event['uri-id'] = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]); - $event['type'] = ($arr['type'] ?? '') ?: 'event'; - $event['summary'] = $arr['summary'] ?? ''; - $event['desc'] = $arr['desc'] ?? ''; - $event['location'] = $arr['location'] ?? ''; - $event['allow_cid'] = $arr['allow_cid'] ?? ''; - $event['allow_gid'] = $arr['allow_gid'] ?? ''; - $event['deny_cid'] = $arr['deny_cid'] ?? ''; - $event['deny_gid'] = $arr['deny_gid'] ?? ''; - $event['nofinish'] = intval($arr['nofinish'] ?? (!empty($event['start']) && empty($event['finish']))); + $event = [ + 'id' => intval($arr['id'] ?? 0), + 'uid' => intval($arr['uid'] ?? 0), + 'cid' => intval($arr['cid'] ?? 0), + 'guid' => ($arr['guid'] ?? '') ?: System::createUUID(), + 'type' => ($arr['type'] ?? '') ?: 'event', + 'summary' => $arr['summary'] ?? '', + 'desc' => $arr['desc'] ?? '', + 'location' => $arr['location'] ?? '', + 'allow_cid' => $arr['allow_cid'] ?? '', + 'allow_gid' => $arr['allow_gid'] ?? '', + 'deny_cid' => $arr['deny_cid'] ?? '', + 'deny_gid' => $arr['deny_gid'] ?? '', + 'nofinish' => intval($arr['nofinish'] ?? (!empty($arr['start']) && empty($arr['finish']))), + 'created' => DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now'), + 'edited' => DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now'), + 'start' => DateTimeFormat::utc(($arr['start'] ?? '') ?: DBA::NULL_DATETIME), + 'finish' => DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME), + ]; + + $event['uri'] = ($arr['uri'] ?? '') ?: Item::newURI($event['guid']); + $event['uri-id'] = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]); - $event['created'] = DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now'); - $event['edited'] = DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now'); - $event['start'] = DateTimeFormat::utc(($arr['start'] ?? '') ?: DBA::NULL_DATETIME); - $event['finish'] = DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME); if ($event['finish'] < DBA::NULL_DATETIME) { $event['finish'] = DBA::NULL_DATETIME; } From d1b21eaf422c044c1d4374b8f9208733d211fe41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 25 Jul 2022 17:53:18 +0200 Subject: [PATCH 2/2] Changes: - use local variables --- src/Model/Event.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Model/Event.php b/src/Model/Event.php index f289fd4e4f..712e5861ac 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -243,19 +243,23 @@ class Event */ public static function store(array $arr): int { + $guid = $arr['guid'] ?? '' ?: System::createUUID(); + $uri = $arr['uri'] ?? '' ?: Item::newURI($guid); $event = [ 'id' => intval($arr['id'] ?? 0), 'uid' => intval($arr['uid'] ?? 0), 'cid' => intval($arr['cid'] ?? 0), - 'guid' => ($arr['guid'] ?? '') ?: System::createUUID(), - 'type' => ($arr['type'] ?? '') ?: 'event', - 'summary' => $arr['summary'] ?? '', - 'desc' => $arr['desc'] ?? '', - 'location' => $arr['location'] ?? '', - 'allow_cid' => $arr['allow_cid'] ?? '', - 'allow_gid' => $arr['allow_gid'] ?? '', - 'deny_cid' => $arr['deny_cid'] ?? '', - 'deny_gid' => $arr['deny_gid'] ?? '', + 'guid' => $guid, + 'uri' => $uri, + 'uri-id' => ItemURI::insert(['uri' => $uri, 'guid' => $guid]), + 'type' => ($arr['type'] ?? '') ?: 'event', + 'summary' => $arr['summary'] ?? '', + 'desc' => $arr['desc'] ?? '', + 'location' => $arr['location'] ?? '', + 'allow_cid' => $arr['allow_cid'] ?? '', + 'allow_gid' => $arr['allow_gid'] ?? '', + 'deny_cid' => $arr['deny_cid'] ?? '', + 'deny_gid' => $arr['deny_gid'] ?? '', 'nofinish' => intval($arr['nofinish'] ?? (!empty($arr['start']) && empty($arr['finish']))), 'created' => DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now'), 'edited' => DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now'), @@ -263,8 +267,6 @@ class Event 'finish' => DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME), ]; - $event['uri'] = ($arr['uri'] ?? '') ?: Item::newURI($event['guid']); - $event['uri-id'] = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]); if ($event['finish'] < DBA::NULL_DATETIME) { $event['finish'] = DBA::NULL_DATETIME;