diff --git a/.gitattributes b/.gitattributes index 1a7fadf6c9..4ae6ab295d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,3 +8,4 @@ .gitattributes export-ignore CHANGELOG.md export-ignore /package.json export-ignore +phpcs.xml export-ignore diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index 7d745ec75b..833b5fb59c 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -20,7 +20,7 @@ jobs: access_token: ${{ github.token }} - name: Checkout changes - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -29,7 +29,14 @@ jobs: with: php-version: 8.0 extensions: curl, fileinfo, gd, mbstring, openssl, pdo, pdo_sqlite, sqlite3, xml, zip - tools: phpcs + + - name: Install Composer dependencies + run: composer install --no-interaction --no-progress --no-scripts + + - name: Reset modules + run: | + git reset --hard + git clean -fd - name: Run code quality checks (on push) if: github.event_name == 'push' @@ -43,7 +50,7 @@ jobs: name: JavaScript steps: - name: Checkout changes - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/manifest.yml b/.github/workflows/manifest.yml index 72597a5329..1ad51ca43e 100644 --- a/.github/workflows/manifest.yml +++ b/.github/workflows/manifest.yml @@ -15,28 +15,8 @@ jobs: extensions: curl, fileinfo, gd, mbstring, openssl, pdo, pdo_sqlite, sqlite3, xml, zip key: winter-cms-cache-develop steps: - - name: Cancel previous incomplete runs - uses: styfle/cancel-workflow-action@0.8.0 - with: - access_token: ${{ github.token }} - - name: Checkout changes - uses: actions/checkout@v3 - - - name: Setup extension cache - id: extcache - uses: shivammathur/cache-extensions@v1 - with: - php-version: ${{ env.phpVersion }} - extensions: ${{ env.extensions }} - key: ${{ env.key }} - - - name: Cache extensions - uses: actions/cache@v3 - with: - path: ${{ steps.extcache.outputs.dir }} - key: ${{ steps.extcache.outputs.key }} - restore-keys: ${{ steps.extcache.outputs.key }} + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -44,17 +24,6 @@ jobs: php-version: ${{ env.phpVersion }} extensions: ${{ env.extensions }} - - name: Setup dependency cache - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Composer dependencies run: composer install --no-interaction --no-progress --no-scripts @@ -74,13 +43,8 @@ jobs: runs-on: ubuntu-latest needs: updateManifest steps: - - name: Cancel previous incomplete runs - uses: styfle/cancel-workflow-action@0.8.0 - with: - access_token: ${{ github.token }} - - name: Checkout changes - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: wintercms/meta ref: master diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e14444a88e..39fe990b9a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,6 +7,10 @@ on: - develop pull_request: +concurrency: + group: phpunit-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: frontendTests: strategy: @@ -28,22 +32,7 @@ jobs: access_token: ${{ github.token }} - name: Checkout changes - uses: actions/checkout@v3 - - - name: Setup extension cache - id: extcache - uses: shivammathur/cache-extensions@v1 - with: - php-version: ${{ env.phpVersion }} - extensions: ${{ env.extensions }} - key: ${{ env.key }} - - - name: Cache extensions - uses: actions/cache@v3 - with: - path: ${{ steps.extcache.outputs.dir }} - key: ${{ steps.extcache.outputs.key }} - restore-keys: ${{ steps.extcache.outputs.key }} + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -64,17 +53,6 @@ jobs: if: github.head_ref == '1.2' || github.ref == 'refs/heads/1.2' || github.base_ref == '1.2' run: php ./.github/workflows/utilities/library-switcher "1.2.x-dev as 1.2" - - name: Setup dependency cache - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Composer dependencies run: composer install --no-interaction --no-progress --no-scripts @@ -104,28 +82,8 @@ jobs: extensions: curl, fileinfo, gd, mbstring, openssl, pdo, pdo_sqlite, sqlite3, xml, zip key: winter-cms-cache-develop steps: - - name: Cancel previous incomplete runs - uses: styfle/cancel-workflow-action@0.8.0 - with: - access_token: ${{ github.token }} - - name: Checkout changes - uses: actions/checkout@v2 - - - name: Setup extension cache - id: extcache - uses: shivammathur/cache-extensions@v1 - with: - php-version: ${{ matrix.phpVersion }} - extensions: ${{ env.extensions }} - key: ${{ env.key }} - - - name: Cache extensions - uses: actions/cache@v2 - with: - path: ${{ steps.extcache.outputs.dir }} - key: ${{ steps.extcache.outputs.key }} - restore-keys: ${{ steps.extcache.outputs.key }} + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -149,17 +107,6 @@ jobs: if: github.head_ref == '1.2' || github.ref == 'refs/heads/1.2' || github.base_ref == '1.2' run: php ./.github/workflows/utilities/library-switcher "1.2.x-dev as 1.2" - - name: Setup dependency cache - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Composer dependencies run: composer install --no-interaction --no-progress --no-scripts diff --git a/.github/workflows/utilities/phpcs-pr b/.github/workflows/utilities/phpcs-pr index 231930c4f8..1446ffbf1d 100755 --- a/.github/workflows/utilities/phpcs-pr +++ b/.github/workflows/utilities/phpcs-pr @@ -30,7 +30,7 @@ if (!count($files)) { } // Run all changed files through the PHPCS code sniffer and generate a CSV report -$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files)); +$csv = shell_exec('./vendor/bin/phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files)); $lines = array_map(function ($row) { return array_map(function ($column) { return trim($column, '"'); diff --git a/.github/workflows/utilities/phpcs-push b/.github/workflows/utilities/phpcs-push index fe51c44c2b..475a4e3fc6 100755 --- a/.github/workflows/utilities/phpcs-push +++ b/.github/workflows/utilities/phpcs-push @@ -30,7 +30,7 @@ if (!count($files)) { } // Run all changed files through the PHPCS code sniffer and generate a CSV report -$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files)); +$csv = shell_exec('./vendor/bin/phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files)); $lines = array_map(function ($row) { return array_map(function ($column) { return trim($column, '"'); diff --git a/bootstrap/app.php b/bootstrap/app.php index 10e92d3cd6..3cb4279a7f 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -12,7 +12,7 @@ */ $app = new Winter\Storm\Foundation\Application( - realpath(__DIR__.'/../') + realpath(__DIR__ . '/../') ); /* diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 0b57e5e2f2..9e56cab1b6 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -13,10 +13,10 @@ | */ -$helperPath = __DIR__.'/../vendor/winter/storm/src/Support/helpers.php'; +$helperPath = __DIR__ . '/../vendor/winter/storm/src/Support/helpers.php'; if (!file_exists($helperPath)) { - echo 'Missing vendor files, try running "composer install" or use the Wizard installer.'.PHP_EOL; + echo 'Missing vendor files, try running "composer install" or use the Wizard installer.' . PHP_EOL; exit(1); } @@ -34,4 +34,4 @@ | */ -require __DIR__.'/../vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; diff --git a/composer.json b/composer.json index 8f4e849a5f..ba899b71fa 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "mockery/mockery": "^1.4.4", "fakerphp/faker": "^1.9.2", "squizlabs/php_codesniffer": "^3.2", + "slevomat/coding-standard": "^8.15.0", "php-parallel-lint/php-parallel-lint": "^1.0", "dms/phpunit-arraysubset-asserts": "^0.1.0|^0.2.1" }, @@ -56,13 +57,13 @@ "@php artisan package:discover" ], "test": [ - "phpunit --stop-on-failure" + "@php artisan test -- --stop-on-failure" ], "lint": [ "parallel-lint --exclude vendor --exclude storage --exclude modules/system/tests/fixtures/plugins/testvendor/goto/Plugin.php ." ], "sniff": [ - "phpcs --colors -nq --report=\"full\" --extensions=\"php\"" + "@php artisan sniff" ] }, "minimum-stability": "dev", @@ -81,7 +82,8 @@ "config": { "allow-plugins": { "composer/installers": true, - "wikimedia/composer-merge-plugin": true + "wikimedia/composer-merge-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/modules/backend/ServiceProvider.php b/modules/backend/ServiceProvider.php index 8d352d294d..2babd7cf74 100644 --- a/modules/backend/ServiceProvider.php +++ b/modules/backend/ServiceProvider.php @@ -1,4 +1,6 @@ - 'modules/backend/assets/images/dashboard-icon.svg', 'url' => Backend::url('backend'), 'permissions' => ['backend.access_dashboard'], - 'order' => 10 + 'order' => 10, ], 'media' => [ 'label' => 'backend::lang.media.menu_label', @@ -132,8 +134,8 @@ protected function registerBackendNavigation() 'iconSvg' => 'modules/backend/assets/images/media-icon.svg', 'url' => Backend::url('backend/media'), 'permissions' => ['media.*'], - 'order' => 200 - ] + 'order' => 200, + ], ]); $manager->registerOwnerAlias('Winter.Backend', 'October.Backend'); }); @@ -147,7 +149,7 @@ protected function registerBackendReportWidgets() WidgetManager::instance()->registerReportWidgets(function ($manager) { $manager->registerReportWidget(\Backend\ReportWidgets\Welcome::class, [ 'label' => 'backend::lang.dashboard.welcome.widget_title_default', - 'context' => 'dashboard' + 'context' => 'dashboard', ]); }); } @@ -277,7 +279,7 @@ protected function registerBackendSettings() 'class' => 'Backend\Models\BrandSetting', 'permissions' => ['backend.manage_branding'], 'order' => 500, - 'keywords' => 'brand style' + 'keywords' => 'brand style', ], 'editor' => [ 'label' => 'backend::lang.editor.menu_label', @@ -287,7 +289,7 @@ protected function registerBackendSettings() 'class' => 'Backend\Models\EditorSetting', 'permissions' => ['backend.manage_editor'], 'order' => 500, - 'keywords' => 'html code class style' + 'keywords' => 'html code class style', ], 'myaccount' => [ 'label' => 'backend::lang.myaccount.menu_label', @@ -297,7 +299,7 @@ protected function registerBackendSettings() 'url' => Backend::url('backend/users/myaccount'), 'order' => 500, 'context' => 'mysettings', - 'keywords' => 'backend::lang.myaccount.menu_keywords' + 'keywords' => 'backend::lang.myaccount.menu_keywords', ], 'preferences' => [ 'label' => 'backend::lang.backend_preferences.menu_label', @@ -307,7 +309,7 @@ protected function registerBackendSettings() 'url' => Backend::url('backend/preferences'), 'permissions' => ['backend.manage_preferences'], 'order' => 510, - 'context' => 'mysettings' + 'context' => 'mysettings', ], 'access_logs' => [ 'label' => 'backend::lang.access_log.menu_label', @@ -316,8 +318,8 @@ protected function registerBackendSettings() 'icon' => 'icon-lock', 'url' => Backend::url('backend/accesslogs'), 'permissions' => ['system.access_logs'], - 'order' => 920 - ] + 'order' => 920, + ], ]); $manager->registerOwnerAlias('Winter.Backend', 'October.Backend'); }); diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index ae58bb475f..645332cb62 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -1,16 +1,18 @@ -controller->formExtendModel($model) ?: $model; $this->initForm($model); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } } @@ -287,8 +288,7 @@ public function update($recordId = null, $context = null) $model = $this->controller->formFindModelObject($recordId); $this->initForm($model); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } } @@ -384,8 +384,7 @@ public function preview($recordId = null, $context = null) $model = $this->controller->formFindModelObject($recordId); $this->initForm($model); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } } @@ -451,7 +450,7 @@ public function formGetContext() protected function createModel() { $class = $this->config->modelClass; - return new $class; + return new $class(); } /** @@ -532,7 +531,7 @@ protected function getLang($name, $default = null, $extras = []) { $name = $this->getConfig($name, $default); $vars = [ - 'name' => Lang::get($this->getConfig('name', 'backend::lang.model.name')) + 'name' => Lang::get($this->getConfig('name', 'backend::lang.model.name')), ]; $vars = array_merge($vars, $extras); return Lang::get($name, $vars); @@ -779,7 +778,7 @@ public function formFindModelObject($recordId) if (!$result) { throw new ApplicationException($this->getLang('not-found-message', 'backend::lang.form.not_found', [ - 'class' => get_class($model), 'id' => $recordId + 'class' => get_class($model), 'id' => $recordId, ])); } diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index 057a0758a3..08532a3d4e 100644 --- a/modules/backend/behaviors/ImportExportController.php +++ b/modules/backend/behaviors/ImportExportController.php @@ -1,21 +1,23 @@ -vars['importResults'] = $model->getResultStats(); $this->vars['returnUrl'] = $this->getRedirectUrlForType('import'); - } - catch (MassAssignmentException $ex) { + } catch (MassAssignmentException $ex) { $this->controller->handleError(new ApplicationException(Lang::get( 'backend::lang.model.mass_assignment_failed', ['attribute' => $ex->getMessage()] ))); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } @@ -228,8 +228,7 @@ public function onImportLoadForm() { try { $this->checkRequiredImportColumns(); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } @@ -329,7 +328,7 @@ protected function getImportFileColumns() if (!post('first_row_titles')) { array_walk($firstRow, function (&$value, $key) { - $value = 'Column #'.($key + 1); + $value = 'Column #' . ($key + 1); }); } @@ -421,7 +420,7 @@ protected function checkRequiredImportColumns() if (!$found) { throw new ApplicationException(Lang::get('backend::lang.import_export.required_match_column_error', [ - 'label' => Lang::get($label) + 'label' => Lang::get($label), ])); } } @@ -447,19 +446,17 @@ public function onExport() $reference = $model->export($columns, $exportOptions); $fileUrl = $this->controller->actionUrl( 'download', - $reference.'/'.$this->exportFileName + $reference . '/' . $this->exportFileName ); $this->vars['fileUrl'] = $fileUrl; $this->vars['returnUrl'] = $this->getRedirectUrlForType('export'); - } - catch (MassAssignmentException $ex) { + } catch (MassAssignmentException $ex) { $this->controller->handleError(new ApplicationException(Lang::get( 'backend::lang.model.mass_assignment_failed', ['attribute' => $ex->getMessage()] ))); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } @@ -583,8 +580,7 @@ protected function checkUseListExportMode() if (is_array($useList)) { $listDefinition = array_get($useList, 'definition'); - } - else { + } else { $listDefinition = $useList; } @@ -620,7 +616,7 @@ public function exportFromList($definition = null, $options = []) /* * Prepare CSV */ - $csv = CsvWriter::createFromFileObject(new SplTempFileObject); + $csv = CsvWriter::createFromFileObject(new SplTempFileObject()); $csv->setOutputBOM(CsvWriter::BOM_UTF8); $csv->setDelimiter($options['delimiter']); $csv->setEnclosure($options['enclosure']); @@ -687,7 +683,7 @@ public function exportFromList($definition = null, $options = []) */ public function importExportMakePartial($partial, $params = []) { - $contents = $this->controller->makePartial('import_export_'.$partial, $params + $this->vars, false); + $contents = $this->controller->makePartial('import_export_' . $partial, $params + $this->vars, false); if (!$contents) { $contents = $this->makePartial($partial, $params); @@ -704,7 +700,7 @@ public function importExportMakePartial($partial, $params = []) protected function checkPermissionsForType($type) { if ( - ($permissions = $this->getConfig($type.'[permissions]')) && + ($permissions = $this->getConfig($type . '[permissions]')) && (!BackendAuth::getUser()->hasAnyAccess((array) $permissions)) ) { return Response::make(View::make('backend::access_denied'), 403); @@ -717,11 +713,11 @@ protected function makeOptionsFormWidgetForType($type) return null; } - if ($fieldConfig = $this->getConfig($type.'[form]')) { + if ($fieldConfig = $this->getConfig($type . '[form]')) { $widgetConfig = $this->makeConfig($fieldConfig); $widgetConfig->model = $this->getModelForType($type); - $widgetConfig->alias = $type.'OptionsForm'; - $widgetConfig->arrayName = ucfirst($type).'Options'; + $widgetConfig->alias = $type . 'OptionsForm'; + $widgetConfig->arrayName = ucfirst($type) . 'Options'; return $this->makeWidget('Backend\Widgets\Form', $widgetConfig); } @@ -731,20 +727,20 @@ protected function makeOptionsFormWidgetForType($type) protected function getModelForType($type) { - $cacheProperty = $type.'Model'; + $cacheProperty = $type . 'Model'; if ($this->{$cacheProperty} !== null) { return $this->{$cacheProperty}; } - $modelClass = $this->getConfig($type.'[modelClass]'); + $modelClass = $this->getConfig($type . '[modelClass]'); if (!$modelClass) { throw new ApplicationException(Lang::get('backend::lang.import_export.missing_model_class_error', [ - 'type' => $type + 'type' => $type, ])); } - return $this->{$cacheProperty} = new $modelClass; + return $this->{$cacheProperty} = new $modelClass(); } protected function makeListColumns($config) @@ -759,8 +755,7 @@ protected function makeListColumns($config) foreach ($config->columns as $attribute => $column) { if (is_array($column)) { $result[$attribute] = array_get($column, 'label', $attribute); - } - else { + } else { $result[$attribute] = $column ?: $attribute; } } @@ -770,7 +765,7 @@ protected function makeListColumns($config) protected function getRedirectUrlForType($type) { - $redirect = $this->getConfig($type.'[redirect]'); + $redirect = $this->getConfig($type . '[redirect]'); if ($redirect !== null) { return $redirect ? Backend::url($redirect) : 'javascript:;'; diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index d9b25f712a..38fe0badaa 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -1,10 +1,12 @@ -listDefinitions = $config; $this->primaryDefinition = key($this->listDefinitions); - } - else { + } else { $this->listDefinitions = ['list' => $config]; $this->primaryDefinition = 'list'; } @@ -124,7 +125,7 @@ public function makeList($definition = null) * Create the model */ $class = $listConfig->modelClass; - $model = new $class; + $model = new $class(); $model = $this->controller->listExtendModel($model, $definition); /* @@ -325,7 +326,7 @@ public function index_onDelete() * Create the model */ $class = $listConfig->modelClass; - $model = new $class; + $model = new $class(); $model = $this->controller->listExtendModel($model, $definition); /* @@ -352,8 +353,7 @@ public function index_onDelete() ? $listConfig->deleteMessage : 'backend::lang.list.delete_selected_success' )); - } - else { + } else { Flash::error(Lang::get( (!empty($listConfig->noRecordsDeletedMessage)) ? $listConfig->noRecordsDeletedMessage @@ -407,7 +407,7 @@ public function listRender($definition = null) */ public function listMakePartial($partial, $params = []) { - $contents = $this->controller->makePartial('list_'.$partial, $params + $this->vars, false); + $contents = $this->controller->makePartial('list_' . $partial, $params + $this->vars, false); if (!$contents) { $contents = $this->makePartial($partial, $params); } diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 3f8346df4e..c64a38f0a3 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1,12 +1,14 @@ -validateField($field); - $result = ['#'.$this->relationGetId('view') => $this->relationRenderView($field)]; + $result = ['#' . $this->relationGetId('view') => $this->relationRenderView($field)]; if ($toolbar = $this->relationRenderToolbar($field)) { - $result['#'.$this->relationGetId('toolbar')] = $toolbar; + $result['#' . $this->relationGetId('toolbar')] = $toolbar; } if ($eventResult = $this->controller->relationExtendRefreshResults($field)) { @@ -515,7 +517,7 @@ public function relationRenderView($field = null) */ public function relationMakePartial($partial, $params = []) { - $contents = $this->controller->makePartial('relation_'.$partial, $params + $this->vars, false); + $contents = $this->controller->makePartial('relation_' . $partial, $params + $this->vars, false); if (!$contents) { $contents = $this->makePartial($partial, $params); } @@ -614,7 +616,7 @@ protected function makeToolbarWidget() if ($useSearch) { $toolbarConfig->search = [ - 'prompt' => 'backend::lang.list.search_prompt' + 'prompt' => 'backend::lang.list.search_prompt', ]; } @@ -658,10 +660,10 @@ protected function makeViewWidget() { $widget = null; - /* - * Multiple (has many, belongs to many) - */ if ($this->viewMode === 'multi') { + /* + * Multiple (has many, belongs to many) + */ $config = $this->makeConfigForMode('view', 'list'); $config->model = $this->relationModel; $config->alias = $this->alias . 'ViewList'; @@ -684,8 +686,7 @@ protected function makeViewWidget() if ($config->recordUrl) { $defaultOnClick = null; - } - elseif ( + } elseif ( !$this->makeConfigForMode('manage', 'form', false) && !$this->makeConfigForMode('pivot', 'form', false) ) { @@ -707,13 +708,11 @@ protected function makeViewWidget() $widget->bindEvent('list.extendQueryBefore', function ($query) use ($sqlConditions) { $query->whereRaw($sqlConditions); }); - } - elseif ($scopeMethod = $this->getConfig('view[scope]')) { + } elseif ($scopeMethod = $this->getConfig('view[scope]')) { $widget->bindEvent('list.extendQueryBefore', function ($query) use ($scopeMethod) { $query->$scopeMethod($this->model); }); - } - else { + } else { $widget->bindEvent('list.extendQueryBefore', function ($query) use ($widget) { $this->relationObject->addDefinedConstraintsToQuery($query); if ($widget->getSortColumn()) { @@ -732,15 +731,15 @@ protected function makeViewWidget() if ($sessionKey) { $this->relationObject->withDeferred($sessionKey); - } - elseif ($this->model->exists) { + } elseif ($this->model->exists) { $this->relationObject->addConstraints(); } /* * Allows pivot data to enter the fray */ - if ($this->relationType === 'belongsToMany' + if ( + $this->relationType === 'belongsToMany' || $this->relationType === 'morphToMany' || $this->relationType === 'morphedByMany' ) { @@ -752,7 +751,8 @@ protected function makeViewWidget() /* * Constrain the list by the search widget, if available */ - if ($this->toolbarWidget && $this->getConfig('view[showSearch]') + if ( + $this->toolbarWidget && $this->getConfig('view[showSearch]') && $searchWidget = $this->toolbarWidget->getSearchWidget() ) { $searchWidget->bindEvent('search.submit', function () use ($widget, $searchWidget) { @@ -765,8 +765,7 @@ protected function makeViewWidget() */ if (Request::ajax()) { $widget->setSearchTerm($searchWidget->getActiveTerm()); - } - else { + } else { $searchWidget->setActiveTerm(null); } } @@ -782,11 +781,10 @@ protected function makeViewWidget() // Apply predefined filter values $widget->addFilter([$this->viewFilterWidget, 'applyAllScopesToQuery']); } - } - /* - * Single (belongs to, has one) - */ - elseif ($this->viewMode === 'single') { + } elseif ($this->viewMode === 'single') { + /* + * Single (belongs to, has one) + */ $this->viewModel = $this->relationObject->getResults() ?: $this->relationModel; @@ -807,9 +805,6 @@ protected function makeManageWidget() { $widget = null; - /* - * List / Pivot - */ if ($this->manageMode === 'list' || $this->manageMode === 'pivot') { $isPivot = $this->manageMode === 'pivot'; @@ -832,11 +827,9 @@ protected function makeManageWidget() $this->relationGetId(), $this->relationGetSessionKey() ); - } - elseif ($config->showCheckboxes) { + } elseif ($config->showCheckboxes) { $config->recordOnClick = "$.wn.relationBehavior.toggleListCheckbox(this)"; - } - elseif ($isPivot) { + } elseif ($isPivot) { $config->recordOnClick = sprintf( "$.wn.relationBehavior.clickManagePivotListRecord(':%s', '%s', '%s')", $this->relationModel->getKeyName(), @@ -854,13 +847,11 @@ protected function makeManageWidget() $widget->bindEvent('list.extendQueryBefore', function ($query) use ($sqlConditions) { $query->whereRaw($sqlConditions); }); - } - elseif ($scopeMethod = $this->getConfig('manage[scope]')) { + } elseif ($scopeMethod = $this->getConfig('manage[scope]')) { $widget->bindEvent('list.extendQueryBefore', function ($query) use ($scopeMethod) { $query->$scopeMethod($this->model); }); - } - else { + } else { $widget->bindEvent('list.extendQueryBefore', function ($query) use ($widget) { $this->relationObject->addDefinedConstraintsToQuery($query); if ($widget->getSortColumn()) { @@ -897,11 +888,7 @@ protected function makeManageWidget() // Apply predefined filter values $widget->addFilter([$this->manageFilterWidget, 'applyAllScopesToQuery']); } - } - /* - * Form - */ - elseif ($this->manageMode === 'form') { + } elseif ($this->manageMode === 'form') { if (!$config = $this->makeConfigForMode('manage', 'form', false)) { return null; } @@ -975,11 +962,10 @@ protected function makePivotWidget() 'id' => $this->manageId, ])); } - } - /* - * New record - */ - else { + } else { + /* + * New record + */ if ($this->foreignId) { $foreignModel = $this->relationModel ->whereIn($foreignKeyName, (array) $this->foreignId) @@ -1195,8 +1181,7 @@ public function onRelationManageUpdate() foreach ($modelsToSave as $modelToSave) { $modelToSave->save(null, $this->manageWidget->getSessionKey()); } - } - elseif ($this->viewMode === 'single') { + } elseif ($this->viewMode === 'single') { // Ensure that the view widget model is the same instance as the manage widget model // since they will technically be different object instances in this context as // $viewWidet->model is populated by $this->relationObject->getResults() and @@ -1217,10 +1202,10 @@ public function onRelationManageDelete() { $this->beforeAjax(); - /* - * Multiple (has many, belongs to many) - */ if ($this->viewMode === 'multi') { + /* + * Multiple (has many, belongs to many) + */ if (($checkedIds = post('checked')) && is_array($checkedIds)) { foreach ($checkedIds as $relationId) { if (!$obj = $this->relationModel->find($relationId)) { @@ -1230,11 +1215,10 @@ public function onRelationManageDelete() $obj->delete(); } } - } - /* - * Single (belongs to, has one) - */ - elseif ($this->viewMode === 'single') { + } elseif ($this->viewMode === 'single') { + /* + * Single (belongs to, has one) + */ $relatedModel = $this->viewModel; if ($relatedModel->exists) { $relatedModel->delete(); @@ -1260,10 +1244,10 @@ public function onRelationManageAdd() $recordId = post('record_id'); $sessionKey = $this->deferredBinding ? $this->relationGetSessionKey() : null; - /* - * Add - */ if ($this->viewMode === 'multi') { + /* + * Add + */ $checkedIds = $recordId ? [$recordId] : post('checked'); if (is_array($checkedIds)) { @@ -1279,11 +1263,10 @@ public function onRelationManageAdd() $this->relationObject->add($model, $sessionKey); } } - } - /* - * Link - */ - elseif ($this->viewMode === 'single') { + } elseif ($this->viewMode === 'single') { + /* + * Link + */ if ($recordId && ($model = $this->relationModel->find($recordId))) { if ($this->relationType === 'hasOne') { // Unassign previous relation if one is already assigned @@ -1324,10 +1307,10 @@ public function onRelationManageRemove() $sessionKey = $this->deferredBinding ? $this->relationGetSessionKey() : null; $relatedModel = $this->relationModel; - /* - * Remove - */ if ($this->viewMode === 'multi') { + /* + * Remove + */ $checkedIds = $recordId ? [$recordId] : post('checked'); if (is_array($checkedIds)) { @@ -1338,11 +1321,10 @@ public function onRelationManageRemove() $this->relationObject->remove($model, $sessionKey); } } - } - /* - * Unlink - */ - elseif ($this->viewMode === 'single') { + } elseif ($this->viewMode === 'single') { + /* + * Unlink + */ if ($this->relationType === 'belongsTo') { $this->relationObject->dissociate(); $this->relationObject->getParent()->save(); @@ -1352,12 +1334,10 @@ public function onRelationManageRemove() $this->model->refresh(); $this->initRelation($this->model); } - } - elseif ($this->relationType === 'hasOne' || $this->relationType === 'morphOne') { + } elseif ($this->relationType === 'hasOne' || $this->relationType === 'morphOne') { if ($obj = $relatedModel->find($recordId)) { $this->relationObject->remove($obj, $sessionKey); - } - elseif ($this->viewModel->exists) { + } elseif ($this->viewModel->exists) { $this->relationObject->remove($this->viewModel, $sessionKey); } } @@ -1419,7 +1399,7 @@ public function onRelationManagePivotCreate() } }); - return ['#'.$this->relationGetId('view') => $this->relationRenderView()]; + return ['#' . $this->relationGetId('view') => $this->relationRenderView()]; } public function onRelationManagePivotUpdate() @@ -1435,7 +1415,7 @@ public function onRelationManagePivotUpdate() $modelToSave->save(null, $this->pivotWidget->getSessionKey()); } - return ['#'.$this->relationGetId('view') => $this->relationRenderView()]; + return ['#' . $this->relationGetId('view') => $this->relationRenderView()]; } // @@ -1722,11 +1702,9 @@ protected function evalManageMode() case 'belongsToMany': if (isset($this->config->pivot)) { return 'pivot'; - } - elseif ($this->eventTarget === 'list') { + } elseif ($this->eventTarget === 'list') { return 'form'; - } - else { + } else { return 'list'; } @@ -1799,19 +1777,12 @@ protected function makeConfigForMode($mode = 'view', $type = 'list', $throwExcep { $config = null; - /* - * Look for $this->config->view['list'] - */ if ( isset($this->config->{$mode}) && array_key_exists($type, $this->config->{$mode}) ) { $config = $this->config->{$mode}[$type]; - } - /* - * Look for $this->config->list - */ - elseif (isset($this->config->{$type})) { + } elseif (isset($this->config->{$type})) { $config = $this->config->{$type}; } @@ -1826,7 +1797,7 @@ protected function makeConfigForMode($mode = 'view', $type = 'list', $throwExcep } if ($throwException) { - throw new ApplicationException('Missing configuration for '.$mode.'.'.$type.' in RelationController definition '.$this->field); + throw new ApplicationException('Missing configuration for ' . $mode . '.' . $type . ' in RelationController definition ' . $this->field); } return false; diff --git a/modules/backend/behaviors/ReorderController.php b/modules/backend/behaviors/ReorderController.php index 20cd3460ff..8e2a313317 100644 --- a/modules/backend/behaviors/ReorderController.php +++ b/modules/backend/behaviors/ReorderController.php @@ -1,9 +1,11 @@ -validateModel(); - /* - * Simple - */ if ($this->sortMode == 'simple') { if ( (!$ids = post('record_ids')) || @@ -128,11 +127,7 @@ public function onReorder() } $model->setSortableOrder($ids, $orders); - } - /* - * Nested set - */ - elseif ($this->sortMode == 'nested') { + } elseif ($this->sortMode == 'nested') { $sourceNode = $model->find(post('sourceNode')); $targetNode = post('targetNode') ? $model->find(post('targetNode')) : null; @@ -193,7 +188,7 @@ public function reorderGetModel() throw new ApplicationException('Please specify the modelClass property for reordering'); } - return $this->model = new $modelClass; + return $this->model = new $modelClass(); } /** @@ -221,15 +216,13 @@ protected function validateModel() $model->isClassExtendedWith(\October\Rain\Database\Behaviors\Sortable::class) ) { $this->sortMode = 'simple'; - } - elseif ( + } elseif ( isset($modelTraits[\Winter\Storm\Database\Traits\NestedTree::class]) || isset($modelTraits[\October\Rain\Database\Traits\NestedTree::class]) ) { $this->sortMode = 'nested'; $this->showTree = true; - } - else { + } else { throw new ApplicationException('The model must implement the Sortable trait/behavior or the NestedTree trait.'); } @@ -253,8 +246,7 @@ protected function getRecords() ->orderBy($model->getSortOrderColumn()) ->get() ; - } - elseif ($this->sortMode == 'nested') { + } elseif ($this->sortMode == 'nested') { $records = $query->getNested(); } @@ -280,8 +272,7 @@ protected function makeToolbarWidget() if ($toolbarConfig = $this->getConfig('toolbar')) { $toolbarConfig = $this->makeConfig($toolbarConfig); $toolbarWidget = $this->makeWidget('Backend\Widgets\Toolbar', $toolbarConfig); - } - else { + } else { $toolbarWidget = null; } diff --git a/modules/backend/behaviors/UserPreferencesModel.php b/modules/backend/behaviors/UserPreferencesModel.php index 52e2cd7575..c285b9bbd6 100644 --- a/modules/backend/behaviors/UserPreferencesModel.php +++ b/modules/backend/behaviors/UserPreferencesModel.php @@ -1,7 +1,9 @@ -userContext ? $item->userContext->id : 0; - return $this->recordCode.'-userpreference-'.$userId; + return $this->recordCode . '-userpreference-' . $userId; } } diff --git a/modules/backend/behaviors/importexportcontroller/TranscodeFilter.php b/modules/backend/behaviors/importexportcontroller/TranscodeFilter.php index bc683d600f..d25ff53916 100644 --- a/modules/backend/behaviors/importexportcontroller/TranscodeFilter.php +++ b/modules/backend/behaviors/importexportcontroller/TranscodeFilter.php @@ -1,8 +1,12 @@ -" /> diff --git a/modules/backend/behaviors/relationcontroller/partials/_manage_form.php b/modules/backend/behaviors/relationcontroller/partials/_manage_form.php index cab9fec785..58e4144780 100644 --- a/modules/backend/behaviors/relationcontroller/partials/_manage_form.php +++ b/modules/backend/behaviors/relationcontroller/partials/_manage_form.php @@ -35,7 +35,7 @@ true, 'data-request-success' => "$.wn.relationBehavior.changed('" . e($relationField) . "', 'created')", - 'sessionKey' => $newSessionKey + 'sessionKey' => $newSessionKey, ]) ?> diff --git a/modules/backend/behaviors/relationcontroller/partials/_manage_list.php b/modules/backend/behaviors/relationcontroller/partials/_manage_list.php index f3664c9906..56bb03d7c6 100644 --- a/modules/backend/behaviors/relationcontroller/partials/_manage_list.php +++ b/modules/backend/behaviors/relationcontroller/partials/_manage_list.php @@ -3,7 +3,7 @@ diff --git a/modules/backend/behaviors/relationcontroller/partials/_manage_pivot.php b/modules/backend/behaviors/relationcontroller/partials/_manage_pivot.php index 6ac2419bfc..c08647d911 100644 --- a/modules/backend/behaviors/relationcontroller/partials/_manage_pivot.php +++ b/modules/backend/behaviors/relationcontroller/partials/_manage_pivot.php @@ -2,7 +2,7 @@