From 742a5f415bc45819b11c77402efc114fa2f4451e Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:27:36 +0200 Subject: [PATCH 01/19] Remove unused imports --- modules/backend/ServiceProvider.php | 1 - modules/backend/formwidgets/Repeater.php | 1 - modules/backend/models/Preference.php | 1 - modules/backend/models/UserPreference.php | 2 -- modules/backend/traits/FormModelSaver.php | 1 - modules/backend/widgets/Lists.php | 1 - modules/cms/ServiceProvider.php | 1 - modules/cms/classes/Asset.php | 1 - modules/cms/classes/ComponentBase.php | 2 -- modules/cms/classes/Controller.php | 3 --- modules/cms/classes/Page.php | 2 -- modules/cms/components/UnknownComponent.php | 1 - modules/cms/controllers/Index.php | 1 - modules/cms/controllers/ThemeLogs.php | 2 -- modules/cms/controllers/ThemeOptions.php | 1 - modules/cms/controllers/Themes.php | 2 -- modules/cms/twig/Extension.php | 2 -- modules/cms/twig/FlashNode.php | 1 - modules/cms/twig/FlashTokenParser.php | 1 - modules/cms/widgets/AssetList.php | 2 -- modules/system/ServiceProvider.php | 2 -- modules/system/classes/CombineAssets.php | 1 - modules/system/classes/MailManager.php | 3 --- modules/system/classes/MarkupManager.php | 1 - modules/system/classes/PluginBase.php | 1 - modules/system/classes/SettingsManager.php | 2 -- modules/system/classes/SystemController.php | 1 - modules/system/classes/UpdateManager.php | 1 - modules/system/console/OctoberDown.php | 1 - modules/system/console/OctoberFresh.php | 2 -- modules/system/console/OctoberInstall.php | 2 -- modules/system/console/OctoberUp.php | 2 -- modules/system/console/OctoberUpdate.php | 1 - modules/system/console/PluginInstall.php | 1 - modules/system/console/PluginRefresh.php | 1 - modules/system/controllers/EventLogs.php | 2 -- modules/system/controllers/MailBrandSettings.php | 2 -- modules/system/controllers/MailLayouts.php | 2 -- modules/system/controllers/MailPartials.php | 2 -- modules/system/controllers/MailTemplates.php | 1 - modules/system/controllers/RequestLogs.php | 2 -- modules/system/controllers/Settings.php | 1 - .../2015_10_01_000014_Db_System_Mail_Layout_Rename.php | 1 - modules/system/models/MailPartial.php | 1 - modules/system/models/Parameter.php | 1 - modules/system/traits/ConfigMaker.php | 1 - modules/system/twig/Extension.php | 2 -- 47 files changed, 69 deletions(-) diff --git a/modules/backend/ServiceProvider.php b/modules/backend/ServiceProvider.php index 195ab1856..92b503d08 100644 --- a/modules/backend/ServiceProvider.php +++ b/modules/backend/ServiceProvider.php @@ -1,7 +1,6 @@ Date: Wed, 15 Aug 2018 18:30:03 +0200 Subject: [PATCH 02/19] Remove methods which are identical to parent method --- modules/system/console/OctoberDown.php | 8 -------- modules/system/console/OctoberFresh.php | 8 -------- modules/system/console/OctoberInstall.php | 8 -------- modules/system/console/OctoberUp.php | 16 ---------------- modules/system/console/OctoberUpdate.php | 8 -------- modules/system/console/PluginInstall.php | 9 --------- modules/system/console/PluginRefresh.php | 9 --------- modules/system/console/ThemeInstall.php | 9 --------- modules/system/console/ThemeList.php | 8 -------- 9 files changed, 83 deletions(-) diff --git a/modules/system/console/OctoberDown.php b/modules/system/console/OctoberDown.php index a013acf53..81ffedbca 100644 --- a/modules/system/console/OctoberDown.php +++ b/modules/system/console/OctoberDown.php @@ -49,14 +49,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/OctoberFresh.php b/modules/system/console/OctoberFresh.php index 57b95b869..ec002164d 100644 --- a/modules/system/console/OctoberFresh.php +++ b/modules/system/console/OctoberFresh.php @@ -57,14 +57,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 7413f1969..78b206b94 100644 --- a/modules/system/console/OctoberInstall.php +++ b/modules/system/console/OctoberInstall.php @@ -85,14 +85,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/OctoberUp.php b/modules/system/console/OctoberUp.php index a122230ca..87c4a156b 100644 --- a/modules/system/console/OctoberUp.php +++ b/modules/system/console/OctoberUp.php @@ -43,20 +43,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 d9f508b0e..9a17e33a1 100644 --- a/modules/system/console/OctoberUpdate.php +++ b/modules/system/console/OctoberUpdate.php @@ -112,14 +112,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/PluginInstall.php b/modules/system/console/PluginInstall.php index e6cae5d3c..a9e64d02c 100644 --- a/modules/system/console/PluginInstall.php +++ b/modules/system/console/PluginInstall.php @@ -75,13 +75,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 187ab0373..08132f3ef 100644 --- a/modules/system/console/PluginRefresh.php +++ b/modules/system/console/PluginRefresh.php @@ -77,13 +77,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/ThemeInstall.php b/modules/system/console/ThemeInstall.php index 69c5c4f94..bc7bcc33e 100644 --- a/modules/system/console/ThemeInstall.php +++ b/modules/system/console/ThemeInstall.php @@ -143,13 +143,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..f8dfc8ca7 100644 --- a/modules/system/console/ThemeList.php +++ b/modules/system/console/ThemeList.php @@ -65,14 +65,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. */ From 3a918ad2007877301fcc0d7ad24ee62cb329d5f0 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:33:24 +0200 Subject: [PATCH 03/19] Remove "null" assignments --- modules/backend/behaviors/ReorderController.php | 2 +- modules/backend/classes/FilterScope.php | 2 +- modules/backend/classes/FormField.php | 4 ++-- modules/backend/classes/FormTabs.php | 2 +- modules/backend/formwidgets/DatePicker.php | 8 ++++---- modules/backend/formwidgets/FileUpload.php | 6 +++--- modules/backend/formwidgets/MediaFinder.php | 4 ++-- modules/backend/formwidgets/Repeater.php | 4 ++-- modules/backend/formwidgets/RichEditor.php | 2 +- modules/backend/formwidgets/TagList.php | 2 +- modules/backend/widgets/Filter.php | 2 +- modules/backend/widgets/Form.php | 2 +- modules/backend/widgets/MediaManager.php | 2 +- modules/backend/widgets/Table.php | 4 ++-- modules/cms/classes/Asset.php | 2 +- modules/cms/classes/CmsCompoundObject.php | 2 +- modules/cms/classes/Controller.php | 4 ++-- modules/cms/classes/PartialStack.php | 2 +- modules/cms/classes/Theme.php | 2 +- modules/cms/helpers/Cms.php | 2 +- modules/cms/traits/UrlMaker.php | 4 ++-- modules/cms/widgets/TemplateList.php | 2 +- modules/system/models/PluginVersion.php | 2 +- 23 files changed, 34 insertions(+), 34 deletions(-) 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/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..05a3f5a01 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. diff --git a/modules/backend/classes/FormTabs.php b/modules/backend/classes/FormTabs.php index 253c8e358..f40e3be1d 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. diff --git a/modules/backend/formwidgets/DatePicker.php b/modules/backend/formwidgets/DatePicker.php index 2259174a6..da774b90b 100644 --- a/modules/backend/formwidgets/DatePicker.php +++ b/modules/backend/formwidgets/DatePicker.php @@ -26,25 +26,25 @@ class DatePicker extends FormWidgetBase /** * @var string Provide an explicit date display format. */ - public $format = null; + public $format; /** * @var string the minimum/earliest date that can be selected. * eg: 2000-01-01 */ - public $minDate = null; + public $minDate; /** * @var string the maximum/latest date that can be selected. * eg: 2020-12-31 */ - public $maxDate = null; + public $maxDate; /** * @var string number of years either side or array of upper/lower range * eg: 10 or [1900,1999] */ - public $yearRange = null; + public $yearRange; /** * @var int first day of the week diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index 006ba8cfd..3d36cb2ae 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -36,17 +36,17 @@ class FileUpload extends FormWidgetBase /** * @var string Prompt text to display for the upload button. */ - public $prompt = null; + public $prompt; /** * @var int Preview image width */ - public $imageWidth = null; + public $imageWidth; /** * @var int Preview image height */ - public $imageHeight = null; + public $imageHeight; /** * @var mixed Collection of acceptable file types. diff --git a/modules/backend/formwidgets/MediaFinder.php b/modules/backend/formwidgets/MediaFinder.php index 817d0af78..70c077b8c 100644 --- a/modules/backend/formwidgets/MediaFinder.php +++ b/modules/backend/formwidgets/MediaFinder.php @@ -37,12 +37,12 @@ class MediaFinder extends FormWidgetBase /** * @var int Preview image width */ - public $imageWidth = null; + public $imageWidth; /** * @var int Preview image height */ - public $imageHeight = null; + public $imageHeight; // // Object properties diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index e56da85aa..6c0cdf269 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -39,12 +39,12 @@ class Repeater extends FormWidgetBase /** * @var int Minimum items required. Pre-displays those items when not using groups */ - public $minItems = null; + public $minItems; /** * @var int Maximum items permitted */ - public $maxItems = null; + public $maxItems; // // Object properties diff --git a/modules/backend/formwidgets/RichEditor.php b/modules/backend/formwidgets/RichEditor.php index 48f548156..b9532d54c 100644 --- a/modules/backend/formwidgets/RichEditor.php +++ b/modules/backend/formwidgets/RichEditor.php @@ -29,7 +29,7 @@ class RichEditor extends FormWidgetBase /** * @var boolean Determines whether content has HEAD and HTML tags. */ - public $toolbarButtons = null; + public $toolbarButtons; /** * @var boolean If true, the editor is set to read-only mode diff --git a/modules/backend/formwidgets/TagList.php b/modules/backend/formwidgets/TagList.php index 0ec1d4102..88e62d645 100644 --- a/modules/backend/formwidgets/TagList.php +++ b/modules/backend/formwidgets/TagList.php @@ -30,7 +30,7 @@ class TagList extends FormWidgetBase /** * @var mixed Predefined options settings. Set to true to get from model. */ - public $options = null; + public $options; /** * @var string Mode for the return value. Values: string, array, relation. diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 9af3a8c57..a1e155ec7 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -32,7 +32,7 @@ class Filter extends WidgetBase * @var string The context of this filter, scopes that do not belong * to this context will not be shown. */ - public $context = null; + public $context; // // Object properties diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index ae88098a7..901e34292 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. diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index b9de13fbf..d6d8d8884 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 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/classes/Asset.php b/modules/cms/classes/Asset.php index 6247fcb00..d64ed9956 100644 --- a/modules/cms/classes/Asset.php +++ b/modules/cms/classes/Asset.php @@ -34,7 +34,7 @@ class Asset extends Extendable /** * @var string Specifies the file name, the CMS object was loaded from. */ - protected $originalFileName = null; + protected $originalFileName; /** * @var string Last modified time. diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 8eea1b5d0..3318e1c7e 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -73,7 +73,7 @@ class CmsCompoundObject extends CmsObject /** * @var array|null Cache for component properties. */ - protected static $objectComponentPropertyMap = null; + protected static $objectComponentPropertyMap; /** * @var mixed Cache store for the getViewBag method. diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 43f80329c..4bea8bc1e 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -99,12 +99,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. diff --git a/modules/cms/classes/PartialStack.php b/modules/cms/classes/PartialStack.php index d49db3465..98136e8ae 100644 --- a/modules/cms/classes/PartialStack.php +++ b/modules/cms/classes/PartialStack.php @@ -13,7 +13,7 @@ class PartialStack /** * @var array The current partial "object" being rendered. */ - public $activePartial = null; + public $activePartial; /** * @var array Collection of previously rendered partial "objects". diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index e6ae6c64f..1eb6cc5be 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 diff --git a/modules/cms/helpers/Cms.php b/modules/cms/helpers/Cms.php index d94ac1bdf..e8195d2a5 100644 --- a/modules/cms/helpers/Cms.php +++ b/modules/cms/helpers/Cms.php @@ -12,7 +12,7 @@ use Route; */ class Cms { - protected static $actionExists = null; + protected static $actionExists; /** * Returns a URL in context of the Frontend diff --git a/modules/cms/traits/UrlMaker.php b/modules/cms/traits/UrlMaker.php index 50fc3a26b..210922cfa 100644 --- a/modules/cms/traits/UrlMaker.php +++ b/modules/cms/traits/UrlMaker.php @@ -72,12 +72,12 @@ trait UrlMaker /** * @var string URL cache */ - protected $url = null; + protected $url; /** * @var string Page where detected component is found. */ - protected static $urlPageName = null; + protected static $urlPageName; /** * Changes the component used for generating the URLs dynamically. diff --git a/modules/cms/widgets/TemplateList.php b/modules/cms/widgets/TemplateList.php index a18df610e..46b540550 100644 --- a/modules/cms/widgets/TemplateList.php +++ b/modules/cms/widgets/TemplateList.php @@ -63,7 +63,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. diff --git a/modules/system/models/PluginVersion.php b/modules/system/models/PluginVersion.php index 6fbd26398..321cb60df 100644 --- a/modules/system/models/PluginVersion.php +++ b/modules/system/models/PluginVersion.php @@ -28,7 +28,7 @@ class PluginVersion extends Model /** * @var array Cache store for version information */ - protected static $versionCache = null; + protected static $versionCache; /** * @var bool Plugin has been disabled by a missing dependency. From 0947406343045dafba7fd75b4b4acf05a5be8c86 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:35:15 +0200 Subject: [PATCH 04/19] Remove senseless proxy functions --- modules/cms/classes/CmsObject.php | 11 ----------- modules/system/console/OctoberDown.php | 8 -------- modules/system/console/OctoberEnv.php | 8 -------- modules/system/console/OctoberFresh.php | 8 -------- modules/system/console/OctoberMirror.php | 8 -------- modules/system/console/OctoberUp.php | 8 -------- modules/system/console/OctoberUpdate.php | 8 -------- modules/system/console/OctoberUtil.php | 8 -------- modules/system/console/PluginInstall.php | 9 --------- modules/system/console/PluginRefresh.php | 9 --------- modules/system/console/PluginRemove.php | 9 --------- modules/system/console/ThemeInstall.php | 9 --------- modules/system/console/ThemeList.php | 8 -------- modules/system/console/ThemeRemove.php | 9 --------- modules/system/console/ThemeUse.php | 9 --------- 15 files changed, 129 deletions(-) diff --git a/modules/cms/classes/CmsObject.php b/modules/cms/classes/CmsObject.php index b8b0ee86d..483a10f1d 100644 --- a/modules/cms/classes/CmsObject.php +++ b/modules/cms/classes/CmsObject.php @@ -53,17 +53,6 @@ class CmsObject extends HalcyonModel implements CmsObjectContract */ protected $themeCache; - /** - * Create a new CMS object instance. - * - * @param array $attributes - * @return void - */ - public function __construct(array $attributes = []) - { - parent::__construct($attributes); - } - /** * The "booting" method of the model. * @return void diff --git a/modules/system/console/OctoberDown.php b/modules/system/console/OctoberDown.php index 81ffedbca..5f39fdba9 100644 --- a/modules/system/console/OctoberDown.php +++ b/modules/system/console/OctoberDown.php @@ -26,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. */ diff --git a/modules/system/console/OctoberEnv.php b/modules/system/console/OctoberEnv.php index de8a50390..9bbfff34f 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. */ diff --git a/modules/system/console/OctoberFresh.php b/modules/system/console/OctoberFresh.php index ec002164d..e87e5422d 100644 --- a/modules/system/console/OctoberFresh.php +++ b/modules/system/console/OctoberFresh.php @@ -27,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. */ 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 87c4a156b..a599732b6 100644 --- a/modules/system/console/OctoberUp.php +++ b/modules/system/console/OctoberUp.php @@ -23,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. */ diff --git a/modules/system/console/OctoberUpdate.php b/modules/system/console/OctoberUpdate.php index 9a17e33a1..ccfe1001b 100644 --- a/modules/system/console/OctoberUpdate.php +++ b/modules/system/console/OctoberUpdate.php @@ -29,14 +29,6 @@ class OctoberUpdate extends Command */ protected $description = 'Updates October CMS and all plugins, database and files.'; - /** - * Create a new command instance. - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. */ 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 a9e64d02c..4b7420a79 100644 --- a/modules/system/console/PluginInstall.php +++ b/modules/system/console/PluginInstall.php @@ -28,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 diff --git a/modules/system/console/PluginRefresh.php b/modules/system/console/PluginRefresh.php index 08132f3ef..b79be41ca 100644 --- a/modules/system/console/PluginRefresh.php +++ b/modules/system/console/PluginRefresh.php @@ -29,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 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 bc7bcc33e..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 diff --git a/modules/system/console/ThemeList.php b/modules/system/console/ThemeList.php index f8dfc8ca7..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. */ 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 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 05/19] 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)) { From a075be206bccd827a49f92064d2446f7e32a92a5 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:47:06 +0200 Subject: [PATCH 06/19] Replace class references with "self" --- modules/backend/widgets/MediaManager.php | 10 +++++----- modules/cms/models/ThemeData.php | 4 ++-- modules/system/classes/PluginManager.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index b3f613d93..f00b083ea 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -759,7 +759,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'])) { @@ -774,7 +774,7 @@ class MediaManager extends WidgetBase } return [ - 'mode' => MediaManager::SELECTION_MODE_NORMAL, + 'mode' => self::SELECTION_MODE_NORMAL, 'width' => null, 'height' => null ]; @@ -783,9 +783,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'); } diff --git a/modules/cms/models/ThemeData.php b/modules/cms/models/ThemeData.php index 69194d310..bb6de6a42 100644 --- a/modules/cms/models/ThemeData.php +++ b/modules/cms/models/ThemeData.php @@ -85,11 +85,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/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 4d7d6bc25..a682736d4 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -736,7 +736,7 @@ class PluginManager /* * Delete from file system */ - if ($pluginPath = PluginManager::instance()->getPluginPath($id)) { + if ($pluginPath = self::instance()->getPluginPath($id)) { File::deleteDirectory($pluginPath); } } From 123145fd548431c1b805c09da26e4eed2dfd205a Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:49:52 +0200 Subject: [PATCH 07/19] Remove unnecessary parentheses --- modules/backend/behaviors/FormController.php | 2 +- modules/backend/behaviors/RelationController.php | 2 +- modules/backend/classes/BackendController.php | 2 +- modules/backend/classes/Controller.php | 8 ++++---- modules/backend/classes/WidgetBase.php | 2 +- modules/backend/formwidgets/FileUpload.php | 8 ++++---- modules/backend/widgets/Filter.php | 4 ++-- modules/backend/widgets/Form.php | 4 ++-- modules/cms/classes/ComponentHelpers.php | 4 ++-- modules/cms/classes/Controller.php | 10 +++++----- modules/system/classes/VersionManager.php | 8 ++++---- modules/system/models/File.php | 2 +- modules/system/traits/ViewMaker.php | 2 +- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 7462124d8..1efe1a443 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -472,7 +472,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/RelationController.php b/modules/backend/behaviors/RelationController.php index 389f2f77b..2781302ef 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -421,7 +421,7 @@ class RelationController extends ControllerBehavior /* * Determine the partial to use based on the supplied section option */ - $section = (isset($options['section'])) ? $options['section'] : null; + $section = isset($options['section']) ? $options['section'] : null; switch (strtolower($section)) { case 'toolbar': return $this->toolbarWidget ? $this->toolbarWidget->render() : null; diff --git a/modules/backend/classes/BackendController.php b/modules/backend/classes/BackendController.php index 4330761c6..1a77aa8c8 100644 --- a/modules/backend/classes/BackendController.php +++ b/modules/backend/classes/BackendController.php @@ -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..1cfece561 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -520,7 +520,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 +531,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 +539,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 +551,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/WidgetBase.php b/modules/backend/classes/WidgetBase.php index 468f56d81..31479a726 100644 --- a/modules/backend/classes/WidgetBase.php +++ b/modules/backend/classes/WidgetBase.php @@ -65,7 +65,7 @@ abstract class WidgetBase extends Extendable * If no alias is set by the configuration. */ if (!isset($this->alias)) { - $this->alias = (isset($this->config->alias)) ? $this->config->alias : $this->defaultAlias; + $this->alias = isset($this->config->alias) ? $this->config->alias : $this->defaultAlias; } /* diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index 3d36cb2ae..589ef468b 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -207,20 +207,20 @@ class FileUpload extends FormWidgetBase $cssDimensions = ''; if ($mode == 'block') { - $cssDimensions .= ($this->imageWidth) + $cssDimensions .= $this->imageWidth ? 'width: '.$this->imageWidth.'px;' : 'width: '.$this->imageHeight.'px;'; - $cssDimensions .= ($this->imageHeight) + $cssDimensions .= $this->imageHeight ? 'height: '.$this->imageHeight.'px;' : 'height: auto;'; } else { - $cssDimensions .= ($this->imageWidth) + $cssDimensions .= $this->imageWidth ? 'width: '.$this->imageWidth.'px;' : 'width: auto;'; - $cssDimensions .= ($this->imageHeight) + $cssDimensions .= $this->imageHeight ? 'height: '.$this->imageHeight.'px;' : 'height: auto;'; } diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index a1e155ec7..898d2466f 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -524,7 +524,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; } @@ -584,7 +584,7 @@ class Filter extends WidgetBase */ protected function makeFilterScope($name, $config) { - $label = (isset($config['label'])) ? $config['label'] : null; + $label = isset($config['label']) ? $config['label'] : null; $scopeType = isset($config['type']) ? $config['type'] : null; $scope = new FilterScope($name, $label); diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 901e34292..1852ee751 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -550,7 +550,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; } @@ -643,7 +643,7 @@ class Form extends WidgetBase */ protected function makeFormField($name, $config = []) { - $label = (isset($config['label'])) ? $config['label'] : null; + $label = isset($config['label']) ? $config['label'] : null; list($fieldName, $fieldContext) = $this->getFieldName($name); $field = new FormField($fieldName, $label); diff --git a/modules/cms/classes/ComponentHelpers.php b/modules/cms/classes/ComponentHelpers.php index bdb44a589..703327ecd 100644 --- a/modules/cms/classes/ComponentHelpers.php +++ b/modules/cms/classes/ComponentHelpers.php @@ -106,7 +106,7 @@ class ComponentHelpers public static function getComponentName($component) { $details = $component->componentDetails(); - $name = (isset($details['name'])) + $name = isset($details['name']) ? $details['name'] : 'cms::lang.component.unnamed'; @@ -121,7 +121,7 @@ class ComponentHelpers public static function getComponentDescription($component) { $details = $component->componentDetails(); - $name = (isset($details['description'])) + $name = isset($details['description']) ? $details['description'] : 'cms::lang.component.no_description'; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 91294c7b5..259145029 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -332,7 +332,7 @@ class Controller if ( $useAjax && ($handler = post('_handler')) && - ($this->verifyCsrfToken()) && + $this->verifyCsrfToken() && ($handlerResponse = $this->runAjaxHandler($handler)) && $handlerResponse !== true ) { @@ -717,7 +717,7 @@ class Controller if ($componentObj && $componentObj->methodExists($handlerName)) { $this->componentContext = $componentObj; $result = $componentObj->runAjaxHandler($handlerName); - return ($result) ?: true; + return $result ?: true; } } /* @@ -726,12 +726,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; } /* @@ -740,7 +740,7 @@ class Controller if (($componentObj = $this->findComponentByHandler($handler)) !== null) { $this->componentContext = $componentObj; $result = $componentObj->runAjaxHandler($handler); - return ($result) ?: true; + return $result ?: true; } } diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index dcedfdc07..ace928272 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -79,7 +79,7 @@ class VersionManager */ public function updatePlugin($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; @@ -111,7 +111,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 +165,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; @@ -327,7 +327,7 @@ class VersionManager ; } - return (isset($this->databaseVersions[$code])) + return isset($this->databaseVersions[$code]) ? $this->databaseVersions[$code] : self::NO_VERSION_VALUE; } diff --git a/modules/system/models/File.php b/modules/system/models/File.php index 40f6a46af..b61f7d985 100644 --- a/modules/system/models/File.php +++ b/modules/system/models/File.php @@ -75,6 +75,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/traits/ViewMaker.php b/modules/system/traits/ViewMaker.php index ac8d1d248..2041f3f42 100644 --- a/modules/system/traits/ViewMaker.php +++ b/modules/system/traits/ViewMaker.php @@ -300,6 +300,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; } } From bc17975634157c7bfa37531c591e54f201bc4aa6 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:51:25 +0200 Subject: [PATCH 08/19] Remove alias functions --- modules/backend/formwidgets/DatePicker.php | 4 ++-- modules/cms/twig/DebugExtension.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/backend/formwidgets/DatePicker.php b/modules/backend/formwidgets/DatePicker.php index da774b90b..5bfaea068 100644 --- a/modules/backend/formwidgets/DatePicker.php +++ b/modules/backend/formwidgets/DatePicker.php @@ -90,13 +90,13 @@ class DatePicker extends FormWidgetBase $this->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/cms/twig/DebugExtension.php b/modules/cms/twig/DebugExtension.php index cf58389b5..f747e8c02 100644 --- a/modules/cms/twig/DebugExtension.php +++ b/modules/cms/twig/DebugExtension.php @@ -608,6 +608,6 @@ class DebugExtension extends Twig_Extension $strings[] = $key . ': ' . $value; } - return join('; ', $strings); + return implode('; ', $strings); } } From 77b6f072918c41d7f8efd6b317f6d4b48d9f2601 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:53:11 +0200 Subject: [PATCH 09/19] Modify conditions to use elvis operators --- modules/backend/widgets/Filter.php | 8 ++++---- modules/backend/widgets/MediaManager.php | 2 +- modules/cms/classes/CmsCompoundObject.php | 2 +- modules/cms/classes/Controller.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 898d2466f..4e37ef1a1 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -151,11 +151,11 @@ class Filter extends WidgetBase $min = $scope->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; diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index f00b083ea..1ee174162 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -535,7 +535,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']; diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 3318e1c7e..f5218c76e 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -279,7 +279,7 @@ class CmsCompoundObject extends CmsObject else { $cached = Cache::get($key, false); $unserialized = $cached ? @unserialize(@base64_decode($cached)) : false; - $objectComponentMap = $unserialized ? $unserialized : []; + $objectComponentMap = $unserialized ?: []; if ($objectComponentMap) { self::$objectComponentPropertyMap = $objectComponentMap; } diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 259145029..301b87ba5 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -118,7 +118,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')); } From a3d7a028b44b1705ce1660d50ed0cbfa347fce25 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 18:54:46 +0200 Subject: [PATCH 10/19] Replace is_null with "=== null" comparison --- modules/backend/classes/Controller.php | 2 +- modules/backend/classes/ControllerBehavior.php | 2 +- modules/backend/classes/FormField.php | 2 +- modules/backend/classes/NavigationManager.php | 2 +- modules/backend/controllers/Auth.php | 2 +- modules/backend/formwidgets/RecordFinder.php | 2 +- modules/backend/widgets/Filter.php | 2 +- modules/backend/widgets/Form.php | 2 +- modules/cms/classes/Controller.php | 2 +- modules/system/classes/MarkupManager.php | 2 +- modules/system/console/OctoberEnv.php | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index 1cfece561..2374bec88 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -361,7 +361,7 @@ class Controller extends Extendable } // Load the view - if (!$this->suppressView && is_null($result)) { + if (!$this->suppressView && $result === null) { return $this->makeView($actionName); } 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/FormField.php b/modules/backend/classes/FormField.php index 05a3f5a01..75ae62ac2 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -266,7 +266,7 @@ class FormField */ protected function evalConfig($config) { - if (is_null($config)) { + if ($config === null) { $config = []; } diff --git a/modules/backend/classes/NavigationManager.php b/modules/backend/classes/NavigationManager.php index 0ea6770f6..128ff1103 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) { diff --git a/modules/backend/controllers/Auth.php b/modules/backend/controllers/Auth.php index a024c6b18..4268d2b4e 100644 --- a/modules/backend/controllers/Auth.php +++ b/modules/backend/controllers/Auth.php @@ -75,7 +75,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/formwidgets/RecordFinder.php b/modules/backend/formwidgets/RecordFinder.php index 232010bbb..29fe816cd 100644 --- a/modules/backend/formwidgets/RecordFinder.php +++ b/modules/backend/formwidgets/RecordFinder.php @@ -213,7 +213,7 @@ class RecordFinder extends FormWidgetBase { list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom); - if (!is_null($model)) { + if ($model !== null) { return $model->{$attribute}; } diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 4e37ef1a1..94c415a94 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -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 { diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 1852ee751..154c97410 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -672,7 +672,7 @@ class Form extends WidgetBase else { $fieldType = isset($config['type']) ? $config['type'] : null; - if (!is_string($fieldType) && !is_null($fieldType)) { + if (!is_string($fieldType) && $fieldType !== null) { throw new ApplicationException(Lang::get( 'backend::lang.field.invalid_type', ['type'=>gettype($fieldType)] diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 301b87ba5..427933578 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -484,7 +484,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 === null ? $isDebugMode : $strictVariables; $forceBytecode = Config::get('cms.forceBytecodeInvalidation', false); $options = [ diff --git a/modules/system/classes/MarkupManager.php b/modules/system/classes/MarkupManager.php index 4f7943700..7708021a2 100644 --- a/modules/system/classes/MarkupManager.php +++ b/modules/system/classes/MarkupManager.php @@ -115,7 +115,7 @@ class MarkupManager { $items = $this->transactionMode ? 'transactionItems' : 'items'; - if (is_null($this->$items)) { + if ($this->$items === null) { $this->$items = []; } diff --git a/modules/system/console/OctoberEnv.php b/modules/system/console/OctoberEnv.php index 9bbfff34f..6e87ff908 100644 --- a/modules/system/console/OctoberEnv.php +++ b/modules/system/console/OctoberEnv.php @@ -266,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'; } From 62c59a4903fa30d5cebd298fa4cf420d6e3f1d19 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:15:13 +0200 Subject: [PATCH 11/19] Refactor ternary operators to null coalescing operators --- .../backend/behaviors/ImportExportController.php | 4 +--- modules/backend/behaviors/RelationController.php | 4 ++-- modules/backend/classes/AuthManager.php | 4 +--- modules/backend/classes/BackendController.php | 6 +++--- modules/backend/classes/FormTabs.php | 2 +- modules/backend/classes/NavigationManager.php | 4 +--- modules/backend/classes/WidgetBase.php | 2 +- modules/backend/classes/WidgetManager.php | 2 +- modules/backend/traits/SessionMaker.php | 2 +- modules/backend/widgets/Filter.php | 4 ++-- modules/backend/widgets/Form.php | 6 +++--- modules/backend/widgets/Lists.php | 8 +++----- modules/backend/widgets/ReportContainer.php | 2 +- modules/cms/classes/CodeBase.php | 2 +- modules/cms/classes/ComponentHelpers.php | 8 ++------ modules/cms/classes/Controller.php | 11 +++-------- modules/cms/twig/DebugExtension.php | 2 +- modules/cms/widgets/ComponentList.php | 14 +++----------- modules/system/classes/UpdateManager.php | 6 +++--- modules/system/classes/VersionManager.php | 4 +--- modules/system/models/PluginVersion.php | 4 +--- modules/system/traits/ViewMaker.php | 2 +- 22 files changed, 37 insertions(+), 66 deletions(-) diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index 6b371f68b..67676427d 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 diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 2781302ef..3e14bd615 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -421,7 +421,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; @@ -1520,7 +1520,7 @@ 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')) && is_array($context)) { $context = $exists 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 1a77aa8c8..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; diff --git a/modules/backend/classes/FormTabs.php b/modules/backend/classes/FormTabs.php index f40e3be1d..ea755a55e 100644 --- a/modules/backend/classes/FormTabs.php +++ b/modules/backend/classes/FormTabs.php @@ -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 128ff1103..8af12ee33 100644 --- a/modules/backend/classes/NavigationManager.php +++ b/modules/backend/classes/NavigationManager.php @@ -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/WidgetBase.php b/modules/backend/classes/WidgetBase.php index 31479a726..11c2814d8 100644 --- a/modules/backend/classes/WidgetBase.php +++ b/modules/backend/classes/WidgetBase.php @@ -65,7 +65,7 @@ abstract class WidgetBase extends Extendable * If no alias is set by the configuration. */ if (!isset($this->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/traits/SessionMaker.php b/modules/backend/traits/SessionMaker.php index 3f47fce51..1af4dc71f 100644 --- a/modules/backend/traits/SessionMaker.php +++ b/modules/backend/traits/SessionMaker.php @@ -55,7 +55,7 @@ trait SessionMaker return $currentStore; } - return isset($currentStore[$key]) ? $currentStore[$key] : $default; + return $currentStore[$key] ?? $default; } /** diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 94c415a94..6cd2fd477 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -584,8 +584,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); diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 154c97410..2dc30ab48 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -643,7 +643,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); @@ -671,7 +671,7 @@ class Form extends WidgetBase */ else { - $fieldType = isset($config['type']) ? $config['type'] : null; + $fieldType = $config['type'] ?? null; if (!is_string($fieldType) && $fieldType !== null) { throw new ApplicationException(Lang::get( 'backend::lang.field.invalid_type', @@ -714,7 +714,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; }); diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index f0e52b472..b18d0391c 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -873,7 +873,7 @@ class Lists extends WidgetBase $config['searchable'] = false; } - $columnType = isset($config['type']) ? $config['type'] : null; + $columnType = $config['type'] ?? null; $column = new ListColumn($name, $label); $column->displayAs($columnType, $config); @@ -1220,7 +1220,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); @@ -1489,9 +1489,7 @@ class Lists extends WidgetBase } 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'; } } 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/cms/classes/CodeBase.php b/modules/cms/classes/CodeBase.php index 4fc9eb9bd..87df2dcc9 100644 --- a/modules/cms/classes/CodeBase.php +++ b/modules/cms/classes/CodeBase.php @@ -94,7 +94,7 @@ class CodeBase extends Extendable implements ArrayAccess */ public function offsetGet($offset) { - return isset($this->controller->vars[$offset]) ? $this->controller->vars[$offset] : null; + return $this->controller->vars[$offset] ?? null; } /** diff --git a/modules/cms/classes/ComponentHelpers.php b/modules/cms/classes/ComponentHelpers.php index 703327ecd..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 427933578..ab73e1111 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -484,7 +484,7 @@ class Controller $useCache = !Config::get('cms.twigNoCache'); $isDebugMode = Config::get('app.debug', false); $strictVariables = Config::get('cms.enableTwigStrictVariables', false); - $strictVariables = $strictVariables === null ? $isDebugMode : $strictVariables; + $strictVariables = $strictVariables ?? $isDebugMode; $forceBytecode = Config::get('cms.forceBytecodeInvalidation', false); $options = [ @@ -1354,15 +1354,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/twig/DebugExtension.php b/modules/cms/twig/DebugExtension.php index f747e8c02..ab80f116a 100644 --- a/modules/cms/twig/DebugExtension.php +++ b/modules/cms/twig/DebugExtension.php @@ -374,7 +374,7 @@ class DebugExtension extends Twig_Extension } $method = $parts[1]; - return isset($this->commentMap[$method]) ? $this->commentMap[$method] : null; + return $this->commentMap[$method] ?? null; } /** diff --git a/modules/cms/widgets/ComponentList.php b/modules/cms/widgets/ComponentList.php index 8c0486004..6b0d008e3 100644 --- a/modules/cms/widgets/ComponentList.php +++ b/modules/cms/widgets/ComponentList.php @@ -78,17 +78,9 @@ class ComponentList extends WidgetBase $pluginDetails = $plugin->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/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index bac12a550..916e3f10b 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -251,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, diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index ace928272..4b1666a48 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -327,9 +327,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/models/PluginVersion.php b/modules/system/models/PluginVersion.php index 321cb60df..29ebe4298 100644 --- a/modules/system/models/PluginVersion.php +++ b/modules/system/models/PluginVersion.php @@ -146,9 +146,7 @@ class PluginVersion extends Model self::$versionCache = self::lists('version', 'code'); } - return isset(self::$versionCache[$pluginCode]) - ? self::$versionCache[$pluginCode] - : null; + return self::$versionCache[$pluginCode] ?? null; } /** diff --git a/modules/system/traits/ViewMaker.php b/modules/system/traits/ViewMaker.php index 2041f3f42..be2ef1fcc 100644 --- a/modules/system/traits/ViewMaker.php +++ b/modules/system/traits/ViewMaker.php @@ -140,7 +140,7 @@ trait ViewMaker */ public function makeLayout($name = null, $params = [], $throwException = true) { - $layout = $name === null ? $this->layout : $name; + $layout = $name ?? $this->layout; if ($layout == '') { return ''; } From 2cdbb37a367c82d5199195ae17708581210baada Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:18:26 +0200 Subject: [PATCH 12/19] Remove duplicate array keys in language files --- modules/backend/lang/bg/lang.php | 1 - modules/backend/lang/fa/lang.php | 2 -- modules/cms/lang/et/lang.php | 1 - modules/system/lang/cs/lang.php | 1 - 4 files changed, 5 deletions(-) diff --git a/modules/backend/lang/bg/lang.php b/modules/backend/lang/bg/lang.php index 4544f6548..308d875a9 100644 --- a/modules/backend/lang/bg/lang.php +++ b/modules/backend/lang/bg/lang.php @@ -136,7 +136,6 @@ return [ 'setup_title' => 'Настройка на списък', '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/cms/lang/et/lang.php b/modules/cms/lang/et/lang.php index 2ef5df439..12841b1cd 100644 --- a/modules/cms/lang/et/lang.php +++ b/modules/cms/lang/et/lang.php @@ -255,7 +255,6 @@ return [ 'name' => '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/system/lang/cs/lang.php b/modules/system/lang/cs/lang.php index d139e750c..913446d43 100644 --- a/modules/system/lang/cs/lang.php +++ b/modules/system/lang/cs/lang.php @@ -185,7 +185,6 @@ return [ 'deleting' => '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' => [ From ab73442e3d9b07b6474e9732c96e97670904508b Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:18:52 +0200 Subject: [PATCH 13/19] Add missing break statement --- modules/backend/widgets/Filter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 6cd2fd477..030f253f3 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -705,6 +705,8 @@ class Filter extends WidgetBase } } + break; + case 'numberrange': if (is_array($scope->value) && count($scope->value) > 1) { list($min, $max) = array_values($scope->value); From fbca3bea927686dde3f485012fd6a437e9ac8cd8 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:23:12 +0200 Subject: [PATCH 14/19] Remove redundant variables --- modules/backend/behaviors/FormController.php | 3 +-- modules/backend/behaviors/ImportExportController.php | 3 +-- modules/backend/behaviors/RelationController.php | 3 +-- modules/backend/models/BrandSetting.php | 4 +--- modules/backend/models/EditorSetting.php | 4 +--- modules/backend/widgets/Form.php | 3 +-- modules/backend/widgets/MediaManager.php | 8 ++------ modules/cms/classes/Theme.php | 3 +-- modules/cms/controllers/Index.php | 4 +--- modules/cms/controllers/ThemeOptions.php | 3 +-- modules/cms/controllers/Themes.php | 12 ++++-------- modules/system/classes/VersionManager.php | 3 +-- modules/system/controllers/Settings.php | 3 +-- modules/system/helpers/DateTime.php | 3 +-- modules/system/models/MailBrandSetting.php | 4 +--- modules/system/traits/ConfigMaker.php | 3 +-- 16 files changed, 20 insertions(+), 46 deletions(-) diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 1efe1a443..8cba49f65 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -436,8 +436,7 @@ class FormController extends ControllerBehavior protected function createModel() { $class = $this->config->modelClass; - $model = new $class; - return $model; + return new $class; } /** diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index 67676427d..a84a203d1 100644 --- a/modules/backend/behaviors/ImportExportController.php +++ b/modules/backend/behaviors/ImportExportController.php @@ -695,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/RelationController.php b/modules/backend/behaviors/RelationController.php index 3e14bd615..453aedcca 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -903,8 +903,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); } // 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/widgets/Form.php b/modules/backend/widgets/Form.php index 2dc30ab48..353390040 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -947,8 +947,7 @@ class Form extends WidgetBase } if ($field->type === 'widget') { - $widget = $this->makeFormFieldWidget($field); - return $widget->showLabels; + return $this->makeFormFieldWidget($field)->showLabels; } return true; diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index 1ee174162..3910d2815 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -683,9 +683,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) @@ -899,9 +897,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) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 1eb6cc5be..3cb5cfefc 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -448,8 +448,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/controllers/Index.php b/modules/cms/controllers/Index.php index 57dc574f2..37534d196 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -427,9 +427,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) diff --git a/modules/cms/controllers/ThemeOptions.php b/modules/cms/controllers/ThemeOptions.php index 02fe3d30b..9333e1c06 100644 --- a/modules/cms/controllers/ThemeOptions.php +++ b/modules/cms/controllers/ThemeOptions.php @@ -131,8 +131,7 @@ class ThemeOptions extends Controller protected function getThemeData($dirName) { $theme = $this->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 836fbbeb3..d80015d61 100644 --- a/modules/cms/controllers/Themes.php +++ b/modules/cms/controllers/Themes.php @@ -115,8 +115,7 @@ class Themes extends Controller $widgetConfig->arrayName = 'Theme'; $widgetConfig->context = 'update'; - $widget = $this->makeWidget(Form::class, $widgetConfig); - return $widget; + return $this->makeWidget(Form::class, $widgetConfig); } // @@ -173,8 +172,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); } // @@ -256,8 +254,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); } // @@ -293,8 +290,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/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index 4b1666a48..8236e44d9 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -246,8 +246,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))); } /** diff --git a/modules/system/controllers/Settings.php b/modules/system/controllers/Settings.php index 0197cd379..522ff0f38 100644 --- a/modules/system/controllers/Settings.php +++ b/modules/system/controllers/Settings.php @@ -165,8 +165,7 @@ class Settings extends Controller } $class = $item->class; - $model = $class::instance(); - return $model; + return $class::instance(); } /** diff --git a/modules/system/helpers/DateTime.php b/modules/system/helpers/DateTime.php index 45522071a..e8a68ebaa 100644 --- a/modules/system/helpers/DateTime.php +++ b/modules/system/helpers/DateTime.php @@ -130,8 +130,7 @@ class DateTime $replacements['\\'.$from] = '['.$from.']'; } - $momentFormat = strtr($format, $replacements); - return $momentFormat; + return strtr($format, $replacements); } } diff --git a/modules/system/models/MailBrandSetting.php b/modules/system/models/MailBrandSetting.php index 9e32fe989..95d467d04 100644 --- a/modules/system/models/MailBrandSetting.php +++ b/modules/system/models/MailBrandSetting.php @@ -154,8 +154,6 @@ class MailBrandSetting extends Model $parser->parse(FileHelper::get($basePath . '/custom.less')); - $css = $parser->getCss(); - - return $css; + return $parser->getCss(); } } diff --git a/modules/system/traits/ConfigMaker.php b/modules/system/traits/ConfigMaker.php index 5e4f95198..0b068227f 100644 --- a/modules/system/traits/ConfigMaker.php +++ b/modules/system/traits/ConfigMaker.php @@ -182,8 +182,7 @@ trait ConfigMaker { $classFolder = strtolower(class_basename($class)); $classFile = realpath(dirname(File::fromClass($class))); - $guessedPath = $classFile ? $classFile . '/' . $classFolder . $suffix : null; - return $guessedPath; + return $classFile ? $classFile . '/' . $classFolder . $suffix : null; } /** From 8b6f11e6acfe3c14127d7d42c0e17cb8d8ae999c Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:25:42 +0200 Subject: [PATCH 15/19] Extract child instructions --- .../backend/behaviors/RelationController.php | 15 +++---- modules/backend/classes/FormField.php | 10 ++--- modules/backend/classes/Skin.php | 9 ++-- modules/backend/controllers/Auth.php | 5 +-- modules/backend/models/User.php | 11 +++-- modules/backend/widgets/Form.php | 4 +- modules/backend/widgets/Lists.php | 5 +-- modules/backend/widgets/MediaManager.php | 44 +++++++++---------- modules/backend/widgets/Search.php | 4 +- modules/cms/classes/Controller.php | 10 ++--- modules/system/classes/CombineAssets.php | 5 +-- modules/system/classes/PluginBase.php | 5 +-- modules/system/console/OctoberUpdate.php | 5 +-- modules/system/models/File.php | 5 +-- modules/system/traits/EventEmitter.php | 10 ++--- modules/system/traits/ViewMaker.php | 10 ++--- 16 files changed, 68 insertions(+), 89 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 453aedcca..278c99d70 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1445,9 +1445,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'; @@ -1508,9 +1507,8 @@ class RelationController extends ControllerBehavior if ($this->eventTarget == 'button-add') { return 'list'; } - else { - return 'form'; - } + + return 'form'; } } @@ -1600,9 +1598,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/classes/FormField.php b/modules/backend/classes/FormField.php index 75ae62ac2..dc7109c1d 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -234,9 +234,8 @@ class FormField return []; } - else { - $this->options = $value; - } + + $this->options = $value; return $this; } @@ -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/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/controllers/Auth.php b/modules/backend/controllers/Auth.php index 4268d2b4e..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()); 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/widgets/Form.php b/modules/backend/widgets/Form.php index 353390040..9762ff568 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -1163,9 +1163,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 b18d0391c..0c83abd16 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -1514,9 +1514,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 3910d2815..4457d1f4c 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -1303,31 +1303,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/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/cms/classes/Controller.php b/modules/cms/classes/Controller.php index ab73e1111..0b14c9561 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -820,9 +820,8 @@ class Controller if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name'=>$partialName])); } - else { - return false; - } + + return false; } } /* @@ -857,9 +856,8 @@ class Controller if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name'=>$name])); } - else { - return false; - } + + return false; } /* diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index 32d4e084c..34dceea32 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -487,9 +487,8 @@ class CombineAssets if ($actionExists) { return Url::action($combineAction, [$outputFilename], false); } - else { - return '/combine/'.$outputFilename; - } + + return '/combine/'.$outputFilename; } /** diff --git a/modules/system/classes/PluginBase.php b/modules/system/classes/PluginBase.php index 7a0507544..54fbf20a6 100644 --- a/modules/system/classes/PluginBase.php +++ b/modules/system/classes/PluginBase.php @@ -255,9 +255,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/console/OctoberUpdate.php b/modules/system/console/OctoberUpdate.php index ccfe1001b..f2404f862 100644 --- a/modules/system/console/OctoberUpdate.php +++ b/modules/system/console/OctoberUpdate.php @@ -63,9 +63,8 @@ class OctoberUpdate extends Command $this->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'); diff --git a/modules/system/models/File.php b/modules/system/models/File.php index b61f7d985..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/'; } /** diff --git a/modules/system/traits/EventEmitter.php b/modules/system/traits/EventEmitter.php index 054668b4c..919b93cdc 100644 --- a/modules/system/traits/EventEmitter.php +++ b/modules/system/traits/EventEmitter.php @@ -48,9 +48,8 @@ trait EventEmitter if ($halt) { return $response; } - else { - $result = array_merge($result, $response); - } + + $result = array_merge($result, $response); } /* @@ -60,9 +59,8 @@ trait EventEmitter if ($halt) { return $response; } - else { - $result = array_merge($result, $response); - } + + $result = array_merge($result, $response); } return $result; diff --git a/modules/system/traits/ViewMaker.php b/modules/system/traits/ViewMaker.php index be2ef1fcc..36255383e 100644 --- a/modules/system/traits/ViewMaker.php +++ b/modules/system/traits/ViewMaker.php @@ -91,9 +91,8 @@ trait ViewMaker if ($throwException) { throw new SystemException(Lang::get('backend::lang.partial.not_found_name', ['name' => $partialPath])); } - else { - return false; - } + + return false; } return $this->makeFileContents($partialPath, $params); @@ -151,9 +150,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); From ee9414f3fd2dad0017a7daf8ae41920065463f6e Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:26:20 +0200 Subject: [PATCH 16/19] Simplify ternary operators --- modules/backend/widgets/Filter.php | 2 +- modules/system/classes/PluginManager.php | 4 +--- modules/system/classes/VersionManager.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 030f253f3..322f26000 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -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; diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index a682736d4..a3e1ffa69 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -300,9 +300,7 @@ class PluginManager */ public function exists($id) { - return (!$this->findByIdentifier($id) || $this->isDisabled($id)) - ? false - : true; + return !(!$this->findByIdentifier($id) || $this->isDisabled($id)); } /** diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index 8236e44d9..4fd08f953 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -229,7 +229,7 @@ class VersionManager $history->delete(); } - return (($countHistory + $countVersions) > 0) ? true : false; + return ($countHistory + $countVersions) > 0; } // From 0716101bc8d79a57d5f1ab29d9aba301ad413195 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Wed, 15 Aug 2018 19:26:49 +0200 Subject: [PATCH 17/19] Merge unset statements --- modules/cms/controllers/Index.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index 37534d196..d7cb19fd2 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -459,9 +459,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; } } From 66fa03f17e962aba34f9fef02c5d3bca524632ed Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Fri, 24 Aug 2018 19:40:40 +0200 Subject: [PATCH 18/19] Revert "Remove unused imports" This reverts commit 742a5f415bc45819b11c77402efc114fa2f4451e. --- modules/backend/ServiceProvider.php | 1 + modules/backend/formwidgets/Repeater.php | 1 + modules/backend/models/Preference.php | 1 + modules/backend/models/UserPreference.php | 2 ++ modules/backend/traits/FormModelSaver.php | 1 + modules/backend/widgets/Lists.php | 1 + modules/cms/ServiceProvider.php | 1 + modules/cms/classes/Asset.php | 1 + modules/cms/classes/ComponentBase.php | 2 ++ modules/cms/classes/Controller.php | 3 +++ modules/cms/classes/Page.php | 2 ++ modules/cms/components/UnknownComponent.php | 1 + modules/cms/controllers/Index.php | 1 + modules/cms/controllers/ThemeLogs.php | 2 ++ modules/cms/controllers/ThemeOptions.php | 1 + modules/cms/controllers/Themes.php | 2 ++ modules/cms/twig/Extension.php | 2 ++ modules/cms/twig/FlashNode.php | 1 + modules/cms/twig/FlashTokenParser.php | 1 + modules/cms/widgets/AssetList.php | 2 ++ modules/system/ServiceProvider.php | 2 ++ modules/system/classes/CombineAssets.php | 1 + modules/system/classes/MailManager.php | 3 +++ modules/system/classes/MarkupManager.php | 1 + modules/system/classes/PluginBase.php | 1 + modules/system/classes/SettingsManager.php | 2 ++ modules/system/classes/SystemController.php | 1 + modules/system/classes/UpdateManager.php | 1 + modules/system/console/OctoberDown.php | 1 + modules/system/console/OctoberFresh.php | 2 ++ modules/system/console/OctoberInstall.php | 2 ++ modules/system/console/OctoberUp.php | 2 ++ modules/system/console/OctoberUpdate.php | 1 + modules/system/console/PluginInstall.php | 1 + modules/system/console/PluginRefresh.php | 1 + modules/system/controllers/EventLogs.php | 2 ++ modules/system/controllers/MailBrandSettings.php | 2 ++ modules/system/controllers/MailLayouts.php | 2 ++ modules/system/controllers/MailPartials.php | 2 ++ modules/system/controllers/MailTemplates.php | 1 + modules/system/controllers/RequestLogs.php | 2 ++ modules/system/controllers/Settings.php | 1 + .../2015_10_01_000014_Db_System_Mail_Layout_Rename.php | 1 + modules/system/models/MailPartial.php | 1 + modules/system/models/Parameter.php | 1 + modules/system/traits/ConfigMaker.php | 1 + modules/system/twig/Extension.php | 2 ++ 47 files changed, 69 insertions(+) diff --git a/modules/backend/ServiceProvider.php b/modules/backend/ServiceProvider.php index 92b503d08..195ab1856 100644 --- a/modules/backend/ServiceProvider.php +++ b/modules/backend/ServiceProvider.php @@ -1,6 +1,7 @@ Date: Fri, 24 Aug 2018 19:51:59 +0200 Subject: [PATCH 19/19] Remove unused imports --- modules/backend/behaviors/FormController.php | 1 - modules/backend/behaviors/ListController.php | 1 - modules/backend/behaviors/RelationController.php | 1 - modules/backend/classes/Controller.php | 1 - modules/backend/classes/WidgetBase.php | 2 -- modules/backend/controllers/Index.php | 1 - modules/backend/controllers/UserGroups.php | 1 - modules/backend/controllers/UserRoles.php | 1 - modules/backend/formwidgets/FileUpload.php | 1 - modules/backend/formwidgets/MediaFinder.php | 2 -- modules/backend/formwidgets/RecordFinder.php | 2 -- modules/backend/formwidgets/Relation.php | 3 --- modules/backend/formwidgets/Repeater.php | 1 - modules/backend/models/Preference.php | 1 - modules/backend/models/UserPreference.php | 2 -- modules/backend/traits/FormModelSaver.php | 1 - modules/backend/traits/SessionMaker.php | 1 - modules/backend/widgets/Lists.php | 3 --- modules/cms/ServiceProvider.php | 1 - modules/cms/classes/Asset.php | 1 - modules/cms/classes/CmsObjectCollection.php | 1 - modules/cms/classes/ComponentBase.php | 2 -- modules/cms/classes/Controller.php | 5 ----- modules/cms/classes/Page.php | 2 -- modules/cms/classes/Router.php | 1 - modules/cms/components/Resources.php | 1 - modules/cms/components/UnknownComponent.php | 1 - modules/cms/controllers/Index.php | 2 -- modules/cms/controllers/ThemeLogs.php | 6 ------ modules/cms/controllers/ThemeOptions.php | 1 - modules/cms/controllers/Themes.php | 3 --- modules/cms/formwidgets/Components.php | 1 - modules/cms/models/ThemeExport.php | 1 - modules/cms/models/ThemeImport.php | 1 - modules/cms/twig/Extension.php | 4 ---- modules/cms/twig/FlashNode.php | 1 - modules/cms/twig/FlashTokenParser.php | 1 - modules/cms/widgets/AssetList.php | 6 ------ modules/cms/widgets/TemplateList.php | 1 - modules/system/ServiceProvider.php | 3 --- modules/system/behaviors/SettingsModel.php | 1 - modules/system/classes/CombineAssets.php | 1 - modules/system/classes/MailManager.php | 2 -- modules/system/classes/MarkupManager.php | 1 - modules/system/classes/SettingsManager.php | 1 - modules/system/classes/SystemController.php | 1 - modules/system/classes/UpdateManager.php | 1 - modules/system/classes/VersionManager.php | 1 - modules/system/console/OctoberDown.php | 1 - modules/system/console/OctoberFresh.php | 2 -- modules/system/console/OctoberInstall.php | 4 ---- modules/system/console/OctoberUp.php | 2 -- modules/system/console/OctoberUpdate.php | 2 -- modules/system/console/PluginInstall.php | 1 - modules/system/console/PluginRefresh.php | 1 - modules/system/controllers/EventLogs.php | 6 ------ modules/system/controllers/MailBrandSettings.php | 3 --- modules/system/controllers/MailLayouts.php | 5 ----- modules/system/controllers/MailPartials.php | 8 -------- modules/system/controllers/MailTemplates.php | 6 ------ modules/system/controllers/RequestLogs.php | 6 ------ modules/system/controllers/Settings.php | 1 - modules/system/controllers/Updates.php | 2 -- .../2015_10_01_000014_Db_System_Mail_Layout_Rename.php | 1 - modules/system/helpers/DateTime.php | 1 - modules/system/models/LogSetting.php | 1 - modules/system/models/MailBrandSetting.php | 3 --- modules/system/models/MailPartial.php | 2 -- modules/system/models/MailTemplate.php | 1 - modules/system/models/Parameter.php | 1 - modules/system/traits/ConfigMaker.php | 1 - modules/system/traits/ViewMaker.php | 1 - modules/system/twig/Extension.php | 3 --- 73 files changed, 146 deletions(-) diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 8cba49f65..3a76b6e98 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; 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 @@