diff --git a/.cache/.gitkeep b/.cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..26873f8 --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,85 @@ +name: PHP coding standards + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + # Runs the PHP coding standards checks. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up PHP. + # - Configures caching for PHPCS scans. + # - Installs Composer dependencies. + # - Make Composer packages available globally. + # - Runs PHPCS on the full codebase (warnings excluded). + # - Generate a report for displaying issues as pull request annotations. + # - Runs PHPCS on the `tests` directory without (warnings included). + # - Generate a report for displaying `test` directory issues as pull request annotations. + # - Ensures version-controlled files are not modified or deleted. + phpcs: + name: Run coding standards checks + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up PHP + uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1 + with: + coverage: none + tools: cs2pr + + # This date is used to ensure that the PHPCS cache is cleared at least once every week. + # http://man7.org/linux/man-pages/man1/date.1.html + - name: "Get last Monday's date" + id: get-date + run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT + + - name: Cache PHPCS scan cache + uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1 + with: + path: | + .cache/phpcs-src.json + .cache/phpcs-tests.json + key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php-version }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} + + - name: Install Composer dependencies + uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0 + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Run PHPCS on all files + id: phpcs-files + if: ${{ ! inputs.old-branch }} + run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml + + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs-files.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-report.xml + + - name: Check test suite files for warnings + id: phpcs-tests + run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml + + - name: Show test suite scan results in PR + if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-tests-report.xml + + - name: Ensure version-controlled files are not modified during the tests + run: git diff --exit-code diff --git a/.gitignore b/.gitignore index 88586c1..beb2775 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ /tests/cache /tests/coverage .DS_Store + +# Track placeholders so that empty directories stay in the repo. +!.gitkeep diff --git a/assets/css/aspire-update.css b/assets/css/aspire-update.css index 89be84f..c8d1825 100644 --- a/assets/css/aspire-update.css +++ b/assets/css/aspire-update.css @@ -1,63 +1,64 @@ -@keyframes glow { - 0% { - background-color: rgba(255, 223, 0, 0.1); - } - - 100% { - background-color: none; - } -} - -.glow-reveal { - animation: glow 0.5s ease-in-out; -} - -.aspireupdate-settings-field-hosts-wrapper .aspireupdate-settings-field-hosts-row { - margin: 0 0 10px; -} - -#aspireupdate-generate-api-key { - display: inline-block; - width: 30px; - height: 30px; - background: url(../images/icon-key.svg) no-repeat center center / 24px 24px; - background-color: #cbcbcb; - border: 1px solid #8c8f94; - border-radius: 3px; - clip-path: inset(0 0 0 0); - color: transparent; - cursor: pointer; - transition: background-color 0.3s ease; -} - -#aspireupdate-generate-api-key:hover { - background-color: #e3e3e3; -} - -.aspireupdate-settings-field-wrapper p.error { - color: #bc3b3b; - display: none; -} - -#voltron { - color: transparent; - font-size: 8px; - line-height: 6px; - display: inline-block; - cursor: default; -} - -#voltron:hover { - animation: blink 1.8s ease-in-out infinite; - animation-delay: 5s; -} - -@keyframes blink { - 0%, - 100% { - color: inherit; - } - 50% { - color: transparent; - } -} + +@keyframes glow { + 0% { + background-color: rgba(255, 223, 0, 0.1); + } + + 100% { + background-color: none; + } +} + +.glow-reveal { + animation: glow 0.5s ease-in-out; +} + +.aspireupdate-settings-field-hosts-wrapper .aspireupdate-settings-field-hosts-row { + margin: 0 0 10px; +} + +#aspireupdate-generate-api-key { + display: inline-block; + width: 30px; + height: 30px; + background: url(../images/icon-key.svg) no-repeat center center / 24px 24px; + background-color: #cbcbcb; + border: 1px solid #8c8f94; + border-radius: 3px; + clip-path: inset(0 0 0 0); + color: transparent; + cursor: pointer; + transition: background-color 0.3s ease; +} + +#aspireupdate-generate-api-key:hover { + background-color: #e3e3e3; +} + +.aspireupdate-settings-field-wrapper p.error { + color: #bc3b3b; + display: none; +} + +#voltron { + color: transparent; + font-size: 8px; + line-height: 6px; + display: inline-block; + cursor: default; +} + +#voltron:hover { + animation: blink 1.8s ease-in-out infinite; + animation-delay: 5s; +} + +@keyframes blink { + 0%, + 100% { + color: inherit; + } + 50% { + color: transparent; + } +} diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index fa9b96f..e9f9f42 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -1,239 +1,241 @@ -jQuery(document).ready(function () { - new ApiRewrites(); - new ApiDebug(); -}); - -class ApiRewrites { - constructor() { - ApiRewrites.host_selector.init(); - ApiRewrites.other_hosts.init(); - ApiRewrites.api_key.init(); - ApiRewrites.enabled_rewrites.init(); - } - - static enabled_rewrites = { - field: jQuery('#aspireupdate-settings-field-enable'), - sub_fields: [], - init() { - ApiRewrites.enabled_rewrites.sub_fields = [ - ApiRewrites.host_selector, - ApiRewrites.api_key - ]; - - ApiRewrites.enabled_rewrites.field.change(function () { - if (jQuery(this).is(':checked')) { - ApiRewrites.enabled_rewrites.show_options(); - } else { - ApiRewrites.enabled_rewrites.hide_options(); - } - }).change(); - }, - show_options() { - Fields.show(ApiRewrites.enabled_rewrites.sub_fields); - }, - hide_options() { - Fields.hide(ApiRewrites.enabled_rewrites.sub_fields); - } - } - - static host_selector = { - field: jQuery('#aspireupdate-settings-field-api_host'), - init() { - ApiRewrites.host_selector.field.change(function () { - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - if ('other' === selected_option.val()) { - ApiRewrites.other_hosts.show(); - } else { - ApiRewrites.other_hosts.hide(); - } - - if (ApiRewrites.host_selector.is_api_key_required()) { - ApiRewrites.api_key.make_required(); - } else { - ApiRewrites.api_key.remove_required(); - } - - if (ApiRewrites.host_selector.has_api_key_url()) { - ApiRewrites.api_key.show_action_button(); - } else { - ApiRewrites.api_key.hide_action_button(); - } - }).change(); - }, - is_api_key_required() { - let is_api_rewrites_enabled = jQuery('#aspireupdate-settings-field-enable').is(':checked'); - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - let require_api_key = selected_option.attr('data-require-api-key'); - if (is_api_rewrites_enabled && 'true' === require_api_key) { - return true; - } - return false; - }, - has_api_key_url() { - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - let api_url = selected_option.attr('data-api-key-url'); - if ('' !== api_url) { - return true; - } - return false; - }, - get_api_key_url() { - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - let api_url = selected_option.attr('data-api-key-url'); - if ('' !== api_url) { - return api_url; - } - return ''; - }, - } - - static other_hosts = { - field: jQuery('#aspireupdate-settings-field-api_host_other'), - init() { - ApiRewrites.other_hosts.field.on("blur", function () { - let value = ApiRewrites.other_hosts.field.val(); - value = ApiRewrites.other_hosts.strip_protocol(value); - value = ApiRewrites.other_hosts.strip_dangerous_characters(value); - ApiRewrites.other_hosts.field.val(value); - }); - }, - show() { - ApiRewrites.other_hosts.field.parent().show(); - ApiRewrites.other_hosts.field.focus(); - ApiRewrites.other_hosts.make_required(); - }, - hide() { - ApiRewrites.other_hosts.field.parent().hide(); - ApiRewrites.other_hosts.remove_required(); - }, - make_required() { - ApiRewrites.other_hosts.field.prop('required', true); - }, - remove_required() { - ApiRewrites.other_hosts.field.prop('required', false); - }, - strip_protocol(value) { - const protocol_regex = /^(https?|ftp|sftp|smtp|ftps|file):\/\/|^www\./i; - return value.replace(protocol_regex, ''); - }, - strip_dangerous_characters(value) { - const dangerous_characters_regex = /[<>/"'&;]/g; - return value.replace(dangerous_characters_regex, ''); - } - } - - static api_key = { - field: jQuery('#aspireupdate-settings-field-api_key'), - action_button: jQuery('#aspireupdate-generate-api-key'), - init() { - ApiRewrites.api_key.action_button.click(function () { - ApiRewrites.api_key.hide_error(); - ApiRewrites.api_key.get_api_key(); - }); - ApiRewrites.api_key.hide_error(); - }, - get_api_key() { - let parameters = { - "url": ApiRewrites.host_selector.get_api_key_url(), - "type": "POST", - "contentType": 'application/json', - "data": JSON.stringify({ - "domain": aspireupdate.domain - }) - }; - jQuery.ajax(parameters) - .done(function (response) { - ApiRewrites.api_key.field.val(response.apikey); - }) - .fail(function (response) { - if ((response.status === 400) || (response.status === 401)) { - ApiRewrites.api_key.show_error(response.responseJSON?.error); - } else { - ApiRewrites.api_key.show_error('Unexpected Error: ' + response.status); - } - }); - }, - show() { - ApiRewrites.api_key.field.parent().parent().parent().show(); - }, - hide() { - ApiRewrites.api_key.field.parent().parent().parent().hide(); - }, - show_action_button() { - ApiRewrites.api_key.action_button.show(); - }, - hide_action_button() { - ApiRewrites.api_key.action_button.hide(); - }, - make_required() { - ApiRewrites.api_key.field.prop('required', true); - }, - remove_required() { - ApiRewrites.api_key.field.prop('required', false); - }, - show_error(message) { - ApiRewrites.api_key.field.parent().find('.error').html(message).show(); - }, - hide_error() { - ApiRewrites.api_key.field.parent().find('.error').html('').hide(); - } - } -} - -class ApiDebug { - constructor() { - ApiDebug.enabled_debug.init(); - } - - static enabled_debug = { - field: jQuery('#aspireupdate-settings-field-enable_debug'), - sub_fields: [], - init() { - ApiDebug.enabled_debug.sub_fields = [ - ApiDebug.debug_type, - ApiDebug.disable_ssl_verification - ]; - - ApiDebug.enabled_debug.field.change(function () { - if (jQuery(this).is(':checked')) { - ApiDebug.enabled_debug.show_options(); - } else { - ApiDebug.enabled_debug.hide_options(); - } - }).change(); - }, - show_options() { - Fields.show(ApiDebug.enabled_debug.sub_fields); - }, - hide_options() { - Fields.hide(ApiDebug.enabled_debug.sub_fields); - } - } - - static debug_type = { - field: jQuery('.aspireupdate-settings-field-wrapper-enable_debug_type'), - } - - static disable_ssl_verification = { - field: jQuery('#aspireupdate-settings-field-disable_ssl_verification'), - } -} - -class Fields { - static show(sub_fields) { - jQuery.each(sub_fields, function (index, sub_field) { - sub_field.field.closest('tr').show().addClass('glow-reveal'); - sub_field.field.change(); - setTimeout(function () { - sub_field.field.closest('tr').removeClass('glow-reveal'); - }, 500); - }); - } - - static hide(sub_fields) { - jQuery.each(sub_fields, function (index, sub_field) { - sub_field.field.closest('tr').hide(); - sub_field.field.change(); - }); - } -} \ No newline at end of file + +jQuery(document).ready(function () { + new ApiRewrites(); + new ApiDebug(); +}); + +class ApiRewrites { + constructor() { + ApiRewrites.host_selector.init(); + ApiRewrites.other_hosts.init(); + ApiRewrites.api_key.init(); + ApiRewrites.enabled_rewrites.init(); + } + + static enabled_rewrites = { + field: jQuery('#aspireupdate-settings-field-enable'), + sub_fields: [], + init() { + ApiRewrites.enabled_rewrites.sub_fields = [ + ApiRewrites.host_selector, + ApiRewrites.api_key + ]; + + ApiRewrites.enabled_rewrites.field.change(function () { + if (jQuery(this).is(':checked')) { + ApiRewrites.enabled_rewrites.show_options(); + } else { + ApiRewrites.enabled_rewrites.hide_options(); + } + }).change(); + }, + show_options() { + Fields.show(ApiRewrites.enabled_rewrites.sub_fields); + }, + hide_options() { + Fields.hide(ApiRewrites.enabled_rewrites.sub_fields); + } + } + + static host_selector = { + field: jQuery('#aspireupdate-settings-field-api_host'), + init() { + ApiRewrites.host_selector.field.change(function () { + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + if ('other' === selected_option.val()) { + ApiRewrites.other_hosts.show(); + } else { + ApiRewrites.other_hosts.hide(); + } + + if (ApiRewrites.host_selector.is_api_key_required()) { + ApiRewrites.api_key.make_required(); + } else { + ApiRewrites.api_key.remove_required(); + } + + if (ApiRewrites.host_selector.has_api_key_url()) { + ApiRewrites.api_key.show_action_button(); + } else { + ApiRewrites.api_key.hide_action_button(); + } + }).change(); + }, + is_api_key_required() { + let is_api_rewrites_enabled = jQuery('#aspireupdate-settings-field-enable').is(':checked'); + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + let require_api_key = selected_option.attr('data-require-api-key'); + if (is_api_rewrites_enabled && 'true' === require_api_key) { + return true; + } + return false; + }, + has_api_key_url() { + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + let api_url = selected_option.attr('data-api-key-url'); + if ('' !== api_url) { + return true; + } + return false; + }, + get_api_key_url() { + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + let api_url = selected_option.attr('data-api-key-url'); + if ('' !== api_url) { + return api_url; + } + return ''; + }, + } + + static other_hosts = { + field: jQuery('#aspireupdate-settings-field-api_host_other'), + init() { + ApiRewrites.other_hosts.field.on("blur", function () { + let value = ApiRewrites.other_hosts.field.val(); + value = ApiRewrites.other_hosts.strip_protocol(value); + value = ApiRewrites.other_hosts.strip_dangerous_characters(value); + ApiRewrites.other_hosts.field.val(value); + }); + }, + show() { + ApiRewrites.other_hosts.field.parent().show(); + ApiRewrites.other_hosts.field.focus(); + ApiRewrites.other_hosts.make_required(); + }, + hide() { + ApiRewrites.other_hosts.field.parent().hide(); + ApiRewrites.other_hosts.remove_required(); + }, + make_required() { + ApiRewrites.other_hosts.field.prop('required', true); + }, + remove_required() { + ApiRewrites.other_hosts.field.prop('required', false); + }, + strip_protocol(value) { + const protocol_regex = /^(https?|ftp|sftp|smtp|ftps|file):\/\/|^www\./i; + return value.replace(protocol_regex, ''); + }, + strip_dangerous_characters(value) { + const dangerous_characters_regex = /[<>/"'&;]/g; + return value.replace(dangerous_characters_regex, ''); + } + } + + static api_key = { + field: jQuery('#aspireupdate-settings-field-api_key'), + action_button: jQuery('#aspireupdate-generate-api-key'), + init() { + ApiRewrites.api_key.action_button.click(function () { + ApiRewrites.api_key.hide_error(); + ApiRewrites.api_key.get_api_key(); + }); + ApiRewrites.api_key.hide_error(); + }, + get_api_key() { + let parameters = { + "url": ApiRewrites.host_selector.get_api_key_url(), + "type": "POST", + "contentType": 'application/json', + "data": JSON.stringify({ + "domain": aspireupdate.domain + }) + }; + jQuery.ajax(parameters) + .done(function (response) { + ApiRewrites.api_key.field.val(response.apikey); + }) + .fail(function (response) { + if ((response.status === 400) || (response.status === 401)) { + ApiRewrites.api_key.show_error(response.responseJSON?.error); + } else { + ApiRewrites.api_key.show_error('Unexpected Error: ' + response.status); + } + }); + }, + show() { + ApiRewrites.api_key.field.parent().parent().parent().show(); + }, + hide() { + ApiRewrites.api_key.field.parent().parent().parent().hide(); + }, + show_action_button() { + ApiRewrites.api_key.action_button.show(); + }, + hide_action_button() { + ApiRewrites.api_key.action_button.hide(); + }, + make_required() { + ApiRewrites.api_key.field.prop('required', true); + }, + remove_required() { + ApiRewrites.api_key.field.prop('required', false); + }, + show_error(message) { + ApiRewrites.api_key.field.parent().find('.error').html(message).show(); + }, + hide_error() { + ApiRewrites.api_key.field.parent().find('.error').html('').hide(); + } + } +} + +class ApiDebug { + constructor() { + ApiDebug.enabled_debug.init(); + } + + static enabled_debug = { + field: jQuery('#aspireupdate-settings-field-enable_debug'), + sub_fields: [], + init() { + ApiDebug.enabled_debug.sub_fields = [ + ApiDebug.debug_type, + ApiDebug.disable_ssl_verification + ]; + + ApiDebug.enabled_debug.field.change(function () { + if (jQuery(this).is(':checked')) { + ApiDebug.enabled_debug.show_options(); + } else { + ApiDebug.enabled_debug.hide_options(); + } + }).change(); + }, + show_options() { + Fields.show(ApiDebug.enabled_debug.sub_fields); + }, + hide_options() { + Fields.hide(ApiDebug.enabled_debug.sub_fields); + } + } + + static debug_type = { + field: jQuery('.aspireupdate-settings-field-wrapper-enable_debug_type'), + } + + static disable_ssl_verification = { + field: jQuery('#aspireupdate-settings-field-disable_ssl_verification'), + } +} + +class Fields { + static show(sub_fields) { + jQuery.each(sub_fields, function (index, sub_field) { + sub_field.field.closest('tr').show().addClass('glow-reveal'); + sub_field.field.change(); + setTimeout(function () { + sub_field.field.closest('tr').removeClass('glow-reveal'); + }, 500); + }); + } + + static hide(sub_fields) { + jQuery.each(sub_fields, function (index, sub_field) { + sub_field.field.closest('tr').hide(); + sub_field.field.change(); + }); + } +} + diff --git a/assets/playground/blueprint.json b/assets/playground/blueprint.json index 3b89a47..d9e8453 100644 --- a/assets/playground/blueprint.json +++ b/assets/playground/blueprint.json @@ -1,57 +1,57 @@ { - "$schema": "https://playground.wordpress.net/blueprint-schema.json", - "preferredVersions": { - "php": "latest", - "wp": "latest" - }, - "meta": { - "title": "AspirePress AspireUpdate Plugin Demo", - "description": "Load table AspireUpdate plugin into a WordPress Playground site", - "author": "asirota", - "categories": [ - "demo", - "plugin" - ] - }, - "siteOptions": { - "blogname": "AspireUpdate Demo Site" - }, - "plugins": [ - "https://github-proxy.com/proxy/?repo=AspirePress/AspireUpdate&branch=playground-ready", - "error-log-viewer", - "plugin-check" - ], - "features": { - "networking": true - }, - "login": true, - "landingPage": "/wp-admin/admin.php?page=aspireupdate-settings", - "steps": [ - { - "step": "defineWpConfigConsts", - "consts": { - "WP_DISABLE_FATAL_ERROR_HANDLER": false, - "WP_DEBUG": false, - "WP_DEBUG_LOG": false, - "WP_DEBUG_DISPLAY": true - } - }, - { - "step": "writeFile", - "path": "/wordpress/wp-content/mu-plugins/rewrite.php", - "data": "set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );" - }, - { - "step": "installTheme", - "themeData": { - "resource": "wordpress.org/themes", - "slug": "twentytwentytwo" - } - }, - { - "step": "writeFile", - "path": "/wordpress/wp-content/mu-plugins/bgnightly-notice.php", - "data": "
Welcome to AspireUpdate Demo. Visit AspirePress documentation for more details.
'; });" - } - ] + "$schema": "https://playground.wordpress.net/blueprint-schema.json", + "preferredVersions": { + "php": "latest", + "wp": "latest" + }, + "meta": { + "title": "AspirePress AspireUpdate Plugin Demo", + "description": "Load table AspireUpdate plugin into a WordPress Playground site", + "author": "asirota", + "categories": [ + "demo", + "plugin" + ] + }, + "siteOptions": { + "blogname": "AspireUpdate Demo Site" + }, + "plugins": [ + "https://github-proxy.com/proxy/?repo=AspirePress/AspireUpdate&branch=playground-ready", + "error-log-viewer", + "plugin-check" + ], + "features": { + "networking": true + }, + "login": true, + "landingPage": "/wp-admin/admin.php?page=aspireupdate-settings", + "steps": [ + { + "step": "defineWpConfigConsts", + "consts": { + "WP_DISABLE_FATAL_ERROR_HANDLER": false, + "WP_DEBUG": false, + "WP_DEBUG_LOG": false, + "WP_DEBUG_DISPLAY": true + } + }, + { + "step": "writeFile", + "path": "/wordpress/wp-content/mu-plugins/rewrite.php", + "data": "set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );" + }, + { + "step": "installTheme", + "themeData": { + "resource": "wordpress.org/themes", + "slug": "twentytwentytwo" + } + }, + { + "step": "writeFile", + "path": "/wordpress/wp-content/mu-plugins/bgnightly-notice.php", + "data": "Welcome to AspireUpdate Demo. Visit AspirePress documentation for more details.
'; });" + } + ] } diff --git a/composer.json b/composer.json index c5a7ae5..d2a49e5 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "name": "aspirepress/aspire-update", "description": "Update plugins and themes for WordPress.", "type": "wordpress-plugin", @@ -12,9 +13,21 @@ "php": ">=7.4.0" }, "require-dev": { + + "squizlabs/php_codesniffer": "3.10.3", + "wp-coding-standards/wpcs": "~3.1.0", "yoast/phpunit-polyfills": "^1.1.0" }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "scripts": { + "format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source", + "lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary, source", "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit" ] } + + } diff --git a/composer.lock b/composer.lock index e7dcd4e..0af7c9c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,10 +4,90 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0916844f3ac21ff922fe9b414c14d840", + + "content-hash": "ee8f3669b94f591108fa37dfcf3db475", "packages": [], "packages-dev": [ { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "doctrine/instantiator", "version": "1.5.0", "source": { @@ -314,6 +394,174 @@ "time": "2022-02-21T01:04:05+00:00" }, { + + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.12", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/87b233b00daf83fb70f40c9a28692be017ea7c6c", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.10.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-05-20T13:34:27+00:00" + }, + { + "name": "phpunit/php-code-coverage", "version": "9.2.32", "source": { @@ -1699,6 +1947,88 @@ "time": "2020-09-28T06:39:44+00:00" }, { + + "name": "squizlabs/php_codesniffer", + "version": "3.10.3", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "62d32998e820bddc40f99f8251958aed187a5c9c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/62d32998e820bddc40f99f8251958aed187a5c9c", + "reference": "62d32998e820bddc40f99f8251958aed187a5c9c", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-09-18T10:38:58+00:00" + }, + { + "name": "theseer/tokenizer", "version": "1.2.3", "source": { @@ -1749,6 +2079,74 @@ "time": "2024-03-03T12:36:25+00:00" }, { + + "name": "wp-coding-standards/wpcs", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.2.1", + "phpcsstandards/phpcsutils": "^1.0.10", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/php_codesniffer", + "type": "custom" + } + ], + "time": "2024-03-25T16:39:00+00:00" + }, + { + "name": "yoast/phpunit-polyfills", "version": "1.1.2", "source": { diff --git a/includes/autoload.php b/includes/autoload.php index ffbf35e..8cc0a3b 100644 --- a/includes/autoload.php +++ b/includes/autoload.php @@ -15,7 +15,7 @@ */ function aspire_update_autoloader( $class_name ) { if ( false !== strpos( $class_name, 'AspireUpdate\\' ) ) { - $class_name = strtolower( str_replace( array( 'AspireUpdate\\', '_' ), array( '', '-' ), $class_name ) ); + $class_name = strtolower( str_replace( [ 'AspireUpdate\\', '_' ], [ '', '-' ], $class_name ) ); $file = __DIR__ . DIRECTORY_SEPARATOR . 'class-' . $class_name . '.php'; if ( file_exists( $file ) ) { diff --git a/includes/class-admin-settings.php b/includes/class-admin-settings.php index 86c0a95..1105ad9 100644 --- a/includes/class-admin-settings.php +++ b/includes/class-admin-settings.php @@ -44,14 +44,16 @@ class Admin_Settings { * The Constructor. */ public function __construct() { - add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'register_admin_menu' ) ); - add_action( 'admin_init', array( $this, 'reset_settings' ) ); - add_action( 'admin_init', array( $this, 'register_settings' ) ); - add_action( 'admin_notices', array( $this, 'reset_admin_notice' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); - - add_action( 'admin_init', array( $this, 'update_settings' ) ); - add_action( 'network_admin_edit_aspireupdate-settings', array( $this, 'update_settings' ) ); + + add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'register_admin_menu' ] ); + add_action( 'admin_init', [ $this, 'reset_settings' ] ); + add_action( 'admin_init', [ $this, 'register_settings' ] ); + add_action( 'admin_notices', [ $this, 'reset_admin_notice' ] ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); + + add_action( 'admin_init', [ $this, 'update_settings' ] ); + add_action( 'network_admin_edit_aspireupdate-settings', [ $this, 'update_settings' ] ); + } /** @@ -72,7 +74,7 @@ public static function get_instance() { * @return array The default values. */ private function get_default_settings() { - $options = array(); + $options = []; $options['api_host'] = 'api.aspirecloud.org'; return $options; } @@ -95,10 +97,12 @@ public function reset_settings() { wp_safe_redirect( add_query_arg( - array( + [ 'reset-success' => 'success', 'reset-success-nonce' => wp_create_nonce( 'aspireupdate-reset-success-nonce' ), - ), + + ], + network_admin_url( 'index.php?page=aspireupdate-settings' ) ) ); @@ -161,7 +165,7 @@ public function get_setting( $setting_name, $default_value = false ) { } if ( isset( $options['enable_debug_type'] ) && is_array( $options['enable_debug_type'] ) ) { - $debug_types = array(); + $debug_types = []; foreach ( $options['enable_debug_type'] as $debug_type_name => $debug_type_enabled ) { if ( $debug_type_enabled ) { $debug_types[] = $debug_type_name; @@ -181,7 +185,7 @@ public function get_setting( $setting_name, $default_value = false ) { * @return array An array of values as defined in the Config File. */ private function get_settings_from_config_file() { - $options = array(); + $options = []; if ( ! defined( 'AP_ENABLE' ) ) { define( 'AP_ENABLE', false ); @@ -208,7 +212,7 @@ private function get_settings_from_config_file() { } if ( ! defined( 'AP_DEBUG_TYPES' ) ) { - define( 'AP_DEBUG_TYPES', array() ); + define( 'AP_DEBUG_TYPES', [] ); } elseif ( is_array( AP_DEBUG_TYPES ) ) { $options['enable_debug_type'] = AP_DEBUG_TYPES; } @@ -241,7 +245,9 @@ public function update_settings() { update_site_option( $this->option_name, $this->sanitize_settings( wp_unslash( $_POST['aspireupdate_settings'] ) ) ); wp_safe_redirect( - add_query_arg( array( network_admin_url( 'index.php?page=aspireupdate-settings' ) ) ) + + add_query_arg( [ network_admin_url( 'index.php?page=aspireupdate-settings' ) ] ) + ); exit; } @@ -263,7 +269,7 @@ public function register_admin_menu() { 'AspireUpdate', is_multisite() ? 'manage_network_options' : 'manage_options', 'aspireupdate-settings', - array( $this, 'the_settings_page' ) + [ $this, 'the_settings_page' ] ); } } @@ -275,19 +281,23 @@ public function register_admin_menu() { * @return void */ public function admin_enqueue_scripts( $hook ) { - if ( ! in_array( $hook, array( 'dashboard_page_aspireupdate-settings','index_page_aspireupdate-settings' ) ) ) { + + if ( ! in_array( $hook, [ 'dashboard_page_aspireupdate-settings', 'index_page_aspireupdate-settings' ], true ) ) { + return; } - wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', array(), AP_VERSION ); - wp_enqueue_script( 'aspire_update_settings_js', plugin_dir_url( __DIR__ ) . 'assets/js/aspire-update.js', array( 'jquery' ), AP_VERSION, true ); + wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', [], AP_VERSION ); + wp_enqueue_script( 'aspire_update_settings_js', plugin_dir_url( __DIR__ ) . 'assets/js/aspire-update.js', [ 'jquery' ], AP_VERSION, true ); wp_localize_script( 'aspire_update_settings_js', 'aspireupdate', - array( + + [ + 'ajax_url' => network_admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aspireupdate-ajax' ), 'domain' => Utilities::get_top_level_domain(), - ) + ] ); } @@ -298,10 +308,12 @@ public function admin_enqueue_scripts( $hook ) { */ public function the_settings_page() { $reset_url = add_query_arg( - array( + [ 'reset' => 'reset', 'reset-nonce' => wp_create_nonce( 'aspireupdate-reset-nonce' ), - ), + + ], + network_admin_url( 'index.php?page=aspireupdate-settings' ) ); ?> @@ -408,9 +420,9 @@ public function register_settings() { register_setting( $this->option_group, $this->option_name, - array( - 'sanitize_callback' => array( $this, 'sanitize_settings' ), - ) + [ + 'sanitize_callback' => [ $this, 'sanitize_settings' ], + ] ); add_settings_section( @@ -418,64 +430,64 @@ public function register_settings() { esc_html__( 'API Configuration', 'AspireUpdate' ), null, 'aspireupdate-settings', - array( + [ 'before_section' => '