Skip to content

Commit

Permalink
style: add wp coding standards and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Nov 19, 2023
1 parent 75b8b04 commit 5d766ca
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

/composer.lock export-ignore
/phpstan.neon export-ignore
/.phpcs.xml export-ignore
35 changes: 35 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PHPCS and PHPStan Check

on:
push:
branches:
- main
paths:
- "**.php"
pull_request:
paths:
- "**.php"

jobs:
phpcs:
name: Run PHPCS
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: 🐘 Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"

- name: 📥 Install PHP dependencies
uses: ramsey/composer-install@v2
with:
composer-options: "--classmap-authoritative"

- name: ✨ PHPCS
run: composer analyse:phpcs

- name: 🧐 PHPStan
run: composer analyse:phpstan
26 changes: 26 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<ruleset name="Custom">
<file>.</file>
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/src/*</exclude-pattern>
<exclude-pattern>/build/*</exclude-pattern>
<exclude-pattern>/*.js</exclude-pattern>

<config name="minimum_wp_version" value="6.3"/>
<arg name="basepath" value="."/>

<rule ref="WordPress">
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="Squiz.Commenting.FileComment.Missing"/>
<exclude name="Squiz.Commenting.ClassComment.Missing"/>
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode"/>
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores"/>
<exclude name="WordPress.WP.AlternativeFunctions.json_encode_json_encode"/>
<exclude name="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents"/>
</rule>
</ruleset>
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
},
"require-dev": {
"szepeviktor/phpstan-wordpress": "^v1.3",
"phpstan/extension-installer": "^1.3"
"phpstan/extension-installer": "^1.3",
"wp-coding-standards/wpcs": "^3.0"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
"clear-cache:phpstan": "phpstan clear-result-cache",
"analyse:phpcs": "phpcs",
"format": "phpcbf"
}
}
Loading

0 comments on commit 5d766ca

Please sign in to comment.