Skip to content

Commit 6e2e3c3

Browse files
committed
chore(phase-3): add PHPStan/PHPCS configs, CI workflow, and Phase 3 plan doc; install dev tools
1 parent 69b31ab commit 6e2e3c3

5 files changed

Lines changed: 156 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, refactor-phase-2, feature/** ]
6+
pull_request:
7+
branches: [ main, refactor-phase-2 ]
8+
9+
jobs:
10+
build-test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php: [ '8.0', '8.1', '8.2', '8.3' ]
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php }}
24+
extensions: mbstring, json, pdo, pdo_mysql
25+
coverage: none
26+
27+
- name: Validate composer.json and composer.lock
28+
run: composer validate --no-check-publish
29+
30+
- name: Install dependencies
31+
run: composer install --no-interaction --no-progress --prefer-dist
32+
33+
- name: Generate autoload
34+
run: composer dump-autoload -o
35+
36+
- name: PHPStan
37+
run: |
38+
if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then \
39+
vendor/bin/phpstan analyse --no-progress; \
40+
else \
41+
echo "Skipping PHPStan"; \
42+
fi
43+
44+
- name: PHPCS
45+
run: |
46+
if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then \
47+
vendor/bin/phpcs; \
48+
else \
49+
echo "Skipping PHPCS"; \
50+
fi
51+
52+
- name: PHPUnit
53+
run: |
54+
if [ -f phpunit.xml ] || [ -f phpunit.xml.dist ]; then \
55+
vendor/bin/phpunit -c phpunit.xml; \
56+
else \
57+
echo "Skipping PHPUnit"; \
58+
fi

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
}
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^10.0"
28+
"phpunit/phpunit": "^10.0",
29+
"phpstan/phpstan": "^2.1",
30+
"squizlabs/php_codesniffer": "^4.0"
2931
},
3032
"support": {
3133
"issues": "https://github.com/BitsHost/php-crud-api-generator/issues",
3234
"source": "https://github.com/BitsHost/php-crud-api-generator"
3335
}
34-
}
36+
}

docs/PHASE_3_PLAN.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Phase 3: Hardening and Release Prep
2+
3+
Branch: `feature/phase-3-hardening` (based on `refactor-phase-2`)
4+
5+
## Goals
6+
- Stabilize API and internal structure (no feature creep)
7+
- High-confidence release quality: tests + static analysis + style checks
8+
- Updated documentation (user + developer)
9+
- Green CI across PHP 8.0–8.3
10+
11+
## Success Criteria
12+
- Build: Composer autoload OK
13+
- Static analysis: PHPStan level 7 (target 8)
14+
- Style: PHPCS PSR-12 clean
15+
- Tests: PHPUnit passing; coverage ≥ 70% (stretch: 80%+)
16+
- CI: Green on PR (lint + static + tests)
17+
- Docs: Up to date (Quickstart, Config, Endpoints, Security, Caching, Observability)
18+
19+
## Workstream Breakdown
20+
21+
### 1) Tests
22+
- Unit tests for:
23+
- Http: Response, ErrorResponder, Middleware (CORS, RateLimit)
24+
- Auth: Authenticator (apikey/basic/jwt + DB auth path), role retrieval
25+
- Security: Rbac, RbacGuard, RateLimiter
26+
- Database: SchemaInspector (via mock PDO), Dialects (quoting)
27+
- ApiGenerator: list/count filters, sort, pagination; CRUD behaviors
28+
- Observability: RequestLogger, Monitor (metrics, alerts)
29+
- Docs: OpenApiGenerator minimal spec
30+
- Integration smoke tests for Router (list/read/create/update/delete/openapi/login)
31+
32+
### 2) Static Analysis + Style
33+
- PHPStan config: `phpstan.neon.dist` (level 7 → iterate up)
34+
- PHPCS config: `phpcs.xml.dist` (PSR-12)
35+
- Address critical findings; schedule non-critical fixes post-freeze
36+
37+
### 3) CI Pipeline
38+
- GitHub Actions: `.github/workflows/ci.yml`
39+
- Matrix: PHP 8.0, 8.1, 8.2, 8.3
40+
- Steps: composer validate → install → dump-autoload → phpstan → phpcs → phpunit
41+
42+
### 4) Docs Updates
43+
- README: Quickstart with `App\Application\Router` entrypoint
44+
- CONFIG: `config/api.php` and `config/cache.php` options aligned with `ApiConfig`/`CacheConfig`
45+
- Endpoints: Actions, filters, sorting, pagination, bulk
46+
- Security: Auth methods + RBAC usage, examples; rate limit headers
47+
- Observability: RequestLogger/Monitor paths, rotation/cleanup
48+
- Caching: CacheManager TTLs, exclusions, varyBy
49+
- Migration: v2.0.0-dev hard break (wrappers removed; canonical namespaces only)
50+
51+
## Execution Sequence (Suggested)
52+
1) Baseline run (build/static/tests) → capture issues
53+
2) Add/fix unit tests per module → quick iterations
54+
3) Router integration smoke tests
55+
4) Raise PHPStan level and fix high-signal findings
56+
5) CI green across matrix
57+
6) Final docs refresh + examples
58+
59+
## Risk & Mitigation
60+
- DB-dependent tests: prefer mocks for unit; add optional integration profile later
61+
- Platform differences (Windows paths): tests use sys_get_temp_dir() and portable paths
62+
- Flaky tests (timing, rate limit): use deterministic settings in test env
63+
64+
---
65+
Maintainer note: Keep PRs small and focused (tests per module); keep branch scoped to hardening only.

phpcs.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHP-CRUD-API-Generator Coding Standards">
3+
<description>PSR-12 with project-specific exclusions.</description>
4+
<rule ref="PSR12" />
5+
6+
<file>src</file>
7+
<file>tests</file>
8+
9+
<exclude-pattern>vendor/*</exclude-pattern>
10+
<exclude-pattern>storage/*</exclude-pattern>
11+
<exclude-pattern>logs/*</exclude-pattern>
12+
13+
<!-- Allow long lines in generated docs/tests -->
14+
<rule ref="Generic.Files.LineLength">
15+
<properties>
16+
<property name="lineLimit" value="160"/>
17+
<property name="absoluteLineLimit" value="0"/>
18+
</properties>
19+
</rule>
20+
</ruleset>

phpstan.neon.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: 7
3+
paths:
4+
- src
5+
- tests
6+
ignoreErrors:
7+
- '#Cannot call method (.*) on mixed#'
8+
reportUnmatchedIgnoredErrors: true
9+
tmpDir: .phpstan

0 commit comments

Comments
 (0)