Skip to content

Commit

Permalink
Code quality clean up (octobercms#4449)
Browse files Browse the repository at this point in the history
Credit to @bennothommo
  • Loading branch information
bennothommo authored and LukeTowers committed Jul 18, 2019
1 parent cc7d595 commit a59d3b8
Show file tree
Hide file tree
Showing 134 changed files with 307 additions and 306 deletions.
4 changes: 3 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ Please ensure that your Pull Request satisfies the following coding standards:
- [PSR 1 Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)
- [PSR 0 Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)

To validate your changes against our coding standards, you may run `./vendor/bin/phpcs -nq --extensions="php"` in your development folder.

#### Team rules

The October team follows the [developer guidelines](https://octobercms.com/docs/help/developer-guide) as much as possible.

#### Escalation process

We do our best to attend to all reported issues. If you have an important issue that requires attention, consider submitting a bounty using the [OctoberCMS Bounty Program](https://www.bountysource.com/teams/october).
We do our best to attend to all reported issues. If you have an important issue that requires attention, consider submitting a bounty using the [OctoberCMS Bounty Program](https://www.bountysource.com/teams/october).
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
| -------- STOP! --------
| Before you change this value, consider carefully if that is actually
| what you want to do. It is HIGHLY recommended that this is always set
| to UTC (as your server & DB timezone should be as well) and instead you
| to UTC (as your server & DB timezone should be as well) and instead you
| use cms.backendTimezone to set the default timezone used in the backend
| to display dates & times.
|
Expand Down
4 changes: 2 additions & 2 deletions config/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@
| this feature on can create a conflict if you have a frontend Service
| Worker running. The 'scope' needs to be correctly set and not have a
| duplicate subfolder structure on the frontend, otherwise it will run
| on both the frontend and backend of your website.
| on both the frontend and backend of your website.
|
| true - allow service workers to run in the backend
|
| false - disallow service workers to run in the backend
|
*/

'enableBackendServiceWorkers' => false,
'enableBackendServiceWorkers' => false,

];
4 changes: 3 additions & 1 deletion modules/backend/behaviors/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public function initForm($model, $context = null)

$this->formWidget->bindEvent('form.beforeRefresh', function ($holder) {
$result = $this->controller->formExtendRefreshData($this->formWidget, $holder->data);
if (is_array($result)) $holder->data = $result;
if (is_array($result)) {
$holder->data = $result;
}
});

$this->formWidget->bindEvent('form.refreshFields', function ($fields) {
Expand Down
14 changes: 5 additions & 9 deletions modules/backend/behaviors/RelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,6 @@ protected function makeManageWidget()
* Form
*/
elseif ($this->manageMode == 'form') {

if (!$config = $this->makeConfigForMode('manage', 'form', false)) {
return null;
}
Expand Down Expand Up @@ -1205,7 +1204,6 @@ public function onRelationManageAdd()
* Add
*/
if ($this->viewMode == 'multi') {

$checkedIds = $recordId ? [$recordId] : post('checked');

if (is_array($checkedIds)) {
Expand All @@ -1221,14 +1219,12 @@ public function onRelationManageAdd()
$this->relationObject->add($model, $sessionKey);
}
}

}
/*
* Link
*/
elseif ($this->viewMode == 'single') {
if ($recordId && ($model = $this->relationModel->find($recordId))) {

$this->relationObject->add($model, $sessionKey);
$this->viewWidget->setFormValues($model->attributes);

Expand All @@ -1242,7 +1238,6 @@ public function onRelationManageAdd()
$parentModel->save();
}
}

}
}

Expand All @@ -1264,7 +1259,6 @@ public function onRelationManageRemove()
* Remove
*/
if ($this->viewMode == 'multi') {

$checkedIds = $recordId ? [$recordId] : post('checked');

if (is_array($checkedIds)) {
Expand Down Expand Up @@ -1707,7 +1701,8 @@ protected function makeConfigForMode($mode = 'view', $type = 'list', $throwExcep
*
* @return \Backend\Classes\WidgetBase
*/
public function relationGetManageWidget() {
public function relationGetManageWidget()
{
return $this->manageWidget;
}

Expand All @@ -1716,7 +1711,8 @@ public function relationGetManageWidget() {
*
* @return \Backend\Classes\WidgetBase
*/
public function relationGetViewWidget() {
public function relationGetViewWidget()
{
return $this->viewWidget;
}
}
}
1 change: 0 additions & 1 deletion modules/backend/classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public function run($action = null, $params = [])
* Check that user is logged in and has permission to view this page
*/
if (!$isPublicAction) {

/*
* Not logged in, redirect to login screen or show ajax error.
*/
Expand Down
2 changes: 0 additions & 2 deletions modules/backend/classes/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ protected function getFieldNameFromData($fieldName, $data, $default = null)
* relation value, all others will look up the relation object as normal.
*/
foreach ($keyParts as $key) {

if ($result instanceof Model && $result->hasRelation($key)) {
if ($key == $lastField) {
$result = $result->getRelationValue($key) ?: $default;
Expand All @@ -709,7 +708,6 @@ protected function getFieldNameFromData($fieldName, $data, $default = null)
}
$result = $result->{$key};
}

}

return $result;
Expand Down
19 changes: 10 additions & 9 deletions modules/backend/classes/FormTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class FormTabs implements IteratorAggregate, ArrayAccess
* @var string Default tab label to use when none is specified.
*/
public $defaultTab = 'backend::lang.form.undefined_tab';

/**
* @var array List of icons for their corresponding tabs.
*/
public $icons = [];

/**
* @var bool Should these tabs stretch to the bottom of the page layout.
*/
Expand Down Expand Up @@ -86,11 +86,11 @@ protected function evalConfig($config)
if (array_key_exists('defaultTab', $config)) {
$this->defaultTab = $config['defaultTab'];
}

if (array_key_exists('icons', $config)) {
$this->icons = $config['icons'];
}

if (array_key_exists('stretch', $config)) {
$this->stretch = $config['stretch'];
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public function getAllFields()

return $tablessFields;
}

/**
* Returns an icon for the tab based on the tab's name.
* @param string $name
Expand All @@ -194,7 +194,7 @@ public function getIcon($name)
return $this->icons[$name];
}
}

/**
* Returns a tab pane CSS class.
* @param string $index
Expand Down Expand Up @@ -222,9 +222,10 @@ public function getPaneCssClass($index = null, $label = null)
*/
public function getIterator()
{
return new ArrayIterator($this->suppressTabs
? $this->getAllFields()
: $this->getFields()
return new ArrayIterator(
$this->suppressTabs
? $this->getAllFields()
: $this->getFields()
);
}

Expand Down
1 change: 0 additions & 1 deletion modules/backend/classes/FormWidgetBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,4 @@ public function getLoadValue()

return $this->formField->getValueFromData($this->data ?: $this->model, $defaultValue);
}

}
6 changes: 4 additions & 2 deletions modules/backend/classes/NavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ protected function loadItems()
*/
$orderCount = 0;
foreach ($item->sideMenu as $sideMenuItem) {
if ($sideMenuItem->order !== -1) continue;
if ($sideMenuItem->order !== -1) {
continue;
}
$sideMenuItem->order = ($orderCount += 100);
}

Expand Down Expand Up @@ -530,4 +532,4 @@ protected function makeItemKey($owner, $code)
{
return strtoupper($owner).'.'.strtoupper($code);
}
}
}
2 changes: 1 addition & 1 deletion modules/backend/classes/WidgetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ public function removeReportWidget($className)

unset($this->reportWidgets[$className]);
}
}
}
6 changes: 4 additions & 2 deletions modules/backend/controllers/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function get($code = null)
try {
return $this->findFileObject($code)->output('inline', true);
}
catch (Exception $ex) {}
catch (Exception $ex) {
}

return Response::make(View::make('backend::404'), 404);
}
Expand All @@ -48,7 +49,8 @@ public function thumb($code = null, $width = 100, $height = 100, $mode = 'auto',
true
);
}
catch (Exception $ex) {}
catch (Exception $ex) {
}

return Response::make(View::make('backend::404'), 404);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/controllers/UserRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct()
/*
* Only super users can access
*/
$this->bindEvent('page.beforeDisplay', function() {
$this->bindEvent('page.beforeDisplay', function () {
if (!$this->user->isSuperUser()) {
return Response::make(View::make('backend::access_denied'), 403);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ protected function migratePermissionsFromGroupsToRoles()
'permissions' => $group->permissions ?? null
]);
}
catch (Exception $ex) {}
catch (Exception $ex) {
}

$permissions[$group->id] = $group->permissions ?? null;
}
Expand Down Expand Up @@ -130,7 +131,8 @@ protected function migratePermissionsFromGroupsToRoles()
$perms = json_decode($permString, true);
$userPerms = array_merge($userPerms, $perms);
}
catch (Exception $ex) {}
catch (Exception $ex) {
}
}

if (count($userPerms) > 0) {
Expand All @@ -157,6 +159,7 @@ protected function splicePermissionsForUser($userId, $permissions)
'permissions' => json_encode($newPerms)
]);
}
catch (Exception $ex) {}
catch (Exception $ex) {
}
}
}
1 change: 0 additions & 1 deletion modules/backend/formwidgets/CodeEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,4 @@ protected function applyEditorPreferences()
$this->displayIndentGuides = $preferences->editor_display_indent_guides;
$this->showPrintMargin = $preferences->editor_show_print_margin;
}

}
1 change: 0 additions & 1 deletion modules/backend/formwidgets/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,4 @@ public function getDataTableOptions($field, $data)

