Skip to content

Commit

Permalink
add phpcs and phpstan checks
Browse files Browse the repository at this point in the history
closes #7
  • Loading branch information
crstauf authored Sep 18, 2023
1 parent d9c1778 commit e6647d4
Show file tree
Hide file tree
Showing 27 changed files with 2,043 additions and 345 deletions.
35 changes: 35 additions & 0 deletions .github/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Contributing

[![PHPCS](https://github.com/cssllc/mu-plugins/actions/workflows/phpcs.yml/badge.svg)](https://github.com/cssllc/mu-plugins/actions/workflows/phpcs.yml)
[![PHPStan](https://github.com/cssllc/mu-plugins/actions/workflows/phpstan.yml/badge.svg)](https://github.com/cssllc/mu-plugins/actions/workflows/phpstan.yml)

## Checks

There are two checks run on pull requests:

1. PHPCS
1. PHPStan

PHPCS and PHPStan are managed via Composer.

### Setup

To setup the checks locally, run the install command with the root of the WordPress install (directory with `composer.json`):

```
composer install
```

### Run

#### PHPCS

```
vendor/bin/phpcs
```

#### PHPStan

```
vendor/bin/phpstan --memory-limit=-1
```
7 changes: 7 additions & 0 deletions .github/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# MU-Plugins

Collection of WordPress mu-plugins to enhance and customize a WordPress install.

## Contributing

Please read the [Contributing doc](contributing.md).
50 changes: 50 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: PHPCS
run-name: Run PHPCS on `${{ github.head_ref }}`

on:
pull_request:
paths:
- 'src/*.php'
- '.github/workflows/phpcs.yml'
- 'phpcs.xml'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
phpcs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Detect File Changes
uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
wpcontent:
- added|modified: 'src/**/*.php'
- name: Setup PHP
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.2"
ini-values: "memory_limit=1G"
coverage: none

- name: Validate composer.json and composer.lock
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
run: composer validate --no-check-publish

- name: Install Composer dependencies
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
run: |
composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader
- name: Run PHPCS checks
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
run: ./vendor/bin/phpcs ${{ steps.filter.outputs.wpcontent_files }}
54 changes: 54 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PHPStan
run-name: Run PHPStan on `${{ github.head_ref }}`

on:
pull_request:
paths:
- 'dev/phpstan-bootstrap.php'
- 'dev/wordpress-overrides.stub'
- 'dev/patches/**/*.patch'
- 'src/**/*.php'
- '.github/workflows/phpstan.yml'
- 'phpstan-baseline.neon'
- 'phpstan.neon'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
phpstan:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Detect File Changes
uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
wpcontent:
- added|modified: 'src/**/*.php'
- name: Setup PHP
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.2"
ini-values: "memory_limit=1G"
coverage: none

- name: Validate composer.json and composer.lock
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
run: composer validate --no-check-publish

- name: Install Composer dependencies
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
run: |
composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader
- name: Run PHPStan checks
if: ${{ steps.filter.outputs.wpcontent == 'true' }}
run: ./vendor/bin/phpstan analyse ${{ steps.filter.outputs.wpcontent_files }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/acf-json
/.phpstan-cache
/acf-json
/vendor
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "cssllc/mu-plugins",
"description": "CSSLLC MU-Plugins",
"require-dev": {
"automattic/vipwpcs": "^3.0",
"szepeviktor/phpstan-wordpress": "^1.1",
"phpstan/extension-installer": "^1.1",
"php-stubs/acf-pro-stubs": "^6.0",
"php-stubs/wordpress-stubs": "^6.0",
"squizlabs/php_codesniffer": "^3.7",
"mediawiki/mediawiki-codesniffer": "^41.0",
"cweagans/composer-patches": "~1.0"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true,
"cweagans/composer-patches": true
}
},
"license": "proprietary",
"extra": {
"patches": {
"php-stubs/acf-pro-stubs": {
"PHPStan return types": "dev/patches/acf-pro-stubs.patch"
}
}
}
}
Loading

0 comments on commit e6647d4

Please sign in to comment.