diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 86c47b42c..a266fcb86 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -5,7 +5,6 @@ use Str; use Lang; use Flash; use Event; -use Input; use Redirect; use Backend; use Backend\Classes\ControllerBehavior; @@ -437,8 +436,7 @@ class FormController extends ControllerBehavior protected function createModel() { $class = $this->config->modelClass; - $model = new $class; - return $model; + return new $class; } /** @@ -473,7 +471,7 @@ class FormController extends ControllerBehavior $redirect = Redirect::to($redirectUrl); } else { // Process relative redirects - $redirect = ($redirectUrl) ? Backend::redirect($redirectUrl) : null; + $redirect = $redirectUrl ? Backend::redirect($redirectUrl) : null; } return $redirect; diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index 6b371f68b..a84a203d1 100644 --- a/modules/backend/behaviors/ImportExportController.php +++ b/modules/backend/behaviors/ImportExportController.php @@ -590,9 +590,7 @@ class ImportExportController extends ControllerBehavior { $lists = $this->controller->makeLists(); - $widget = isset($lists[$definition]) - ? $lists[$definition] - : reset($lists); + $widget = $lists[$definition] ?? reset($lists); /* * Parse options @@ -697,8 +695,7 @@ class ImportExportController extends ControllerBehavior $widgetConfig->alias = $type.'OptionsForm'; $widgetConfig->arrayName = ucfirst($type).'Options'; - $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); - return $widget; + return $this->makeWidget('Backend\Widgets\Form', $widgetConfig); } return null; diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index c0c6898d3..3a45521c2 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -1,6 +1,5 @@ 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(); } } @@ -423,7 +420,7 @@ class RelationController extends ControllerBehavior /* * Determine the partial to use based on the supplied section option */ - $section = (isset($options['section'])) ? $options['section'] : null; + $section = $options['section'] ?? null; switch (strtolower($section)) { case 'toolbar': return $this->toolbarWidget ? $this->toolbarWidget->render() : null; @@ -695,22 +692,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); } } } @@ -905,8 +902,7 @@ class RelationController extends ControllerBehavior $config->model->setRelation('pivot', $pivotModel); } - $widget = $this->makeWidget('Backend\Widgets\Form', $config); - return $widget; + return $this->makeWidget('Backend\Widgets\Form', $config); } // @@ -1448,9 +1444,8 @@ class RelationController extends ControllerBehavior if ($this->eventTarget == 'button-link') { return 'backend::lang.relation.link_a_new'; } - else { - return 'backend::lang.relation.add_a_new'; - } + + return 'backend::lang.relation.add_a_new'; case 'form': if ($this->readOnly) { return 'backend::lang.relation.preview_name'; @@ -1511,9 +1506,8 @@ class RelationController extends ControllerBehavior if ($this->eventTarget == 'button-add') { return 'list'; } - else { - return 'form'; - } + + return 'form'; } } @@ -1522,14 +1516,12 @@ class RelationController extends ControllerBehavior */ protected function evalFormContext($mode = 'manage', $exists = false) { - $config = isset($this->config->{$mode}) ? $this->config->{$mode} : []; + $config = $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) { @@ -1605,9 +1597,8 @@ class RelationController extends ControllerBehavior if ($throwException) { throw new ApplicationException('Missing configuration for '.$mode.'.'.$type.' in RelationController definition '.$this->field); } - else { - return false; - } + + return false; } return $this->makeConfig($config); diff --git a/modules/backend/behaviors/ReorderController.php b/modules/backend/behaviors/ReorderController.php index e0c7c9981..28a602394 100644 --- a/modules/backend/behaviors/ReorderController.php +++ b/modules/backend/behaviors/ReorderController.php @@ -55,7 +55,7 @@ class ReorderController extends ControllerBehavior * - simple: October\Rain\Database\Traits\Sortable * - nested: October\Rain\Database\Traits\NestedTree */ - protected $sortMode = null; + protected $sortMode; /** * @var Backend\Classes\WidgetBase Reference to the widget used for the toolbar. diff --git a/modules/backend/classes/AuthManager.php b/modules/backend/classes/AuthManager.php index 9fd62508d..c56dc6356 100644 --- a/modules/backend/classes/AuthManager.php +++ b/modules/backend/classes/AuthManager.php @@ -150,9 +150,7 @@ class AuthManager extends RainAuthManager $tabs = []; foreach ($this->listPermissions() as $permission) { - $tab = isset($permission->tab) - ? $permission->tab - : 'backend::lang.form.undefined_tab'; + $tab = $permission->tab ?? 'backend::lang.form.undefined_tab'; if (!array_key_exists($tab, $tabs)) { $tabs[$tab] = []; diff --git a/modules/backend/classes/BackendController.php b/modules/backend/classes/BackendController.php index 4330761c6..6da4e0450 100644 --- a/modules/backend/classes/BackendController.php +++ b/modules/backend/classes/BackendController.php @@ -82,8 +82,8 @@ class BackendController extends ControllerBase /* * Look for a Module controller */ - $module = isset($params[0]) ? $params[0] : 'backend'; - $controller = isset($params[1]) ? $params[1] : 'index'; + $module = $params[0] ?? 'backend'; + $controller = $params[1] ?? 'index'; self::$action = $action = isset($params[2]) ? $this->parseAction($params[2]) : 'index'; self::$params = $controllerParams = array_slice($params, 3); $controllerClass = '\\'.$module.'\Controllers\\'.$controller; @@ -100,7 +100,7 @@ class BackendController extends ControllerBase */ if (count($params) >= 2) { list($author, $plugin) = $params; - $controller = isset($params[2]) ? $params[2] : 'index'; + $controller = $params[2] ?? 'index'; self::$action = $action = isset($params[3]) ? $this->parseAction($params[3]) : 'index'; self::$params = $controllerParams = array_slice($params, 4); $controllerClass = '\\'.$author.'\\'.$plugin.'\Controllers\\'.$controller; @@ -136,7 +136,7 @@ class BackendController extends ControllerBase $controller = Str::normalizeClassName($controller); $controllerFile = $inPath.strtolower(str_replace('\\', '/', $controller)) . '.php'; if ($controllerFile = File::existsInsensitive($controllerFile)) { - include_once($controllerFile); + include_once $controllerFile; } } diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index 24f0b6663..4ce71dfca 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -1,6 +1,5 @@ suppressView && is_null($result)) { + if (!$this->suppressView && $result === null) { return $this->makeView($actionName); } @@ -520,7 +519,7 @@ class Controller extends Extendable if (($widget = $this->widget->{$widgetName}) && $widget->methodExists($handlerName)) { $result = $this->runAjaxHandlerForWidget($widget, $handlerName); - return ($result) ?: true; + return $result ?: true; } } else { @@ -531,7 +530,7 @@ class Controller extends Extendable if ($this->methodExists($pageHandler)) { $result = call_user_func_array([$this, $pageHandler], $this->params); - return ($result) ?: true; + return $result ?: true; } /* @@ -539,7 +538,7 @@ class Controller extends Extendable */ if ($this->methodExists($handler)) { $result = call_user_func_array([$this, $handler], $this->params); - return ($result) ?: true; + return $result ?: true; } /* @@ -551,7 +550,7 @@ class Controller extends Extendable foreach ((array) $this->widget as $widget) { if ($widget->methodExists($handler)) { $result = $this->runAjaxHandlerForWidget($widget, $handler); - return ($result) ?: true; + return $result ?: true; } } } diff --git a/modules/backend/classes/ControllerBehavior.php b/modules/backend/classes/ControllerBehavior.php index 99beca86d..95b711566 100644 --- a/modules/backend/classes/ControllerBehavior.php +++ b/modules/backend/classes/ControllerBehavior.php @@ -81,7 +81,7 @@ class ControllerBehavior extends ExtensionBase /* * Return all config */ - if (is_null($name)) { + if ($name === null) { return $this->config; } diff --git a/modules/backend/classes/FilterScope.php b/modules/backend/classes/FilterScope.php index 683b6915d..d82cb1f81 100644 --- a/modules/backend/classes/FilterScope.php +++ b/modules/backend/classes/FilterScope.php @@ -54,7 +54,7 @@ class FilterScope /** * @var string Specifies contextual visibility of this form scope. */ - public $context = null; + public $context; /** * @var bool Specify if the scope is disabled or not. diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index a8980ae6e..dc7109c1d 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -94,12 +94,12 @@ class FormField /** * @var string Specifies contextual visibility of this form field. */ - public $context = null; + public $context; /** * @var bool Specifies if this field is mandatory. */ - public $required = null; + public $required; /** * @var bool Specify if the field is read-only or not. @@ -234,9 +234,8 @@ class FormField return []; } - else { - $this->options = $value; - } + + $this->options = $value; return $this; } @@ -266,7 +265,7 @@ class FormField */ protected function evalConfig($config) { - if (is_null($config)) { + if ($config === null) { $config = []; } @@ -567,9 +566,8 @@ class FormField if ($arrayName) { return $arrayName.'['.implode('][', HtmlHelper::nameToArray($this->fieldName)).']'; } - else { - return $this->fieldName; - } + + return $this->fieldName; } /** diff --git a/modules/backend/classes/FormTabs.php b/modules/backend/classes/FormTabs.php index 253c8e358..ea755a55e 100644 --- a/modules/backend/classes/FormTabs.php +++ b/modules/backend/classes/FormTabs.php @@ -35,7 +35,7 @@ class FormTabs implements IteratorAggregate, ArrayAccess /** * @var bool Should these tabs stretch to the bottom of the page layout. */ - public $stretch = null; + public $stretch; /** * @var boolean If set to TRUE, fields will not be displayed in tabs. @@ -232,6 +232,6 @@ class FormTabs implements IteratorAggregate, ArrayAccess */ public function offsetGet($offset) { - return isset($this->fields[$offset]) ? $this->fields[$offset] : null; + return $this->fields[$offset] ?? null; } } diff --git a/modules/backend/classes/NavigationManager.php b/modules/backend/classes/NavigationManager.php index 0ea6770f6..8af12ee33 100644 --- a/modules/backend/classes/NavigationManager.php +++ b/modules/backend/classes/NavigationManager.php @@ -317,7 +317,7 @@ class NavigationManager { $activeItem = null; - if (!is_null($owner) && !is_null($code)) { + if ($owner !== null && $code !== null) { $activeItem = @$this->items[$this->makeItemKey($owner, $code)]; } else { foreach ($this->listMainMenuItems() as $item) { @@ -466,9 +466,7 @@ class NavigationManager { $key = $owner.$mainMenuItemCode; - return array_key_exists($key, $this->contextSidenavPartials) - ? $this->contextSidenavPartials[$key] - : null; + return $this->contextSidenavPartials[$key] ?? null; } /** diff --git a/modules/backend/classes/Skin.php b/modules/backend/classes/Skin.php index 47facbaac..e46865c3f 100644 --- a/modules/backend/classes/Skin.php +++ b/modules/backend/classes/Skin.php @@ -80,11 +80,10 @@ abstract class Skin ? $this->publicSkinPath . $path : $this->skinPath . $path; } - else { - return $isPublic - ? $this->defaultPublicSkinPath . $path - : $this->defaultSkinPath . $path; - } + + return $isPublic + ? $this->defaultPublicSkinPath . $path + : $this->defaultSkinPath . $path; } /** diff --git a/modules/backend/classes/WidgetBase.php b/modules/backend/classes/WidgetBase.php index 468f56d81..3444b91ad 100644 --- a/modules/backend/classes/WidgetBase.php +++ b/modules/backend/classes/WidgetBase.php @@ -1,7 +1,5 @@ alias)) { - $this->alias = (isset($this->config->alias)) ? $this->config->alias : $this->defaultAlias; + $this->alias = $this->config->alias ?? $this->defaultAlias; } /* diff --git a/modules/backend/classes/WidgetManager.php b/modules/backend/classes/WidgetManager.php index 18ce9e47c..91972173b 100644 --- a/modules/backend/classes/WidgetManager.php +++ b/modules/backend/classes/WidgetManager.php @@ -103,7 +103,7 @@ class WidgetManager $widgetInfo = ['code' => $widgetInfo]; } - $widgetCode = isset($widgetInfo['code']) ? $widgetInfo['code'] : null; + $widgetCode = $widgetInfo['code'] ?? null; if (!$widgetCode) { $widgetCode = Str::getClassId($className); diff --git a/modules/backend/controllers/Auth.php b/modules/backend/controllers/Auth.php index a024c6b18..849a2675f 100644 --- a/modules/backend/controllers/Auth.php +++ b/modules/backend/controllers/Auth.php @@ -54,9 +54,8 @@ class Auth extends Controller if (post('postback')) { return $this->signin_onSubmit(); } - else { - $this->bodyClass .= ' preload'; - } + + $this->bodyClass .= ' preload'; } catch (Exception $ex) { Flash::error($ex->getMessage()); @@ -75,7 +74,7 @@ class Auth extends Controller throw new ValidationException($validation); } - if (is_null($remember = config('cms.backendForceRemember', true))) { + if (($remember = config('cms.backendForceRemember', true)) === null) { $remember = (bool) post('remember'); } diff --git a/modules/backend/controllers/Index.php b/modules/backend/controllers/Index.php index 962186efd..28f7289c1 100644 --- a/modules/backend/controllers/Index.php +++ b/modules/backend/controllers/Index.php @@ -1,7 +1,6 @@ mode = strtolower($this->mode); if ($this->minDate !== null) { - $this->minDate = is_integer($this->minDate) + $this->minDate = is_int($this->minDate) ? Carbon::createFromTimestamp($this->minDate) : Carbon::parse($this->minDate); } if ($this->maxDate !== null) { - $this->maxDate = is_integer($this->maxDate) + $this->maxDate = is_int($this->maxDate) ? Carbon::createFromTimestamp($this->maxDate) : Carbon::parse($this->maxDate); } diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index ad1395f29..4d3d3fb60 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -1,6 +1,5 @@ imageWidth) + $cssDimensions .= $this->imageWidth ? 'width: '.$this->imageWidth.'px;' : 'width: '.$this->imageHeight.'px;'; @@ -216,7 +215,7 @@ class FileUpload extends FormWidgetBase : 'height: auto;'; } else { - $cssDimensions .= ($this->imageWidth) + $cssDimensions .= $this->imageWidth ? 'width: '.$this->imageWidth.'px;' : 'width: auto;'; diff --git a/modules/backend/formwidgets/MediaFinder.php b/modules/backend/formwidgets/MediaFinder.php index 817d0af78..87c8c4c65 100644 --- a/modules/backend/formwidgets/MediaFinder.php +++ b/modules/backend/formwidgets/MediaFinder.php @@ -1,7 +1,5 @@ resolveModelAttribute($this->valueFrom); - if (!is_null($model)) { + if ($model !== null) { return $model->{$attribute}; } diff --git a/modules/backend/formwidgets/Relation.php b/modules/backend/formwidgets/Relation.php index 27f8259a0..4851aba9f 100644 --- a/modules/backend/formwidgets/Relation.php +++ b/modules/backend/formwidgets/Relation.php @@ -1,11 +1,8 @@ 'Настройка на списък', 'setup_help' => 'Използвайте тикчетата, за да изберете колони, които искате да видите в списъка. Можете да промените позицията на колони, като ги плъзнете нагоре или надолу.', 'records_per_page' => 'Записи на страница', - 'records_per_page_help' => 'Select the number of records per page to display. Please note that high number of records on a single page can reduce performance.', 'records_per_page_help' => 'Изберете брой на записи за показване на страница. Моля, имайте предвид, че голям брой записи на една страница може да забави работата на страницата.', 'delete_selected' => 'Изтрии избраните', 'delete_selected_empty' => 'Не са избрани записи за изтриване.', diff --git a/modules/backend/lang/fa/lang.php b/modules/backend/lang/fa/lang.php index c4f52879f..e8c5f005a 100644 --- a/modules/backend/lang/fa/lang.php +++ b/modules/backend/lang/fa/lang.php @@ -555,8 +555,6 @@ return [ 'direction_asc' => 'صعودی', 'direction_desc' => 'نزولی', 'folder' => 'پوشه', - 'direction_asc' => 'صعودی', - 'direction_desc' => 'نزولی', 'no_files_found' => 'فایلی با درخواست شما یافت نشد', 'delete_empty' => 'لطفا موارد را جهت حذف انتخاب نمایید', 'delete_confirm' => 'آیا از حذف مورد(های) انتخاب شده اطمینان دارید؟', diff --git a/modules/backend/models/BrandSetting.php b/modules/backend/models/BrandSetting.php index 4682ee436..389f12d12 100644 --- a/modules/backend/models/BrandSetting.php +++ b/modules/backend/models/BrandSetting.php @@ -131,9 +131,7 @@ class BrandSetting extends Model self::get('custom_css') ); - $css = $parser->getCss(); - - return $css; + return $parser->getCss(); } // diff --git a/modules/backend/models/EditorSetting.php b/modules/backend/models/EditorSetting.php index 5429b20a9..9dc9d86ec 100644 --- a/modules/backend/models/EditorSetting.php +++ b/modules/backend/models/EditorSetting.php @@ -182,8 +182,6 @@ class EditorSetting extends Model $parser->parse($customStyles); - $css = $parser->getCss(); - - return $css; + return $parser->getCss(); } } diff --git a/modules/backend/models/Preference.php b/modules/backend/models/Preference.php index 5f1b53529..43bbfc3d7 100644 --- a/modules/backend/models/Preference.php +++ b/modules/backend/models/Preference.php @@ -9,7 +9,6 @@ use BackendAuth; use DirectoryIterator; use DateTime; use DateTimeZone; -use Carbon\Carbon; /** * Backend preferences for the backend user diff --git a/modules/backend/models/User.php b/modules/backend/models/User.php index de8ab30fa..1ac926a03 100644 --- a/modules/backend/models/User.php +++ b/modules/backend/models/User.php @@ -96,12 +96,11 @@ class User extends UserBase if ($this->avatar) { return $this->avatar->getThumb($size, $size, $options); } - else { - return '//www.gravatar.com/avatar/' . - md5(strtolower(trim($this->email))) . - '?s='. $size . - '&d='. urlencode($default); - } + + return '//www.gravatar.com/avatar/' . + md5(strtolower(trim($this->email))) . + '?s='. $size . + '&d='. urlencode($default); } /** diff --git a/modules/backend/models/UserPreference.php b/modules/backend/models/UserPreference.php index 97a26e159..cb7ee5846 100644 --- a/modules/backend/models/UserPreference.php +++ b/modules/backend/models/UserPreference.php @@ -1,8 +1,6 @@ value[0]; $max = $scope->value[1]; - $params['minStr'] = $min ? $min : ''; - $params['min'] = $min ? $min : null; + $params['minStr'] = $min ?: ''; + $params['min'] = $min ?: null; - $params['maxStr'] = $max ? $max : '∞'; - $params['max'] = $max ? $max : null; + $params['maxStr'] = $max ?: '∞'; + $params['max'] = $max ?: null; } break; @@ -195,7 +195,7 @@ class Filter extends WidgetBase break; case 'checkbox': - $checked = post('value') == 'true' ? true : false; + $checked = post('value') == 'true'; $this->setScopeValue($scope, $checked); break; @@ -263,7 +263,7 @@ class Filter extends WidgetBase case 'text': $values = post('options.value'); - if (!is_null($values) && $values !== '') { + if ($values !== null && $values !== '') { list($value) = $values; } else { @@ -574,7 +574,7 @@ class Filter extends WidgetBase * Check that the filter scope matches the active context */ if ($scopeObj->context !== null) { - $context = (is_array($scopeObj->context)) ? $scopeObj->context : [$scopeObj->context]; + $context = is_array($scopeObj->context) ? $scopeObj->context : [$scopeObj->context]; if (!in_array($this->getContext(), $context)) { continue; } @@ -634,8 +634,8 @@ class Filter extends WidgetBase */ protected function makeFilterScope($name, $config) { - $label = (isset($config['label'])) ? $config['label'] : null; - $scopeType = isset($config['type']) ? $config['type'] : null; + $label = $config['label'] ?? null; + $scopeType = $config['type'] ?? null; $scope = new FilterScope($name, $label); $scope->displayAs($scopeType, $config); @@ -755,6 +755,8 @@ class Filter extends WidgetBase } } + break; + case 'numberrange': if (is_array($scope->value) && count($scope->value) > 1) { list($min, $max) = array_values($scope->value); diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 68a1768a0..28255f22d 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -56,7 +56,7 @@ class Form extends WidgetBase * @var string The context of this form, fields that do not belong * to this context will not be shown. */ - public $context = null; + public $context; /** * @var string If the field element names should be contained in an array. @@ -686,7 +686,7 @@ class Form extends WidgetBase * Check that the form field matches the active context */ if ($fieldObj->context !== null) { - $context = (is_array($fieldObj->context)) ? $fieldObj->context : [$fieldObj->context]; + $context = is_array($fieldObj->context) ? $fieldObj->context : [$fieldObj->context]; if (!in_array($this->getContext(), $context)) { continue; } @@ -779,7 +779,7 @@ class Form extends WidgetBase */ protected function makeFormField($name, $config = []) { - $label = (isset($config['label'])) ? $config['label'] : null; + $label = $config['label'] ?? null; list($fieldName, $fieldContext) = $this->getFieldName($name); $field = new FormField($fieldName, $label); @@ -806,11 +806,11 @@ class Form extends WidgetBase * Defined field type */ else { - $fieldType = isset($config['type']) ? $config['type'] : null; - if (!is_string($fieldType) && !is_null($fieldType)) { + $fieldType = $config['type'] ?? null; + if (!is_string($fieldType) && $fieldType !== null) { throw new ApplicationException(Lang::get( 'backend::lang.field.invalid_type', - ['type'=>gettype($fieldType)] + ['type' => gettype($fieldType)] )); } @@ -873,7 +873,7 @@ class Form extends WidgetBase * Defer the execution of option data collection */ $field->options(function () use ($field, $config) { - $fieldOptions = isset($config['options']) ? $config['options'] : null; + $fieldOptions = $config['options'] ?? null; $fieldOptions = $this->getOptionsFromModel($field, $fieldOptions); return $fieldOptions; }); @@ -1106,8 +1106,7 @@ class Form extends WidgetBase } if ($field->type === 'widget') { - $widget = $this->makeFormFieldWidget($field); - return $widget->showLabels; + return $this->makeFormFieldWidget($field)->showLabels; } return true; @@ -1343,9 +1342,9 @@ class Form extends WidgetBase $key = array_shift($parts); if (isset($array[$key])) { return $array[$key]; - } else { - return $default; } + + return $default; } foreach ($parts as $segment) { diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 91c862e2e..0a21fac55 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -1,10 +1,8 @@ displayAs($columnType, $config); @@ -1221,7 +1218,7 @@ class Lists extends WidgetBase $dateTime = $this->validateDateTimeValue($value, $column); - $format = $column->format !== null ? $column->format : 'g:i A'; + $format = $column->format ?? 'g:i A'; $value = $dateTime->format($format); @@ -1479,19 +1476,18 @@ 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'; } elseif (is_array($this->defaultSort) && isset($this->defaultSort['column'])) { $this->sortColumn = $this->defaultSort['column']; - $this->sortDirection = (isset($this->defaultSort['direction'])) ? - $this->defaultSort['direction'] : - 'desc'; + $this->sortDirection = $this->defaultSort['direction'] ?? 'desc'; } } @@ -1516,9 +1512,8 @@ class Lists extends WidgetBase if ($column === null) { return (count($this->getSortableColumns()) > 0); } - else { - return array_key_exists($column, $this->getSortableColumns()); - } + + return array_key_exists($column, $this->getSortableColumns()); } /** diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index 4a64d3594..6cdee7dbb 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -38,7 +38,7 @@ class MediaManager extends WidgetBase const FILTER_EVERYTHING = 'everything'; - protected $brokenImageHash = null; + protected $brokenImageHash; /** * @var boolean Determines whether the widget is in readonly mode or not @@ -636,7 +636,7 @@ class MediaManager extends WidgetBase $urlAndSize = $this->getCropEditImageUrlAndSize($path, $cropSessionKey); $width = $urlAndSize['dimensions'][0]; - $height = $urlAndSize['dimensions'][1] ? $urlAndSize['dimensions'][1] : 1; + $height = $urlAndSize['dimensions'][1] ?: 1; $this->vars['currentSelectionMode'] = $selectionParams['mode']; $this->vars['currentSelectionWidth'] = $selectionParams['width']; @@ -784,9 +784,7 @@ class MediaManager extends WidgetBase protected function getCurrentFolder() { - $folder = $this->getSession('media_folder', self::FOLDER_ROOT); - - return $folder; + return $this->getSession('media_folder', self::FOLDER_ROOT); } protected function setFilter($filter) @@ -860,7 +858,7 @@ class MediaManager extends WidgetBase if ($result) { if (!isset($result['mode'])) { - $result['mode'] = MediaManager::SELECTION_MODE_NORMAL; + $result['mode'] = self::SELECTION_MODE_NORMAL; } if (!isset($result['width'])) { @@ -875,7 +873,7 @@ class MediaManager extends WidgetBase } return [ - 'mode' => MediaManager::SELECTION_MODE_NORMAL, + 'mode' => self::SELECTION_MODE_NORMAL, 'width' => null, 'height' => null ]; @@ -884,9 +882,9 @@ class MediaManager extends WidgetBase protected function setSelectionParams($selectionMode, $selectionWidth, $selectionHeight) { if (!in_array($selectionMode, [ - MediaManager::SELECTION_MODE_NORMAL, - MediaManager::SELECTION_MODE_FIXED_RATIO, - MediaManager::SELECTION_MODE_FIXED_SIZE + self::SELECTION_MODE_NORMAL, + self::SELECTION_MODE_FIXED_RATIO, + self::SELECTION_MODE_FIXED_SIZE ])) { throw new ApplicationException('Invalid input data'); } @@ -1000,9 +998,7 @@ class MediaManager extends WidgetBase $partition = implode('/', array_slice(str_split($itemSignature, 3), 0, 3)) . '/'; - $result = $this->getThumbnailDirectory().$partition.$thumbFile; - - return $result; + return $this->getThumbnailDirectory().$partition.$thumbFile; } protected function getThumbnailImageUrl($imagePath) @@ -1140,10 +1136,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); @@ -1181,10 +1177,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) { @@ -1422,31 +1418,29 @@ class MediaManager extends WidgetBase * If the target dimensions are provided, resize the original image and * return its URL and dimensions. */ - else { - $originalFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName; - if (!File::isFile($originalFilePath)) { - throw new SystemException('The original image is not found in the cropping session directory.'); - } - - $resizedThumbFileName = 'resized-'.$params['width'].'-'.$params['height'].'.'.$extension; - $tempFilePath = $fullSessionDirectoryPath.'/'.$resizedThumbFileName; - - Resizer::open($originalFilePath) - ->resize($params['width'], $params['height'], [ - 'mode' => 'exact' - ]) - ->save($tempFilePath) - ; - - $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$resizedThumbFileName); - $dimensions = getimagesize($tempFilePath); - - return [ - 'url' => $url, - 'dimensions' => $dimensions - ]; + $originalFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName; + if (!File::isFile($originalFilePath)) { + throw new SystemException('The original image is not found in the cropping session directory.'); } + + $resizedThumbFileName = 'resized-'.$params['width'].'-'.$params['height'].'.'.$extension; + $tempFilePath = $fullSessionDirectoryPath.'/'.$resizedThumbFileName; + + Resizer::open($originalFilePath) + ->resize($params['width'], $params['height'], [ + 'mode' => 'exact' + ]) + ->save($tempFilePath) + ; + + $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$resizedThumbFileName); + $dimensions = getimagesize($tempFilePath); + + return [ + 'url' => $url, + 'dimensions' => $dimensions + ]; } catch (Exception $ex) { if ($sessionDirectoryCreated) { diff --git a/modules/backend/widgets/ReportContainer.php b/modules/backend/widgets/ReportContainer.php index 6abb44506..dc57bd8e7 100644 --- a/modules/backend/widgets/ReportContainer.php +++ b/modules/backend/widgets/ReportContainer.php @@ -416,7 +416,7 @@ class ReportContainer extends WidgetBase $property = [ 'property' => $name, 'title' => isset($params['title']) ? Lang::get($params['title']) : $name, - 'type' => isset($params['type']) ? $params['type'] : 'string' + 'type' => $params['type'] ?? 'string' ]; foreach ($params as $name => $value) { diff --git a/modules/backend/widgets/Search.php b/modules/backend/widgets/Search.php index 8976313c2..2f5749abf 100644 --- a/modules/backend/widgets/Search.php +++ b/modules/backend/widgets/Search.php @@ -98,9 +98,9 @@ class Search extends WidgetBase if ($this->partial) { return $this->controller->makePartial($this->partial); - } else { - return $this->makePartial('search'); } + + return $this->makePartial('search'); } /** diff --git a/modules/backend/widgets/Table.php b/modules/backend/widgets/Table.php index 9de40a3c6..990a99a59 100644 --- a/modules/backend/widgets/Table.php +++ b/modules/backend/widgets/Table.php @@ -34,12 +34,12 @@ class Table extends WidgetBase /** * @var Backend\Widgets\Table\DatasourceBase */ - protected $dataSource = null; + protected $dataSource; /** * @var string Field name used for request data. */ - protected $fieldName = null; + protected $fieldName; /** * @var string diff --git a/modules/cms/ServiceProvider.php b/modules/cms/ServiceProvider.php index 01da9d401..db411be3c 100644 --- a/modules/cms/ServiceProvider.php +++ b/modules/cms/ServiceProvider.php @@ -1,7 +1,6 @@ controller->vars[$offset]) ? $this->controller->vars[$offset] : null; + return $this->controller->vars[$offset] ?? null; } /** 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/ComponentBase.php b/modules/cms/classes/ComponentBase.php index 7a12a1c3c..337a9b6b7 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -3,8 +3,6 @@ use Str; use Lang; use Config; -use Cms\Classes\CodeBase; -use Cms\Classes\CmsException; use October\Rain\Extension\Extendable; use BadMethodCallException; diff --git a/modules/cms/classes/ComponentHelpers.php b/modules/cms/classes/ComponentHelpers.php index bdb44a589..01226cddd 100644 --- a/modules/cms/classes/ComponentHelpers.php +++ b/modules/cms/classes/ComponentHelpers.php @@ -106,9 +106,7 @@ class ComponentHelpers public static function getComponentName($component) { $details = $component->componentDetails(); - $name = (isset($details['name'])) - ? $details['name'] - : 'cms::lang.component.unnamed'; + $name = $details['name'] ?? 'cms::lang.component.unnamed'; return Lang::get($name); } @@ -121,9 +119,7 @@ class ComponentHelpers public static function getComponentDescription($component) { $details = $component->componentDetails(); - $name = (isset($details['description'])) - ? $details['description'] - : 'cms::lang.component.no_description'; + $name = $details['description'] ?? 'cms::lang.component.no_description'; return Lang::get($name); } diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 28e3679da..291da0eb8 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -2,9 +2,7 @@ use Cms; use Url; -use Str; use App; -use File; use View; use Lang; use Flash; @@ -22,13 +20,10 @@ use Cms\Twig\Extension as CmsTwigExtension; use Cms\Models\MaintenanceSetting; use System\Models\RequestLog; use System\Helpers\View as ViewHelper; -use System\Classes\ErrorHandler; use System\Classes\CombineAssets; use System\Twig\Extension as SystemTwigExtension; use October\Rain\Exception\AjaxException; -use October\Rain\Exception\SystemException; use October\Rain\Exception\ValidationException; -use October\Rain\Exception\ApplicationException; use October\Rain\Parse\Bracket as TextParser; use Illuminate\Http\RedirectResponse; @@ -102,12 +97,12 @@ class Controller /** * @var self Cache of self */ - protected static $instance = null; + protected static $instance; /** * @var \Cms\Classes\ComponentBase Object of the active component, used internally. */ - protected $componentContext = null; + protected $componentContext; /** * @var array Component partial stack, used internally. @@ -121,7 +116,7 @@ class Controller */ public function __construct($theme = null) { - $this->theme = $theme ? $theme : Theme::getActiveTheme(); + $this->theme = $theme ?: Theme::getActiveTheme(); if (!$this->theme) { throw new CmsException(Lang::get('cms::lang.theme.active.not_found')); } @@ -335,7 +330,7 @@ class Controller if ( $useAjax && ($handler = post('_handler')) && - ($this->verifyCsrfToken()) && + $this->verifyCsrfToken() && ($handlerResponse = $this->runAjaxHandler($handler)) && $handlerResponse !== true ) { @@ -487,7 +482,7 @@ class Controller $useCache = !Config::get('cms.twigNoCache'); $isDebugMode = Config::get('app.debug', false); $strictVariables = Config::get('cms.enableTwigStrictVariables', false); - $strictVariables = is_null($strictVariables) ? $isDebugMode : $strictVariables; + $strictVariables = $strictVariables ?? $isDebugMode; $forceBytecode = Config::get('cms.forceBytecodeInvalidation', false); $options = [ @@ -731,7 +726,7 @@ class Controller if ($componentObj && $componentObj->methodExists($handlerName)) { $this->componentContext = $componentObj; $result = $componentObj->runAjaxHandler($handlerName); - return ($result) ?: true; + return $result ?: true; } } /* @@ -740,12 +735,12 @@ class Controller else { if (method_exists($this->pageObj, $handler)) { $result = $this->pageObj->$handler(); - return ($result) ?: true; + return $result ?: true; } if (!$this->layout->isFallBack() && method_exists($this->layoutObj, $handler)) { $result = $this->layoutObj->$handler(); - return ($result) ?: true; + return $result ?: true; } /* @@ -754,7 +749,7 @@ class Controller if (($componentObj = $this->findComponentByHandler($handler)) !== null) { $this->componentContext = $componentObj; $result = $componentObj->runAjaxHandler($handler); - return ($result) ?: true; + return $result ?: true; } } @@ -834,23 +829,19 @@ class Controller if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name'=>$partialName])); } - else { - return false; - } + + return false; } } /* * 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; @@ -874,9 +865,8 @@ class Controller if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name'=>$name])); } - else { - return false; - } + + return false; } /* @@ -884,18 +874,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; } /* @@ -1374,15 +1361,10 @@ class Controller if (substr($paramName, 0, 1) == ':') { $routeParamName = substr($paramName, 1); - $newPropertyValue = array_key_exists($routeParamName, $routerParameters) - ? $routerParameters[$routeParamName] - : null; - + $newPropertyValue = $routerParameters[$routeParamName] ?? null; } else { - $newPropertyValue = array_key_exists($paramName, $parameters) - ? $parameters[$paramName] - : null; + $newPropertyValue = $parameters[$paramName] ?? null; } $component->setProperty($propertyName, $newPropertyValue); diff --git a/modules/cms/classes/Page.php b/modules/cms/classes/Page.php index 4c1b9bef7..2ea4ce171 100644 --- a/modules/cms/classes/Page.php +++ b/modules/cms/classes/Page.php @@ -1,8 +1,6 @@ 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/classes/Theme.php b/modules/cms/classes/Theme.php index 4a3c29a2d..da5c5d9f4 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -34,7 +34,7 @@ class Theme /** * @var mixed Keeps the cached configuration file values. */ - protected $configCache = null; + protected $configCache; /** * @var mixed Active theme cache in memory @@ -518,8 +518,7 @@ class Theme public function __get($name) { if ($this->hasCustomData()) { - $theme = $this->getCustomData(); - return $theme->{$name}; + return $this->getCustomData()->{$name}; } return null; diff --git a/modules/cms/components/Resources.php b/modules/cms/components/Resources.php index a8993997b..d5be4bbfb 100644 --- a/modules/cms/components/Resources.php +++ b/modules/cms/components/Resources.php @@ -1,7 +1,6 @@ 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 = []; @@ -428,9 +426,7 @@ class Index extends Controller $widgetConfig->model = $template; $widgetConfig->alias = $alias ?: 'form'.studly_case($type).md5($template->getFileName()).uniqid(); - $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); - - return $widget; + return $this->makeWidget('Backend\Widgets\Form', $widgetConfig); } protected function upgradeSettings($settings) @@ -462,9 +458,7 @@ class Index extends Controller } $properties = json_decode($componentProperties[$index], true); - unset($properties['oc.alias']); - unset($properties['inspectorProperty']); - unset($properties['inspectorClassName']); + unset($properties['oc.alias'], $properties['inspectorProperty'], $properties['inspectorClassName']); $settings[$section] = $properties; } } diff --git a/modules/cms/controllers/ThemeLogs.php b/modules/cms/controllers/ThemeLogs.php index 03bd0cd79..4e508fd6c 100644 --- a/modules/cms/controllers/ThemeLogs.php +++ b/modules/cms/controllers/ThemeLogs.php @@ -1,17 +1,11 @@ findThemeObject($dirName); - $model = ThemeData::forTheme($theme); - return $model; + return ThemeData::forTheme($theme); } protected function findThemeObject($name = null) diff --git a/modules/cms/controllers/Themes.php b/modules/cms/controllers/Themes.php index ac3a06803..0f780b20e 100644 --- a/modules/cms/controllers/Themes.php +++ b/modules/cms/controllers/Themes.php @@ -1,15 +1,12 @@ arrayName = 'Theme'; $widgetConfig->context = 'update'; - $widget = $this->makeWidget(Form::class, $widgetConfig); - return $widget; + return $this->makeWidget(Form::class, $widgetConfig); } // @@ -175,8 +171,7 @@ class Themes extends Controller $widgetConfig->arrayName = 'Theme'; $widgetConfig->context = 'create'; - $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); - return $widget; + return $this->makeWidget('Backend\Widgets\Form', $widgetConfig); } // @@ -258,8 +253,7 @@ class Themes extends Controller $widgetConfig->model->theme = $theme; $widgetConfig->arrayName = 'ThemeExport'; - $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); - return $widget; + return $this->makeWidget('Backend\Widgets\Form', $widgetConfig); } // @@ -295,8 +289,7 @@ class Themes extends Controller $widgetConfig->model->theme = $theme; $widgetConfig->arrayName = 'ThemeImport'; - $widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig); - return $widget; + return $this->makeWidget('Backend\Widgets\Form', $widgetConfig); } // diff --git a/modules/cms/formwidgets/Components.php b/modules/cms/formwidgets/Components.php index 5963fd3fb..de3051e3c 100644 --- a/modules/cms/formwidgets/Components.php +++ b/modules/cms/formwidgets/Components.php @@ -1,6 +1,5 @@ 'CMS', 'manage_content' => 'Halda kodulehe sisufaile', 'manage_assets' => 'Manage website assets - images, JavaScript files, CSS files', - 'manage_pages' => 'Create, modify and delete website pages', 'manage_pages' => 'Loo, muuda ja kustuta kodulehe lehti', 'manage_layouts' => 'Create, modify and delete CMS layouts', 'manage_partials' => 'Create, modify and delete CMS partials', diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 60da81270..e06f1a859 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -93,11 +93,11 @@ class ThemeData extends Model } try { - $themeData = ThemeData::firstOrCreate(['theme' => $dirName]); + $themeData = self::firstOrCreate(['theme' => $dirName]); } catch (Exception $ex) { // Database failed - $themeData = new ThemeData(['theme' => $dirName]); + $themeData = new self(['theme' => $dirName]); } return self::$instances[$dirName] = $themeData; diff --git a/modules/cms/models/ThemeExport.php b/modules/cms/models/ThemeExport.php index 6368ac944..c568a7736 100644 --- a/modules/cms/models/ThemeExport.php +++ b/modules/cms/models/ThemeExport.php @@ -1,7 +1,6 @@ commentMap[$method]) ? $this->commentMap[$method] : null; + return $this->commentMap[$method] ?? null; } /** @@ -608,6 +608,6 @@ class DebugExtension extends Twig_Extension $strings[] = $key . ': ' . $value; } - return join('; ', $strings); + return implode('; ', $strings); } } diff --git a/modules/cms/twig/Extension.php b/modules/cms/twig/Extension.php index f123a744e..4b1987f0d 100644 --- a/modules/cms/twig/Extension.php +++ b/modules/cms/twig/Extension.php @@ -1,15 +1,11 @@ pluginDetails(); - $pluginName = isset($pluginDetails['name']) - ? $pluginDetails['name'] - : Lang::get('system::lang.plugin.unnamed'); - - $pluginIcon = isset($pluginDetails['icon']) - ? $pluginDetails['icon'] - : 'icon-puzzle-piece'; - - $pluginDescription = isset($pluginDetails['description']) - ? $pluginDetails['description'] - : null; + $pluginName = $pluginDetails['name'] ?? Lang::get('system::lang.plugin.unnamed'); + $pluginIcon = $pluginDetails['icon'] ?? 'icon-puzzle-piece'; + $pluginDescription = $pluginDetails['description'] ?? null; $pluginClass = get_class($plugin); diff --git a/modules/cms/widgets/TemplateList.php b/modules/cms/widgets/TemplateList.php index a18df610e..40386cecd 100644 --- a/modules/cms/widgets/TemplateList.php +++ b/modules/cms/widgets/TemplateList.php @@ -4,7 +4,6 @@ use Str; use File; use Input; use Request; -use Response; use Cms\Classes\Theme; use Backend\Classes\WidgetBase; @@ -63,7 +62,7 @@ class TemplateList extends WidgetBase /** * @var string Extra CSS class name to apply to the control. */ - public $controlClass = null; + public $controlClass; /** * @var string A list of file name patterns to suppress / hide. @@ -372,10 +371,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/ServiceProvider.php b/modules/system/ServiceProvider.php index a29e8f946..c3a651f1f 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -1,13 +1,11 @@ transactionMode ? 'transactionItems' : 'items'; - if (is_null($this->$items)) { + if ($this->$items === null) { $this->$items = []; } diff --git a/modules/system/classes/PluginBase.php b/modules/system/classes/PluginBase.php index 12ac9d933..737035d74 100644 --- a/modules/system/classes/PluginBase.php +++ b/modules/system/classes/PluginBase.php @@ -256,9 +256,8 @@ class PluginBase extends ServiceProviderBase if ($exceptionMessage) { throw new SystemException($exceptionMessage); } - else { - $this->loadedYamlConfiguration = []; - } + + $this->loadedYamlConfiguration = []; } else { $this->loadedYamlConfiguration = Yaml::parse(file_get_contents($yamlFilePath)); diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index dbcb21ace..7a4a9bcfd 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -302,9 +302,7 @@ class PluginManager */ public function exists($id) { - return (!$this->findByIdentifier($id) || $this->isDisabled($id)) - ? false - : true; + return !(!$this->findByIdentifier($id) || $this->isDisabled($id)); } /** @@ -760,7 +758,7 @@ class PluginManager /* * Delete from file system */ - if ($pluginPath = PluginManager::instance()->getPluginPath($id)) { + if ($pluginPath = self::instance()->getPluginPath($id)) { File::deleteDirectory($pluginPath); } } diff --git a/modules/system/classes/SettingsManager.php b/modules/system/classes/SettingsManager.php index 9b4b7f781..e6c679122 100644 --- a/modules/system/classes/SettingsManager.php +++ b/modules/system/classes/SettingsManager.php @@ -3,7 +3,6 @@ use Event; use Backend; use BackendAuth; -use System\Classes\PluginManager; use SystemException; /** diff --git a/modules/system/classes/SystemController.php b/modules/system/classes/SystemController.php index 8fa3e4a06..edfe60981 100644 --- a/modules/system/classes/SystemController.php +++ b/modules/system/classes/SystemController.php @@ -2,7 +2,6 @@ use Lang; use ApplicationException; -use System\Classes\CombineAssets; use Illuminate\Routing\Controller as ControllerBase; use Exception; diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index ce1135cbc..5831a1e32 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 { @@ -250,9 +251,9 @@ class UpdateManager */ $plugins = []; foreach (array_get($result, 'plugins', []) as $code => $info) { - $info['name'] = isset($names[$code]) ? $names[$code] : $code; - $info['old_version'] = isset($versions[$code]) ? $versions[$code] : false; - $info['icon'] = isset($icons[$code]) ? $icons[$code] : false; + $info['name'] = $names[$code] ?? $code; + $info['old_version'] = $versions[$code] ?? false; + $info['icon'] = $icons[$code] ?? false; /* * If a plugin has updates frozen, or cannot be updated, @@ -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)) { diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index dcedfdc07..04a199d18 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -1,6 +1,5 @@ pluginManager->getIdentifier($plugin); + $code = is_string($plugin) ? $plugin : $this->pluginManager->getIdentifier($plugin); if (!$this->hasVersionFile($code)) { return false; @@ -111,7 +110,7 @@ class VersionManager */ public function listNewVersions($plugin) { - $code = (is_string($plugin)) ? $plugin : $this->pluginManager->getIdentifier($plugin); + $code = is_string($plugin) ? $plugin : $this->pluginManager->getIdentifier($plugin); if (!$this->hasVersionFile($code)) { return []; @@ -165,7 +164,7 @@ class VersionManager */ public function removePlugin($plugin, $stopOnVersion = null) { - $code = (is_string($plugin)) ? $plugin : $this->pluginManager->getIdentifier($plugin); + $code = is_string($plugin) ? $plugin : $this->pluginManager->getIdentifier($plugin); if (!$this->hasVersionFile($code)) { return false; @@ -229,7 +228,7 @@ class VersionManager $history->delete(); } - return (($countHistory + $countVersions) > 0) ? true : false; + return ($countHistory + $countVersions) > 0; } // @@ -246,8 +245,7 @@ class VersionManager return self::NO_VERSION_VALUE; } - $latest = trim(key(array_slice($versionInfo, -1, 1))); - return $latest; + return trim(key(array_slice($versionInfo, -1, 1))); } /** @@ -327,9 +325,7 @@ class VersionManager ; } - return (isset($this->databaseVersions[$code])) - ? $this->databaseVersions[$code] - : self::NO_VERSION_VALUE; + return $this->databaseVersions[$code] ?? self::NO_VERSION_VALUE; } /** diff --git a/modules/system/console/OctoberDown.php b/modules/system/console/OctoberDown.php index d895ad15e..5f39fdba9 100644 --- a/modules/system/console/OctoberDown.php +++ b/modules/system/console/OctoberDown.php @@ -3,7 +3,6 @@ use Illuminate\Console\Command; use System\Classes\UpdateManager; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; /** * Console command to tear down the database. @@ -27,14 +26,6 @@ class OctoberDown extends Command */ protected $description = 'Destroys all database tables for October and all plugins.'; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ @@ -50,14 +41,6 @@ class OctoberDown extends Command ; } - /** - * Get the console command arguments. - */ - protected function getArguments() - { - return []; - } - /** * Get the console command options. */ diff --git a/modules/system/console/OctoberEnv.php b/modules/system/console/OctoberEnv.php index de8a50390..6e87ff908 100644 --- a/modules/system/console/OctoberEnv.php +++ b/modules/system/console/OctoberEnv.php @@ -46,14 +46,6 @@ class OctoberEnv extends Command */ protected $connection; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ @@ -274,7 +266,7 @@ class OctoberEnv extends Command return "'$value'"; } elseif (is_bool($value)) { return $value ? 'true' : 'false'; - } elseif (is_null($value)) { + } elseif ($value === null) { return 'null'; } diff --git a/modules/system/console/OctoberFresh.php b/modules/system/console/OctoberFresh.php index ec918c3e9..e87e5422d 100644 --- a/modules/system/console/OctoberFresh.php +++ b/modules/system/console/OctoberFresh.php @@ -2,8 +2,6 @@ use File; use Artisan; -use Cms\Classes\Theme; -use Cms\Classes\ThemeManager; use Illuminate\Console\Command; use Symfony\Component\Console\Input\InputOption; @@ -29,14 +27,6 @@ class OctoberFresh extends Command */ protected $description = 'Removes the demo theme and plugin.'; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ @@ -59,14 +49,6 @@ class OctoberFresh extends Command } } - /** - * Get the console command arguments. - */ - protected function getArguments() - { - return []; - } - /** * Get the console command options. */ diff --git a/modules/system/console/OctoberInstall.php b/modules/system/console/OctoberInstall.php index b6661f246..feb39002c 100644 --- a/modules/system/console/OctoberInstall.php +++ b/modules/system/console/OctoberInstall.php @@ -3,13 +3,9 @@ use Db; use App; use Str; -use Url; use PDO; use File; use Config; -use Artisan; -use Cms\Classes\Theme; -use Cms\Classes\ThemeManager; use Backend\Database\Seeds\SeedSetupAdmin; use System\Classes\UpdateManager; use October\Rain\Config\ConfigWriter; @@ -87,14 +83,6 @@ class OctoberInstall extends Command $this->displayOutro(); } - /** - * Get the console command arguments. - */ - protected function getArguments() - { - return []; - } - /** * Get the console command options. */ diff --git a/modules/system/console/OctoberMirror.php b/modules/system/console/OctoberMirror.php index 8154d21a9..a9f5220eb 100644 --- a/modules/system/console/OctoberMirror.php +++ b/modules/system/console/OctoberMirror.php @@ -73,14 +73,6 @@ class OctoberMirror extends Command protected $destinationPath; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ diff --git a/modules/system/console/OctoberUp.php b/modules/system/console/OctoberUp.php index 1fd9b2fa6..a599732b6 100644 --- a/modules/system/console/OctoberUp.php +++ b/modules/system/console/OctoberUp.php @@ -2,8 +2,6 @@ use Illuminate\Console\Command; use System\Classes\UpdateManager; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; /** * Console command to migrate the database. @@ -25,14 +23,6 @@ class OctoberUp extends Command */ protected $description = 'Builds database tables for October and all plugins.'; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ @@ -45,20 +35,4 @@ class OctoberUp extends Command ->update() ; } - - /** - * Get the console command arguments. - */ - protected function getArguments() - { - return []; - } - - /** - * Get the console command options. - */ - protected function getOptions() - { - return []; - } } diff --git a/modules/system/console/OctoberUpdate.php b/modules/system/console/OctoberUpdate.php index 8ad277c5c..b826fe305 100644 --- a/modules/system/console/OctoberUpdate.php +++ b/modules/system/console/OctoberUpdate.php @@ -1,11 +1,9 @@ output->writeln('No new updates found'); return; } - else { - $this->output->writeln(sprintf('Found %s new %s!', $updates, Str::plural('update', $updates))); - } + + $this->output->writeln(sprintf('Found %s new %s!', $updates, Str::plural('update', $updates))); $coreHash = $disableCore ? null : array_get($updateList, 'core.hash'); $coreBuild = array_get($updateList, 'core.build'); @@ -113,14 +102,6 @@ class OctoberUpdate extends Command $this->call('october:up'); } - /** - * Get the console command arguments. - */ - protected function getArguments() - { - return []; - } - /** * Get the console command options. */ diff --git a/modules/system/console/OctoberUtil.php b/modules/system/console/OctoberUtil.php index 3abc3d57d..c2ba6276a 100644 --- a/modules/system/console/OctoberUtil.php +++ b/modules/system/console/OctoberUtil.php @@ -46,14 +46,6 @@ class OctoberUtil extends Command */ protected $description = 'Utility commands for October'; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ diff --git a/modules/system/console/PluginInstall.php b/modules/system/console/PluginInstall.php index a18dbcd9a..4b7420a79 100644 --- a/modules/system/console/PluginInstall.php +++ b/modules/system/console/PluginInstall.php @@ -2,7 +2,6 @@ use Illuminate\Console\Command; use System\Classes\UpdateManager; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use System\Classes\PluginManager; @@ -29,15 +28,6 @@ class PluginInstall extends Command */ protected $description = 'Install a plugin from the October marketplace.'; - /** - * Create a new command instance. - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @return void @@ -76,13 +66,4 @@ class PluginInstall extends Command ['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'], ]; } - - /** - * Get the console command options. - * @return array - */ - protected function getOptions() - { - return []; - } } diff --git a/modules/system/console/PluginRefresh.php b/modules/system/console/PluginRefresh.php index 91343e207..b79be41ca 100644 --- a/modules/system/console/PluginRefresh.php +++ b/modules/system/console/PluginRefresh.php @@ -3,7 +3,6 @@ use Illuminate\Console\Command; use System\Classes\UpdateManager; use System\Classes\PluginManager; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; /** @@ -30,15 +29,6 @@ class PluginRefresh extends Command */ protected $description = 'Removes and re-adds an existing plugin.'; - /** - * Create a new command instance. - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @return void @@ -78,13 +68,4 @@ class PluginRefresh extends Command ['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'], ]; } - - /** - * Get the console command options. - * @return array - */ - protected function getOptions() - { - return []; - } } diff --git a/modules/system/console/PluginRemove.php b/modules/system/console/PluginRemove.php index bcef7caad..98d593bbd 100644 --- a/modules/system/console/PluginRemove.php +++ b/modules/system/console/PluginRemove.php @@ -33,15 +33,6 @@ class PluginRemove extends Command */ protected $description = 'Removes an existing plugin.'; - /** - * Create a new command instance. - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @return void diff --git a/modules/system/console/ThemeInstall.php b/modules/system/console/ThemeInstall.php index 69c5c4f94..2f47fb34c 100644 --- a/modules/system/console/ThemeInstall.php +++ b/modules/system/console/ThemeInstall.php @@ -30,15 +30,6 @@ class ThemeInstall extends Command */ protected $description = 'Install a theme from the October marketplace.'; - /** - * Create a new command instance. - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @return void @@ -143,13 +134,4 @@ class ThemeInstall extends Command ['dirName', InputArgument::OPTIONAL, 'Destination directory name for the theme installation.'], ]; } - - /** - * Get the console command options. - * @return array - */ - protected function getOptions() - { - return []; - } } diff --git a/modules/system/console/ThemeList.php b/modules/system/console/ThemeList.php index d04042f7f..9547475c1 100644 --- a/modules/system/console/ThemeList.php +++ b/modules/system/console/ThemeList.php @@ -26,14 +26,6 @@ class ThemeList extends Command */ protected $description = 'List available themes.'; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ @@ -65,14 +57,6 @@ class ThemeList extends Command $this->info(PHP_EOL."[*] Active [-] Installed [ ] Not installed"); } - /** - * Get the console command arguments. - */ - protected function getArguments() - { - return []; - } - /** * Get the console command options. */ diff --git a/modules/system/console/ThemeRemove.php b/modules/system/console/ThemeRemove.php index 10b49e02f..ec41631cc 100644 --- a/modules/system/console/ThemeRemove.php +++ b/modules/system/console/ThemeRemove.php @@ -32,15 +32,6 @@ class ThemeRemove extends Command */ protected $description = 'Delete an existing theme.'; - /** - * Create a new command instance. - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @return void diff --git a/modules/system/console/ThemeUse.php b/modules/system/console/ThemeUse.php index 9fef73247..1e1e224ec 100644 --- a/modules/system/console/ThemeUse.php +++ b/modules/system/console/ThemeUse.php @@ -29,15 +29,6 @@ class ThemeUse extends Command */ protected $description = 'Switch the active theme.'; - /** - * Create a new command instance. - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @return void diff --git a/modules/system/controllers/EventLogs.php b/modules/system/controllers/EventLogs.php index b303b978c..b8a3b3677 100644 --- a/modules/system/controllers/EventLogs.php +++ b/modules/system/controllers/EventLogs.php @@ -1,18 +1,12 @@ class; - $model = $class::instance(); - return $model; + return $class::instance(); } /** diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index 202668500..3f67d2cdd 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -1,12 +1,10 @@ 'Mazání šablony...', 'deleting_layout' => 'Mazání layoutu...', 'return' => 'Zpět na seznam šablon', - 'saving' => 'Ukládání šablony...', 'sending' => 'Odesílání testovací zprávy...', ], 'mail_brand' => [ diff --git a/modules/system/models/File.php b/modules/system/models/File.php index 40f6a46af..012342617 100644 --- a/modules/system/models/File.php +++ b/modules/system/models/File.php @@ -54,9 +54,8 @@ class File extends FileBase if ($this->isPublic()) { return $uploadsFolder . '/public/'; } - else { - return $uploadsFolder . '/protected/'; - } + + return $uploadsFolder . '/protected/'; } /** @@ -75,6 +74,6 @@ class File extends FileBase protected function copyLocalToStorage($localPath, $storagePath) { $disk = Storage::disk(Config::get('cms.storage.uploads.disk')); - return $disk->put($storagePath, FileHelper::get($localPath), ($this->isPublic()) ? 'public' : null); + return $disk->put($storagePath, FileHelper::get($localPath), $this->isPublic() ? 'public' : null); } } diff --git a/modules/system/models/LogSetting.php b/modules/system/models/LogSetting.php index ad9be0283..a048f568a 100644 --- a/modules/system/models/LogSetting.php +++ b/modules/system/models/LogSetting.php @@ -1,7 +1,6 @@ parse(FileHelper::get($basePath . '/custom.less')); - $css = $parser->getCss(); - - return $css; + return $parser->getCss(); } } diff --git a/modules/system/models/MailPartial.php b/modules/system/models/MailPartial.php index 00b8b23df..ac1971690 100644 --- a/modules/system/models/MailPartial.php +++ b/modules/system/models/MailPartial.php @@ -1,9 +1,7 @@ $partialPath])); } - else { - return false; - } + + return false; } return $this->makeFileContents($partialPath, $params); @@ -140,7 +138,7 @@ trait ViewMaker */ public function makeLayout($name = null, $params = [], $throwException = true) { - $layout = $name === null ? $this->layout : $name; + $layout = $name ?? $this->layout; if ($layout == '') { return ''; } @@ -151,9 +149,8 @@ trait ViewMaker if ($throwException) { throw new SystemException(Lang::get('cms::lang.layout.not_found_name', ['name' => $layoutPath])); } - else { - return false; - } + + return false; } return $this->makeFileContents($layoutPath, $params); @@ -300,6 +297,6 @@ trait ViewMaker $classFolder = strtolower(class_basename($class)); $classFile = realpath(dirname(File::fromClass($class))); $guessedPath = $classFile ? $classFile . '/' . $classFolder . $suffix : null; - return ($isPublic) ? File::localToPublic($guessedPath) : $guessedPath; + return $isPublic ? File::localToPublic($guessedPath) : $guessedPath; } } diff --git a/modules/system/twig/Extension.php b/modules/system/twig/Extension.php index 0c6e037fe..36b7b8ae3 100644 --- a/modules/system/twig/Extension.php +++ b/modules/system/twig/Extension.php @@ -2,10 +2,7 @@ use Url; use Twig_Extension; -use Twig_TokenParser; use Twig_SimpleFilter; -use Twig_SimpleFunction; -use ApplicationException; use System\Classes\MediaLibrary; use System\Classes\MarkupManager;