return $result;
}

}
2 changes: 1 addition & 1 deletion modules/backend/formwidgets/DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function prepareVars()
if ($this->mode === 'date' && !$this->ignoreTimezone) {
$backendTimeZone = \Backend\Models\Preference::get('timezone');
$value->setTimezone($backendTimeZone);
$value->setTime(0,0,0);
$value->setTime(0, 0, 0);
$value->setTimezone(Config::get('app.timezone'));
}
$value = $value->toDateTimeString();
Expand Down
8 changes: 5 additions & 3 deletions modules/backend/formwidgets/NestedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class NestedForm extends FormWidgetBase
/**
* @inheritDoc
*/
public function init() {
public function init()
{
$this->fillFromConfig([
'form',
'usePanelStyles',
Expand All @@ -62,13 +63,14 @@ protected function loadAssets()
/**
* @inheritdoc
*/
function render()
public function render()
{
$this->prepareVars();
return $this->makePartial('nestedform');
}

function prepareVars() {
public function prepareVars()
{
$this->formWidget->previewMode = $this->previewMode;
}
}
2 changes: 1 addition & 1 deletion modules/backend/formwidgets/RichEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ protected function getPageLinksArray()

$iterator = function ($links, $level = 0) use (&$iterator) {
$result = [];
foreach ($links as $linkUrl => $link) {

foreach ($links as $linkUrl => $link) {
/*
* Remove scheme and host from URL
*/
Expand Down
7 changes: 4 additions & 3 deletions modules/backend/formwidgets/TagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ protected function getCustomSeparators()
protected function getSeparatorCharacter()
{
switch (strtolower($this->separator)) {
case 'comma': return ',';
case 'space': return ' ';
case 'comma':
return ',';
case 'space':
return ' ';
}
}

}
5 changes: 2 additions & 3 deletions modules/backend/helpers/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function dateTime($dateTime, $options = [])
'timeSince' => false,
'ignoreTimezone' => false,
], $options));
if(!$dateTime) {

if (!$dateTime) {
return '';
}

Expand Down Expand Up @@ -156,5 +156,4 @@ public function dateTime($dateTime, $options = [])

return '<time'.Html::attributes($attributes).'>'.e($defaultValue).'</time>'.PHP_EOL;
}

}
3 changes: 1 addition & 2 deletions modules/backend/models/BrandSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BrandSetting extends Model
'favicon' => \System\Models\File::class,
'logo' => \System\Models\File::class
];

/**
* @var string The key to store rendered CSS in the cache under
*/
Expand Down Expand Up @@ -181,5 +181,4 @@ public static function getDefaultLogo()

return null;
}

}
Loading

0 comments on commit a59d3b8

Please sign in to comment.