From 02bd38cfb1124f8f775732a19c6a8ae05c8b15a5 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:45:37 +0200 Subject: [PATCH] Merge if constructs --- .../backend/behaviors/RelationController.php | 48 +++++++++---------- modules/backend/widgets/Lists.php | 7 +-- modules/backend/widgets/MediaManager.php | 14 +++--- modules/cms/classes/CodeParser.php | 14 ++---- modules/cms/classes/Controller.php | 32 +++++-------- modules/cms/classes/Router.php | 12 ++--- modules/cms/controllers/Index.php | 8 ++-- modules/cms/widgets/TemplateList.php | 6 +-- modules/system/classes/UpdateManager.php | 19 ++++---- 9 files changed, 72 insertions(+), 88 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index cc46b62be..389f2f77b 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -379,11 +379,9 @@ class RelationController extends ControllerBehavior /* * Pivot widget */ - if ($this->manageMode == 'pivot') { - if ($this->pivotWidget = $this->makePivotWidget()) { - $this->controller->relationExtendPivotWidget($this->pivotWidget, $this->field, $this->model); - $this->pivotWidget->bindToController(); - } + if ($this->manageMode == 'pivot' && $this->pivotWidget = $this->makePivotWidget()) { + $this->controller->relationExtendPivotWidget($this->pivotWidget, $this->field, $this->model); + $this->pivotWidget->bindToController(); } } @@ -695,22 +693,22 @@ class RelationController extends ControllerBehavior /* * Constrain the list by the search widget, if available */ - if ($this->toolbarWidget && $this->getConfig('view[showSearch]')) { - if ($searchWidget = $this->toolbarWidget->getSearchWidget()) { - $searchWidget->bindEvent('search.submit', function () use ($widget, $searchWidget) { - $widget->setSearchTerm($searchWidget->getActiveTerm()); - return $widget->onRefresh(); - }); + if ($this->toolbarWidget && $this->getConfig('view[showSearch]') + && $searchWidget = $this->toolbarWidget->getSearchWidget() + ) { + $searchWidget->bindEvent('search.submit', function () use ($widget, $searchWidget) { + $widget->setSearchTerm($searchWidget->getActiveTerm()); + return $widget->onRefresh(); + }); - /* - * Persist the search term across AJAX requests only - */ - if (Request::ajax()) { - $widget->setSearchTerm($searchWidget->getActiveTerm()); - } - else { - $searchWidget->setActiveTerm(null); - } + /* + * Persist the search term across AJAX requests only + */ + if (Request::ajax()) { + $widget->setSearchTerm($searchWidget->getActiveTerm()); + } + else { + $searchWidget->setActiveTerm(null); } } } @@ -1524,12 +1522,10 @@ class RelationController extends ControllerBehavior { $config = isset($this->config->{$mode}) ? $this->config->{$mode} : []; - if ($context = array_get($config, 'context')) { - if (is_array($context)) { - $context = $exists - ? array_get($context, 'update') - : array_get($context, 'create'); - } + if (($context = array_get($config, 'context')) && is_array($context)) { + $context = $exists + ? array_get($context, 'update') + : array_get($context, 'create'); } if (!$context) { diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index d3e2239d7..f0e52b472 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -1478,10 +1478,11 @@ class Lists extends WidgetBase $this->sortColumn = $sortOptions['column']; $this->sortDirection = $sortOptions['direction']; } + + /* + * Supplied default + */ else { - /* - * Supplied default - */ if (is_string($this->defaultSort)) { $this->sortColumn = $this->defaultSort; $this->sortDirection = 'desc'; diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index d6d8d8884..b3f613d93 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -1039,10 +1039,10 @@ class MediaManager extends WidgetBase protected function resizeImage($fullThumbnailPath, $thumbnailParams, $tempFilePath) { $thumbnailDir = dirname($fullThumbnailPath); - if (!File::isDirectory($thumbnailDir)) { - if (File::makeDirectory($thumbnailDir, 0777, true) === false) { - throw new SystemException('Error creating thumbnail directory'); - } + if (!File::isDirectory($thumbnailDir) + && File::makeDirectory($thumbnailDir, 0777, true) === false + ) { + throw new SystemException('Error creating thumbnail directory'); } $targetDimensions = $this->getTargetDimensions($thumbnailParams['width'], $thumbnailParams['height'], $tempFilePath); @@ -1080,10 +1080,10 @@ class MediaManager extends WidgetBase { try { $thumbnailDir = dirname($path); - if (!File::isDirectory($thumbnailDir)) { - if (File::makeDirectory($thumbnailDir, 0777, true) === false) - return; + if (!File::isDirectory($thumbnailDir) && File::makeDirectory($thumbnailDir, 0777, true) === false) { + return; } + File::copy($this->getBrokenImagePath(), $path); } catch (Exception $ex) { diff --git a/modules/cms/classes/CodeParser.php b/modules/cms/classes/CodeParser.php index b4a57564c..e908f1137 100644 --- a/modules/cms/classes/CodeParser.php +++ b/modules/cms/classes/CodeParser.php @@ -192,11 +192,9 @@ class CodeParser $path = array_get($data, 'filePath', $this->getCacheFilePath()); if (is_file($path)) { - if ($className = $this->extractClassFromFile($path)) { - if (class_exists($className)) { - $data['className'] = $className; - return $data; - } + if (($className = $this->extractClassFromFile($path)) && class_exists($className)) { + $data['className'] = $className; + return $data; } @unlink($path); @@ -271,10 +269,8 @@ class CodeParser { $cached = $this->getCachedInfo(); - if ($cached !== null) { - if (array_key_exists($this->filePath, $cached)) { - return $cached[$this->filePath]; - } + if ($cached !== null && array_key_exists($this->filePath, $cached)) { + return $cached[$this->filePath]; } return null; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 4bea8bc1e..91294c7b5 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -828,15 +828,12 @@ class Controller /* * Component alias is supplied */ - else { - if (($componentObj = $this->findComponentByName($componentAlias)) === null) { - if ($throwException) { - throw new CmsException(Lang::get('cms::lang.component.not_found', ['name'=>$componentAlias])); - } - else { - return false; - } + elseif (($componentObj = $this->findComponentByName($componentAlias)) === null) { + if ($throwException) { + throw new CmsException(Lang::get('cms::lang.component.not_found', ['name'=>$componentAlias])); } + + return false; } $partial = null; @@ -870,18 +867,15 @@ class Controller */ $this->vars['__SELF__'] = $componentObj; } - else { - /* - * Process theme partial - */ - if (($partial = Partial::loadCached($this->theme, $name)) === null) { - if ($throwException) { - throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name'=>$name])); - } - else { - return false; - } + /* + * Process theme partial + */ + elseif (($partial = Partial::loadCached($this->theme, $name)) === null) { + if ($throwException) { + throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name'=>$name])); } + + return false; } /* diff --git a/modules/cms/classes/Router.php b/modules/cms/classes/Router.php index f971db9e3..e17bf37e0 100644 --- a/modules/cms/classes/Router.php +++ b/modules/cms/classes/Router.php @@ -331,14 +331,12 @@ class Router $key = $this->getUrlListCacheKey(); $urlList = Cache::get($key, false); - if ( - $urlList && - ($urlList = @unserialize(@base64_decode($urlList))) && - is_array($urlList) + if ($urlList + && ($urlList = @unserialize(@base64_decode($urlList))) + && is_array($urlList) + && array_key_exists($url, $urlList) ) { - if (array_key_exists($url, $urlList)) { - return $urlList[$url]; - } + return $urlList[$url]; } return null; diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index 1ef6f0504..57dc574f2 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -180,10 +180,10 @@ class Index extends Controller $templateData['code'] = $this->convertLineEndings($templateData['code']); } - if (!Request::input('templateForceSave') && $template->mtime) { - if (Request::input('templateMtime') != $template->mtime) { - throw new ApplicationException('mtime-mismatch'); - } + if (!Request::input('templateForceSave') && $template->mtime + && Request::input('templateMtime') != $template->mtime + ) { + throw new ApplicationException('mtime-mismatch'); } $template->attributes = []; diff --git a/modules/cms/widgets/TemplateList.php b/modules/cms/widgets/TemplateList.php index 46b540550..f81aaa056 100644 --- a/modules/cms/widgets/TemplateList.php +++ b/modules/cms/widgets/TemplateList.php @@ -372,10 +372,8 @@ class TemplateList extends WidgetBase { $operator = $exact ? 'is' : 'contains'; - if (strlen($item->title)) { - if (Str::$operator(Str::lower($item->title), $word)) { - return true; - } + if (strlen($item->title) && Str::$operator(Str::lower($item->title), $word)) { + return true; } if (Str::$operator(Str::lower($item->fileName), $word)) { diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index afd2a9ad3..bac12a550 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -189,10 +189,11 @@ class UpdateManager /* * Retry period not passed, skipping. */ - if (!$force && ($retryTimestamp = Parameter::get('system::update.retry'))) { - if (Carbon::createFromTimeStamp($retryTimestamp)->isFuture()) { - return $oldCount; - } + if (!$force + && ($retryTimestamp = Parameter::get('system::update.retry')) + && Carbon::createFromTimeStamp($retryTimestamp)->isFuture() + ) { + return $oldCount; } try { @@ -535,11 +536,11 @@ class UpdateManager /* * Remove the plugin database and version */ - if (!($plugin = $this->pluginManager->findByIdentifier($name))) { - if ($this->versionManager->purgePlugin($name)) { - $this->note('Purged from database: ' . $name); - return $this; - } + if (!($plugin = $this->pluginManager->findByIdentifier($name)) + && $this->versionManager->purgePlugin($name) + ) { + $this->note('Purged from database: ' . $name); + return $this; } if ($this->versionManager->removePlugin($plugin)) {