From: Mikael Nordfeldth Date: Mon, 5 May 2014 17:05:05 +0000 (+0200) Subject: Functions should return quickly (cosmetic) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=30f4f5606c25f405e6a47e5f26e4b1e96a080e61;p=quix0rs-gnu-social.git Functions should return quickly (cosmetic) ...rather than have long if statements encapsuling everything. --- diff --git a/lib/microappplugin.php b/lib/microappplugin.php index 4da3bef935..ec67d9fe2e 100644 --- a/lib/microappplugin.php +++ b/lib/microappplugin.php @@ -254,11 +254,11 @@ abstract class MicroAppPlugin extends Plugin */ function onNoticeDeleteRelated($notice) { - if ($this->isMyNotice($notice)) { - $this->deleteRelated($notice); + if (!$this->isMyNotice($notice)) { + return true; } - return true; + $this->deleteRelated($notice); } /** @@ -339,12 +339,12 @@ abstract class MicroAppPlugin extends Plugin */ function onStartActivityObjectFromNotice($notice, &$object) { - if ($this->isMyNotice($notice)) { - $object = $this->activityObjectFromNotice($notice); - return false; + if (!$this->isMyNotice($notice)) { + return true; } - return true; + $object = $this->activityObjectFromNotice($notice); + return false; } /** @@ -357,29 +357,28 @@ abstract class MicroAppPlugin extends Plugin */ function onStartHandleFeedEntryWithProfile($activity, $oprofile, &$notice) { - if ($this->isMyActivity($activity)) { + if (!$this->isMyActivity($activity)) { + return true; + } - $actor = $oprofile->checkAuthorship($activity); + $actor = $oprofile->checkAuthorship($activity); - if (!$actor instanceof Ostatus_profile) { - // TRANS: Client exception thrown when no author for an activity was found. - throw new ClientException(_('Cannot get author for activity.')); - } + if (!$actor instanceof Ostatus_profile) { + // TRANS: Client exception thrown when no author for an activity was found. + throw new ClientException(_('Cannot get author for activity.')); + } - $object = $activity->objects[0]; + $object = $activity->objects[0]; - $options = array('uri' => $object->id, - 'url' => $object->link, - 'is_local' => Notice::REMOTE, - 'source' => 'ostatus'); + $options = array('uri' => $object->id, + 'url' => $object->link, + 'is_local' => Notice::REMOTE, + 'source' => 'ostatus'); - // $actor is an ostatus_profile - $notice = $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options); + // $actor is an ostatus_profile + $notice = $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options); - return false; - } - - return true; + return false; } /** @@ -393,51 +392,50 @@ abstract class MicroAppPlugin extends Plugin function onStartHandleSalmonTarget($activity, $target) { - if ($this->isMyActivity($activity)) { - $this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap."); - - if ($target instanceof User_group) { - $uri = $target->getUri(); - if (!array_key_exists($uri, $activity->context->attention)) { - // @todo FIXME: please document (i18n). - // TRANS: Client exception thrown when ... - throw new ClientException(_('Object not posted to this group.')); - } - } else if ($target instanceof User) { - $uri = $target->uri; - $original = null; - if (!empty($activity->context->replyToID)) { - $original = Notice::getKV('uri', - $activity->context->replyToID); - } - if (!array_key_exists($uri, $activity->context->attention) && - (empty($original) || - $original->profile_id != $target->id)) { - // @todo FIXME: Please document (i18n). - // TRANS: Client exception when ... - throw new ClientException(_('Object not posted to this user.')); - } - } else { - // TRANS: Server exception thrown when a micro app plugin uses a target that cannot be handled. - throw new ServerException(_('Do not know how to handle this kind of target.')); - } + if (!$this->isMyActivity($activity)) { + return true; + } + + $this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap."); - $actor = Ostatus_profile::ensureActivityObjectProfile($activity->actor); + if ($target instanceof User_group) { + $uri = $target->getUri(); + if (!array_key_exists($uri, $activity->context->attention)) { + // @todo FIXME: please document (i18n). + // TRANS: Client exception thrown when ... + throw new ClientException(_('Object not posted to this group.')); + } + } else if ($target instanceof User) { + $uri = $target->uri; + $original = null; + if (!empty($activity->context->replyToID)) { + $original = Notice::getKV('uri', $activity->context->replyToID); + } + if (!array_key_exists($uri, $activity->context->attention) && + (empty($original) || + $original->profile_id != $target->id)) { + // @todo FIXME: Please document (i18n). + // TRANS: Client exception when ... + throw new ClientException(_('Object not posted to this user.')); + } + } else { + // TRANS: Server exception thrown when a micro app plugin uses a target that cannot be handled. + throw new ServerException(_('Do not know how to handle this kind of target.')); + } - $object = $activity->objects[0]; + $actor = Ostatus_profile::ensureActivityObjectProfile($activity->actor); - $options = array('uri' => $object->id, - 'url' => $object->link, - 'is_local' => Notice::REMOTE, - 'source' => 'ostatus'); + $object = $activity->objects[0]; - // $actor is an ostatus_profile - $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options); + $options = array('uri' => $object->id, + 'url' => $object->link, + 'is_local' => Notice::REMOTE, + 'source' => 'ostatus'); - return false; - } + // $actor is an ostatus_profile + $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options); - return true; + return false; } /** @@ -451,19 +449,18 @@ abstract class MicroAppPlugin extends Plugin */ function onStartAtomPubNewActivity(&$activity, $user, &$notice) { - if ($this->isMyActivity($activity)) { + if (!$this->isMyActivity($activity)) { + return true; + } - $options = array('source' => 'atompub'); + $options = array('source' => 'atompub'); - // $user->getProfile() is a Profile - $notice = $this->saveNoticeFromActivity($activity, - $user->getProfile(), - $options); + // $user->getProfile() is a Profile + $notice = $this->saveNoticeFromActivity($activity, + $user->getProfile(), + $options); - return false; - } - - return true; + return false; } /** @@ -479,27 +476,26 @@ abstract class MicroAppPlugin extends Plugin */ function onStartImportActivity($user, $author, $activity, $trusted, &$done) { - if ($this->isMyActivity($activity)) { - - $obj = $activity->objects[0]; + if (!$this->isMyActivity($activity)) { + return true; + } - $options = array('uri' => $object->id, - 'url' => $object->link, - 'source' => 'restore'); + $obj = $activity->objects[0]; - // $user->getProfile() is a Profile - $saved = $this->saveNoticeFromActivity($activity, - $user->getProfile(), - $options); + $options = array('uri' => $object->id, + 'url' => $object->link, + 'source' => 'restore'); - if (!empty($saved)) { - $done = true; - } + // $user->getProfile() is a Profile + $saved = $this->saveNoticeFromActivity($activity, + $user->getProfile(), + $options); - return false; + if (!empty($saved)) { + $done = true; } - return true; + return false; } /**