Skip to content

Commit 15f0396

Browse files
authored
Merge pull request #28 from hametuha/feature/standardize-phpstan-playground
Add PHPStan and Playground preview
2 parents 09e158c + 1c17e31 commit 15f0396

14 files changed

Lines changed: 388 additions & 632 deletions

.claude/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ hamelp/
163163
## 注意事項
164164

165165
- `wp-dependencies.json` はビルド成果物だが、`.distignore` には入れない(PHPから読み込むため)
166-
- `composer.lock` `.gitignore` に入っている(複数PHPバージョンでテストするため
166+
- `composer.lock` はコミットする(依存関係の再現性のため。`composer.json` を変更したら必ず `composer install` で更新して一緒にコミットする
167167
- `package-lock.json` はコミットする(アセットビルドの一貫性のため)

.distignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.husky
99
.travis.yml
1010
.github
11+
.node-version
1112
.wp-env.json
1213
.DS_Store
1314
Thumbs.db
@@ -26,6 +27,11 @@ multisite.xml
2627
multisite.xml.dist
2728
phpcs.xml
2829
phpcs.xml.dist
30+
phpcs.ruleset.xml
31+
phpstan.neon
32+
phpstan-baseline.neon
33+
phpstan-bootstrap.php
34+
phpstan
2935
README.md
3036
wp-cli.local.yml
3137
yarn.lock
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Playground Preview - Build
2+
3+
on:
4+
pull_request:
5+
types: [labeled, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
if: >
13+
contains(github.event.pull_request.labels.*.name, 'playground') &&
14+
(github.event.action != 'labeled' || github.event.label.name == 'playground')
15+
uses: tarosky/workflows/.github/workflows/playground-preview-build.yml@main
16+
with:
17+
build_command: 'composer install --no-dev --prefer-dist && npm ci && npm run package'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Playground Preview - Publish
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Playground Preview - Build"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
publish:
15+
if: >
16+
github.event.workflow_run.event == 'pull_request' &&
17+
github.event.workflow_run.conclusion == 'success'
18+
uses: tarosky/workflows/.github/workflows/playground-preview-publish.yml@main

.github/workflows/test.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ jobs:
3939
- name: PHP CodeSniffer
4040
run: composer lint
4141

42+
phpstan:
43+
name: PHPStan
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Setup PHP
49+
uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: 7.4
52+
tools: composer
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Install dependencies
57+
run: composer install --no-progress
58+
59+
- name: Run PHPStan
60+
run: composer phpstan
61+
4262
phplint:
4363
uses: tarosky/workflows/.github/workflows/phplint.yml@main
4464
with:
@@ -70,7 +90,7 @@ jobs:
7090
status:
7191
name: Status Check
7292
runs-on: ubuntu-latest
73-
needs: [ test, phpcs, phplint, assets ]
93+
needs: [ test, phpcs, phpstan, phplint, assets ]
7494
if: always()
7595
steps:
7696
- uses: re-actors/alls-green@release/v1

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Thumbs.db
66
wp-cli.local.yml
77
node_modules/
8-
composer.lock
98
*.sql
109
*.tar.gz
1110
*.zip

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

app/Hametuha/Hamelp/Hooks/AiOverview.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class AiOverview extends Singleton {
2222
* Initialize hooks.
2323
*/
2424
protected function init() {
25+
// wp-ai-client is bundled in WordPress 7.0+. If it's not available
26+
// (older WP), this feature is disabled silently.
27+
if ( ! class_exists( AI_Client::class ) ) {
28+
return;
29+
}
30+
2531
// Initialize wp-ai-client
2632
add_action( 'init', [ AI_Client::class, 'init' ] );
2733

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@
1212
"scripts": {
1313
"test": "phpunit",
1414
"lint": "phpcs --standard=phpcs.ruleset.xml",
15-
"fix": "phpcbf --standard=phpcs.ruleset.xml"
15+
"fix": "phpcbf --standard=phpcs.ruleset.xml",
16+
"phpstan": "phpstan analyse --memory-limit=1G"
1617
},
1718
"minimum-stability": "stable",
1819
"require": {
19-
"php": ">=7.4",
20-
"wordpress/wp-ai-client": "^0.2.1"
20+
"php": ">=7.4"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^9.0",
2424
"yoast/phpunit-polyfills": "^4.0",
25-
"wp-coding-standards/wpcs": "^3.0"
25+
"wp-coding-standards/wpcs": "^3.0",
26+
"phpstan/phpstan": "^2.1",
27+
"szepeviktor/phpstan-wordpress": "^2.0",
28+
"php-stubs/wordpress-stubs": "^6.9",
29+
"php-stubs/wp-cli-stubs": "^2.10"
2630
},
2731
"autoload": {
2832
"psr-0": {

0 commit comments

Comments
 (0)