Skip to content

Commit 593cc62

Browse files
Add PHP CS in GH Actions and Local (#745)
Co-authored-by: Timotei <bondastimotei@gmail.com>
1 parent 22273b1 commit 593cc62

File tree

6 files changed

+258
-4
lines changed

6 files changed

+258
-4
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,29 @@ on:
99
pull_request:
1010

1111
jobs:
12-
test:
12+
check:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
1616

17-
- uses: actions/setup-node@v3
17+
- name: Cache Composer dependencies
18+
uses: actions/cache@v3
1819
with:
19-
node-version: '20'
20+
path: .cache
21+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
22+
23+
- name: Initialize Node.js
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: '22'
2027
check-latest: true
2128
cache: npm
2229
cache-dependency-path: package-lock.json
2330

24-
- run: npm ci
31+
# Start actions
32+
- run: mkdir -p .cache
33+
- run: composer install
34+
- run: composer run sniff-check
2535

36+
- run: npm clean-install
2637
- run: npm run format-check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
.env*
77
.vscode
88
node_modules
9+
/vendor

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
**/*.min.*
22
**/*.ori.*
33
**/*.tpl.php
4+
composer.json
5+
composer.lock
6+
package.json
7+
package-lock.json
8+
vendor
9+
.cache
410
assets/js/css_async.js
511
assets/js/webfontloader.js
612
lib

composer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "litespeedtech/lscache_wp",
3+
"require-dev": {
4+
"squizlabs/php_codesniffer": "*",
5+
"phpcompatibility/php-compatibility": "*"
6+
},
7+
"prefer-stable": true,
8+
"scripts": {
9+
"post-install-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility",
10+
"post-update-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility",
11+
"sniff-check": "phpcs"
12+
}
13+
}

composer.lock

Lines changed: 161 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml.dist

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="LiteSpeed Cache Coding Standards">
3+
<description>Apply LiteSpeed Cache Coding Standards to all plugin files</description>
4+
5+
<!--
6+
#############################################################################
7+
COMMAND LINE ARGUMENTS
8+
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
9+
#############################################################################
10+
-->
11+
12+
<!-- Only scan PHP files -->
13+
<arg name="extensions" value="php"/>
14+
15+
<!-- Cache scan results to use for unchanged files on future scans -->
16+
<arg name="cache" value=".cache/phpcs.json"/>
17+
18+
<!-- Set memory limit to 512M
19+
Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#specifying-phpini-settings
20+
-->
21+
<ini name="memory_limit" value="512M"/>
22+
23+
<!-- Remove unwanted prefix from filepaths -->
24+
<arg name="basepath" value="./"/>
25+
26+
<!-- Check max 20 files in parallel -->
27+
<arg name="parallel" value="20"/>
28+
29+
<!-- Show sniff codes in all reports -->
30+
<arg value="ps"/>
31+
32+
<!--
33+
#############################################################################
34+
FILE SELECTION
35+
Set which files will be subject to the scans executed using this ruleset.
36+
#############################################################################
37+
-->
38+
39+
<file>.</file>
40+
41+
<!-- Exclude any wordpress folder in the current directory -->
42+
<exclude-pattern type="relative">^wordpress/*</exclude-pattern>
43+
44+
<!-- Directories and third-party library exclusions -->
45+
<exclude-pattern>/node_modules/*</exclude-pattern>
46+
<exclude-pattern>/vendor/*</exclude-pattern>
47+
48+
<!--
49+
#############################################################################
50+
SET UP THE RULESET
51+
#############################################################################
52+
-->
53+
<!-- Check PHP v7.2 and all newer versions -->
54+
<config name="testVersion" value="7.2-"/>
55+
56+
<rule ref="PHPCompatibility">
57+
<!-- Exclude false positives -->
58+
<!-- array_key_firstFound is defined in lib/php-compatibility.func.php -->
59+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_key_firstFound" />
60+
</rule>
61+
62+
</ruleset>

0 commit comments

Comments
 (0)