From: Derick Alangi Date: Wed, 20 Mar 2019 18:53:00 +0000 (+0100) Subject: context: Cleanup is_null() checks and irrelevant else code paths X-Git-Tag: 1.34.0-rc.0~2456^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=5479c37368a60df7c0bdee35554b465effa1b491;p=lhc%2Fweb%2Fwiklou.git context: Cleanup is_null() checks and irrelevant else code paths This class specifically has these 2 things in many cases and converts into the use of a tenary operations. Quoting @Thiemo_WMDE from Gerrit comment: "The ?: operator will skip empty arrays, empty strings, as well as the string "0". But this is not a problem here because the properties under test are all objects. Objects are always considered true in PHP." Sample change can be seen below as, from; ``` if ( !is_null( $this->skin )) { return $this->skin; } else { return $this->getContext()->getSkin(); } ``` to ``` return $this->skin ?: $this->getContext()->getSkin(); ``` Change-Id: I377b118d86a24c7bcb15512f6714e6201a3e36ee --- diff --git a/includes/context/DerivativeContext.php b/includes/context/DerivativeContext.php index 9817c3fc4f..d32617e0c3 100644 --- a/includes/context/DerivativeContext.php +++ b/includes/context/DerivativeContext.php @@ -91,11 +91,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return Config */ public function getConfig() { - if ( !is_null( $this->config ) ) { - return $this->config; - } else { - return $this->getContext()->getConfig(); - } + return $this->config ?: $this->getContext()->getConfig(); } /** @@ -111,11 +107,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return Timing */ public function getTiming() { - if ( !is_null( $this->timing ) ) { - return $this->timing; - } else { - return $this->getContext()->getTiming(); - } + return $this->timing ?: $this->getContext()->getTiming(); } /** @@ -129,11 +121,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return WebRequest */ public function getRequest() { - if ( !is_null( $this->request ) ) { - return $this->request; - } else { - return $this->getContext()->getRequest(); - } + return $this->request ?: $this->getContext()->getRequest(); } /** @@ -147,11 +135,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return Title|null */ public function getTitle() { - if ( !is_null( $this->title ) ) { - return $this->title; - } else { - return $this->getContext()->getTitle(); - } + return $this->title ?: $this->getContext()->getTitle(); } /** @@ -165,11 +149,13 @@ class DerivativeContext extends ContextSource implements MutableContext { public function canUseWikiPage() { if ( $this->wikipage !== null ) { return true; - } elseif ( $this->title !== null ) { + } + + if ( $this->title !== null ) { return $this->title->canExist(); - } else { - return $this->getContext()->canUseWikiPage(); } + + return $this->getContext()->canUseWikiPage(); } /** @@ -190,11 +176,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return WikiPage */ public function getWikiPage() { - if ( !is_null( $this->wikipage ) ) { - return $this->wikipage; - } else { - return $this->getContext()->getWikiPage(); - } + return $this->wikipage ?: $this->getContext()->getWikiPage(); } /** @@ -208,11 +190,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return OutputPage */ public function getOutput() { - if ( !is_null( $this->output ) ) { - return $this->output; - } else { - return $this->getContext()->getOutput(); - } + return $this->output ?: $this->getContext()->getOutput(); } /** @@ -226,11 +204,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return User */ public function getUser() { - if ( !is_null( $this->user ) ) { - return $this->user; - } else { - return $this->getContext()->getUser(); - } + return $this->user ?: $this->getContext()->getUser(); } /** @@ -255,11 +229,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @since 1.19 */ public function getLanguage() { - if ( !is_null( $this->lang ) ) { - return $this->lang; - } else { - return $this->getContext()->getLanguage(); - } + return $this->lang ?: $this->getContext()->getLanguage(); } /** @@ -274,11 +244,7 @@ class DerivativeContext extends ContextSource implements MutableContext { * @return Skin */ public function getSkin() { - if ( !is_null( $this->skin ) ) { - return $this->skin; - } else { - return $this->getContext()->getSkin(); - } + return $this->skin ?: $this->getContext()->getSkin(); } /**