From 8501d180c8a4832a7af63da63f5a06075651b7ee Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 28 Feb 2024 10:52:02 -0700 Subject: [PATCH 1/4] - scaffold tests from the codebase in the core WPGraphQL repo --- tests/unit/specs/GraphiQLToolbar.test.js | 17 +++++++++++++++++ tests/unit/specs/Help.test.js | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/unit/specs/GraphiQLToolbar.test.js create mode 100644 tests/unit/specs/Help.test.js diff --git a/tests/unit/specs/GraphiQLToolbar.test.js b/tests/unit/specs/GraphiQLToolbar.test.js new file mode 100644 index 0000000..34a7d60 --- /dev/null +++ b/tests/unit/specs/GraphiQLToolbar.test.js @@ -0,0 +1,17 @@ +/** + * @todo should this test live near the component it is testing? + * + * related: https://github.com/wp-graphql/wpgraphql-ide/issues/31 + */ +describe('GraphiQL Toolbar', () => { + + test('it should render', () => {}) + test.skip('it should render with prettify button', () => {}) + + test.skip('filter to add button as the first toolbar button', () => {}) + test.skip('filter to add button as the last toolbar button', () => {}) + test.skip('filter to add button after the prettify button', () => {}) + test.skip('filter to remove prettify button', () => {}) + test.skip('filter remove all buttons except a custom button', () => {}) + +}) diff --git a/tests/unit/specs/Help.test.js b/tests/unit/specs/Help.test.js new file mode 100644 index 0000000..a438024 --- /dev/null +++ b/tests/unit/specs/Help.test.js @@ -0,0 +1,11 @@ +/** + * @todo should this test live near the component it is testing? + */ +describe('GraphiQL Help Screen', () => { + + test('it should render', () => {}) + test.skip( 'absolute links should have target="_blank"', () => {}) + test.skip( 'each card should have a title', () => {}) + test.skip( 'each card should have an action', () => {}) + +}) From c57c8014539ceb058338589f57dde1181d965117 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 28 Feb 2024 15:20:52 -0700 Subject: [PATCH 2/4] - adds composer dev dependencies and scripts for phpcs and phpcbf - adds phpcs.xml.dist from wp-graphql with changes per existing files in this plugin - updates plugin header - updates formatting to be phpcs compliant - adds tests/_output directory for caching output of test and scripts like phpcs - updates composer.lock file - adds github workflow to check the code standards when PRs are opened --- .../workflows/wordpress-coding-standards.yml | 44 + composer.json | 50 +- composer.lock | 846 ++++++++++++++++++ phpcs.xml.dist | 182 ++++ tests/_output/.gitkeep | 0 wpgraphql-ide.php | 253 +++--- 6 files changed, 1231 insertions(+), 144 deletions(-) create mode 100644 .github/workflows/wordpress-coding-standards.yml create mode 100644 composer.lock create mode 100644 phpcs.xml.dist create mode 100644 tests/_output/.gitkeep diff --git a/.github/workflows/wordpress-coding-standards.yml b/.github/workflows/wordpress-coding-standards.yml new file mode 100644 index 0000000..4329468 --- /dev/null +++ b/.github/workflows/wordpress-coding-standards.yml @@ -0,0 +1,44 @@ +name: WordPress Coding Standards + +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master + +jobs: + run: + runs-on: ubuntu-latest + name: PHPCS + strategy: + matrix: + php: [ 8.1 ] + + steps: + - name: Cancel previous runs of this workflow (pull requests only) + if: ${{ github.event_name == 'pull_request' }} + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: ramsey/composer-install@v2 + with: + composer-options: "--no-progress" + + - name: Run PHPCS + run: composer run-script check-cs diff --git a/composer.json b/composer.json index 4199bfe..e300f66 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,38 @@ { - "name": "josephfusco/wpgraphql-ide", - "description": "A next-gen query editor for WPGraphQL.", - "type": "wordpress-plugin", - "license": "GPL-3.0-or-later", - "authors": [ - { - "name": "Joseph Fusco", - "homepage": "https://github.com/josephfusco", - "role": "Developer" - } - ], - "require": { - "php": "^8.0" - } + "name": "josephfusco/wpgraphql-ide", + "description": "A next-gen query editor for WPGraphQL.", + "type": "wordpress-plugin", + "license": "GPL-3.0-or-later", + "authors": [ + { + "name": "Joseph Fusco", + "homepage": "https://github.com/josephfusco", + "role": "Developer" + } + ], + "require": { + "php": "^8.0" + }, + "require-dev": { + "automattic/vipwpcs": "^3.0", + "slevomat/coding-standard": "^8.9", + "phpcompatibility/phpcompatibility-wp": "^2.1", + "phpcompatibility/php-compatibility": "dev-develop as 9.9.9" + }, + "scripts": { + "phpcs-i": [ + "php ./vendor/bin/phpcs -i" + ], + "check-cs": [ + "php ./vendor/bin/phpcs" + ], + "fix-cs": [ + "php ./vendor/bin/phpcbf" + ] + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..f0746fe --- /dev/null +++ b/composer.lock @@ -0,0 +1,846 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "b02980443416834f4ee65874f4fd3321", + "packages": [], + "packages-dev": [ + { + "name": "automattic/vipwpcs", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/VIP-Coding-Standards.git", + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "sirbrillig/phpcs-variable-analysis": "^2.11.17", + "squizlabs/php_codesniffer": "^3.7.2", + "wp-coding-standards/wpcs": "^3.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", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4 || ^5 || ^6 || ^7" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/Automattic/VIP-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues", + "source": "https://github.com/Automattic/VIP-Coding-Standards", + "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" + }, + "time": "2023-09-05T11:01:05+00:00" + }, + { + "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": "phpcompatibility/php-compatibility", + "version": "dev-develop", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "e5cd2e244097fb62c5ac8f1153a26a73c3a50438" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/e5cd2e244097fb62c5ac8f1153a26a73c3a50438", + "reference": "e5cd2e244097fb62c5ac8f1153a26a73c3a50438", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "replace": { + "wimg/php-compatibility": "*" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.3", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4 || ^10.1.0", + "yoast/phpunit-polyfills": "^1.0.5 || ^2.0.0" + }, + "suggest": { + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "default-branch": true, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev", + "dev-develop": "10.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibility/security/policy", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-02-12T16:57:44+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "time": "2022-10-25T01:46:02+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2022-10-24T09:00:36+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.9", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "908247bc65010c7b7541a9551e002db12e9dae70" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/908247bc65010c7b7541a9551e002db12e9dae70", + "reference": "908247bc65010c7b7541a9551e002db12e9dae70", + "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.8.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": "2023-12-08T14:50:00+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.26.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/231e3186624c03d7e7c890ec662b81e6b0405227", + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.26.0" + }, + "time": "2024-02-23T16:05:55+00:00" + }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.11.17", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/3b71162a6bf0cde2bff1752e40a1788d8273d049", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpcsstandards/phpcsdevcs": "^1.1", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "sirbrillig/phpcs-import-detection": "^1.1", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2023-08-05T23:46:11+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "8.14.1", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/fea1fd6f137cc84f9cba0ae30d549615dbc6a926", + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.23.1", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.37", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.14", + "phpstan/phpstan-strict-rules": "1.5.1", + "phpunit/phpunit": "8.5.21|9.6.8|10.3.5" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.14.1" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2023-10-08T07:28:08+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.9.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "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-02-16T15:06:51+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" + }, + "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" + }, + "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/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" + } + ], + "aliases": [ + { + "package": "phpcompatibility/php-compatibility", + "version": "dev-develop", + "alias": "9.9.9", + "alias_normalized": "9.9.9.0" + } + ], + "minimum-stability": "stable", + "stability-flags": { + "phpcompatibility/php-compatibility": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^8.0" + }, + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..8ed7591 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,182 @@ + + + Coding standards for the WPGraphQL plugin + + + ./wpgraphql-ide.php + ./phpstan/* + */**/tests/ + */node_modules/* + */vendor/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_output/.gitkeep b/tests/_output/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/wpgraphql-ide.php b/wpgraphql-ide.php index 86786ea..784008c 100644 --- a/wpgraphql-ide.php +++ b/wpgraphql-ide.php @@ -8,6 +8,8 @@ * License: GPLv3 or later * Text Domain: wpgraphql-ide * Version: 1.0.1 + * Requires PHP: 7.4 + * Tested up to: 6.4.3 * * @package WPGraphQLIDE */ @@ -15,7 +17,7 @@ namespace WPGraphQLIDE; if ( ! defined( 'ABSPATH' ) ) { - exit; + exit; } define( 'WPGRAPHQL_IDE_ROOT_ELEMENT_ID', 'wpgraphql-ide-root' ); @@ -26,7 +28,7 @@ * @return string The SVG logo markup. */ function graphql_logo_svg(): string { - return << @@ -45,33 +47,33 @@ function graphql_logo_svg(): string { * @return bool Whether the user lacks the required capability. */ function user_lacks_capability(): bool { - $capability_required = apply_filters( 'wpgraphqlide_capability_required', 'manage_options' ); + $capability_required = apply_filters( 'wpgraphqlide_capability_required', 'manage_options' ); - return ! current_user_can( $capability_required ); + return ! current_user_can( $capability_required ); } /** * Checks if the current page is intended for the dedicated WPGraphQL IDE (non-drawer). - * + * * @return bool True if the current page is a dedicated WPGraphQL IDE page, false otherwise. */ function is_dedicated_ide_page(): bool { - if ( ! function_exists( 'get_current_screen' ) ) { - _doing_it_wrong( __FUNCTION__, 'Function should only be called within admin pages context.', '1.0.1' ); - return false; - } - - $screen = get_current_screen(); - if ( ! $screen ) { - return false; - } - - $dedicated_ide_screens = [ - 'toplevel_page_graphiql-ide', // old - GraphiQL IDE - 'graphql_page_graphql-ide', // new - GraphQL IDE - ]; - - return in_array( $screen->id, $dedicated_ide_screens, true ); + if ( ! function_exists( 'get_current_screen' ) ) { + _doing_it_wrong( __FUNCTION__, 'Function should only be called within admin pages context.', '1.0.1' ); + return false; + } + + $screen = get_current_screen(); + if ( ! $screen ) { + return false; + } + + $dedicated_ide_screens = [ + 'toplevel_page_graphiql-ide', // old - GraphiQL IDE + 'graphql_page_graphql-ide', // new - GraphQL IDE + ]; + + return in_array( $screen->id, $dedicated_ide_screens, true ); } /** @@ -80,27 +82,25 @@ function is_dedicated_ide_page(): bool { * This function adds the mount point for the plugin's React app. * * @global WP_Admin_Bar $wp_admin_bar The WordPress Admin Bar instance. - * - * @return void */ function register_wpadminbar_menu(): void { - if ( is_dedicated_ide_page() ) { - return; - } + if ( is_dedicated_ide_page() ) { + return; + } - if ( user_lacks_capability() ) { - return; - } + if ( user_lacks_capability() ) { + return; + } - global $wp_admin_bar; + global $wp_admin_bar; - $args = [ - 'id' => 'wpgraphql-ide', - 'title' => '
', - 'href' => '#', - ]; + $args = [ + 'id' => 'wpgraphql-ide', + 'title' => '
', + 'href' => '#', + ]; - $wp_admin_bar->add_node( $args ); + $wp_admin_bar->add_node( $args ); } add_action( 'admin_bar_menu', __NAMESPACE__ . '\\register_wpadminbar_menu', 999 ); @@ -115,49 +115,43 @@ function register_wpadminbar_menu(): void { * * @see add_submenu_page() For more information on adding submenu pages. * @link https://developer.wordpress.org/reference/functions/add_submenu_page/ - * - * @return void */ function register_dedicated_ide_menu(): void { - if ( user_lacks_capability() ) { - return; - } - - add_submenu_page( - 'graphiql-ide', - __( 'GraphQL IDE', 'wp-graphql' ), - __( 'GraphQL IDE', 'wp-graphql' ), - 'manage_options', - 'graphql-ide', - __NAMESPACE__ . '\\render_dedicated_ide_page' - ); + if ( user_lacks_capability() ) { + return; + } + + add_submenu_page( + 'graphiql-ide', + __( 'GraphQL IDE', 'wp-graphql' ), + __( 'GraphQL IDE', 'wp-graphql' ), + 'manage_options', + 'graphql-ide', + __NAMESPACE__ . '\\render_dedicated_ide_page' + ); } add_action( 'admin_menu', __NAMESPACE__ . '\\register_dedicated_ide_menu' ); /** * Renders the container for the dedicated IDE page for the React app to be mounted to. - * - * @return void */ function render_dedicated_ide_page(): void { - echo '
IDE GOES HERE
'; + echo '
IDE GOES HERE
'; } /** * Enqueues custom CSS to set the "GraphQL IDE" menu item icon in the WordPress Admin Bar. - * - * @return void */ function enqueue_graphql_ide_menu_icon_css(): void { - if ( is_dedicated_ide_page() ) { - return; - } + if ( is_dedicated_ide_page() ) { + return; + } - if ( user_lacks_capability() ) { - return; - } + if ( user_lacks_capability() ) { + return; + } - $custom_css = ' + $custom_css = ' #wp-admin-bar-wpgraphql-ide .ab-icon::before { background-image: url("data:image/svg+xml;base64,' . base64_encode( graphql_logo_svg() ) . '"); background-size: 100%; @@ -170,62 +164,60 @@ function enqueue_graphql_ide_menu_icon_css(): void { } '; - wp_add_inline_style( 'admin-bar', $custom_css ); + wp_add_inline_style( 'admin-bar', $custom_css ); } add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\enqueue_graphql_ide_menu_icon_css' ); add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\enqueue_graphql_ide_menu_icon_css' ); /** * Enqueues the React application script and associated styles. - * - * @return void */ function enqueue_react_app_with_styles(): void { - if ( ! class_exists( '\WPGraphQL\Router' ) ) { - return; - } - - if ( user_lacks_capability() ) { - return; - } - - $app_dependencies = [ - 'wp-element', - 'wp-components', - 'wp-api-fetch', - 'wp-i18n', - ]; - - $app_context = get_app_context(); - - $version = get_plugin_header( 'Version' ); - - wp_enqueue_script( - 'wpgraphql-ide-app', - plugins_url( 'build/index.js', __FILE__ ), - $app_dependencies, - $version, - true - ); - - wp_localize_script( - 'wpgraphql-ide-app', - 'WPGRAPHQL_IDE_DATA', - [ - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'graphqlEndpoint' => trailingslashit( site_url() ) . 'index.php?' . \WPGraphQL\Router::$route, - 'rootElementId' => WPGRAPHQL_IDE_ROOT_ELEMENT_ID, - 'context' => $app_context, - ] - ); - - wp_enqueue_style( 'wpgraphql-ide-app', plugins_url( 'build/index.css', __FILE__ ), [], $version ); - // Avoid running custom styles through a build process for an improved developer experience. - wp_enqueue_style( 'wpgraphql-ide', plugins_url( 'styles/wpgraphql-ide.css', __FILE__ ), [], $version ); - - // Extensions looking to extend GraphiQL can hook in here, - // after the window object is established, but before the App renders - do_action( 'wpgraphqlide_enqueue_script', $app_context ); + if ( ! class_exists( '\WPGraphQL\Router' ) ) { + return; + } + + if ( user_lacks_capability() ) { + return; + } + + $app_dependencies = [ + 'wp-element', + 'wp-components', + 'wp-api-fetch', + 'wp-i18n', + ]; + + $app_context = get_app_context(); + + $version = get_plugin_header( 'Version' ); + + wp_enqueue_script( + 'wpgraphql-ide-app', + plugins_url( 'build/index.js', __FILE__ ), + $app_dependencies, + $version, + true + ); + + wp_localize_script( + 'wpgraphql-ide-app', + 'WPGRAPHQL_IDE_DATA', + [ + 'nonce' => wp_create_nonce( 'wp_rest' ), + 'graphqlEndpoint' => trailingslashit( site_url() ) . 'index.php?' . \WPGraphQL\Router::$route, + 'rootElementId' => WPGRAPHQL_IDE_ROOT_ELEMENT_ID, + 'context' => $app_context, + ] + ); + + wp_enqueue_style( 'wpgraphql-ide-app', plugins_url( 'build/index.css', __FILE__ ), [], $version ); + // Avoid running custom styles through a build process for an improved developer experience. + wp_enqueue_style( 'wpgraphql-ide', plugins_url( 'styles/wpgraphql-ide.css', __FILE__ ), [], $version ); + + // Extensions looking to extend GraphiQL can hook in here, + // after the window object is established, but before the App renders + do_action( 'wpgraphqlide_enqueue_script', $app_context ); } add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\enqueue_react_app_with_styles' ); add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\enqueue_react_app_with_styles' ); @@ -233,34 +225,35 @@ function enqueue_react_app_with_styles(): void { /** * Retrieves the specific header of this plugin. * - * @param string The plugin data key. + * @param string $key The plugin data key. * @return string|null The version number of the plugin. Returns an empty string if the version is not found. */ -function get_plugin_header( $key = '' ): ?string { - if ( ! function_exists( 'get_plugin_data' ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - } +function get_plugin_header( string $key = '' ): ?string { + if ( ! function_exists( 'get_plugin_data' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } - if ( empty( $key ) ) { - return null; - } + if ( empty( $key ) ) { + return null; + } - $plugin_data = get_plugin_data( __FILE__ ); + $plugin_data = get_plugin_data( __FILE__ ); - return $plugin_data[ $key ] ?? null; + return $plugin_data[ $key ] ?? null; } /** * Retrieves app context. - * - * @return array The possibly filtered app context array. + * + * @return array The possibly filtered app context array. */ -function get_app_context() { - $context = apply_filters( 'wpgraphqlide_context', [ - 'pluginVersion' => get_plugin_header( 'Version' ), - 'pluginName' => get_plugin_header( 'Name' ), - 'externalFragments' => apply_filters( 'wpgraphqlide_external_fragments', [] ) - ]); - - return $context; +function get_app_context(): array { + return apply_filters( + 'wpgraphqlide_context', + [ + 'pluginVersion' => get_plugin_header( 'Version' ), + 'pluginName' => get_plugin_header( 'Name' ), + 'externalFragments' => apply_filters( 'wpgraphqlide_external_fragments', [] ), + ] + ); } From 9fb4dfe63ff43d98f97e570767f91949f797fe01 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 28 Feb 2024 16:21:18 -0700 Subject: [PATCH 3/4] Update .github/workflows/wordpress-coding-standards.yml Co-authored-by: Joe Fusco --- .github/workflows/wordpress-coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wordpress-coding-standards.yml b/.github/workflows/wordpress-coding-standards.yml index 4329468..e6fd3f9 100644 --- a/.github/workflows/wordpress-coding-standards.yml +++ b/.github/workflows/wordpress-coding-standards.yml @@ -4,7 +4,7 @@ on: push: branches: - develop - - master + - main pull_request: branches: - develop From 537f92692298314939cdbbd4e63ed653561da54e Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 28 Feb 2024 16:21:39 -0700 Subject: [PATCH 4/4] Update .github/workflows/wordpress-coding-standards.yml Co-authored-by: Joe Fusco --- .github/workflows/wordpress-coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wordpress-coding-standards.yml b/.github/workflows/wordpress-coding-standards.yml index e6fd3f9..5f9ea26 100644 --- a/.github/workflows/wordpress-coding-standards.yml +++ b/.github/workflows/wordpress-coding-standards.yml @@ -8,7 +8,7 @@ on: pull_request: branches: - develop - - master + - main jobs: run: