Skip to content

Commit a686285

Browse files
authored
Merge pull request #8 from BitsHost/feature/phase-3-hardening
Feature/phase 3 hardening
2 parents c4bd17d + 2288f9c commit a686285

80 files changed

Lines changed: 4651 additions & 4916 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
services:
13+
mysql:
14+
image: mysql:8.0
15+
env:
16+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
17+
MYSQL_DATABASE: test
18+
MYSQL_ROOT_PASSWORD: ""
19+
ports:
20+
- 3306:3306
21+
options: >-
22+
--health-cmd="mysqladmin ping -h 127.0.0.1 --silent"
23+
--health-interval=10s
24+
--health-timeout=5s
25+
--health-retries=30
26+
strategy:
27+
matrix:
28+
php: [ '8.2', '8.3' ]
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Setup PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: ${{ matrix.php }}
38+
extensions: mbstring, json, pdo, pdo_mysql
39+
coverage: none
40+
41+
- name: Validate composer.json and composer.lock
42+
run: composer validate --no-check-publish
43+
44+
- name: Install dependencies
45+
run: composer install --no-interaction --no-progress --prefer-dist
46+
47+
- name: Install MySQL client
48+
run: sudo apt-get update && sudo apt-get install -y mysql-client
49+
50+
- name: Wait for MySQL
51+
run: |
52+
for i in {1..60}; do
53+
mysqladmin ping -h 127.0.0.1 --silent && break
54+
sleep 2
55+
done
56+
mysql -h 127.0.0.1 -uroot -e "SHOW DATABASES;"
57+
58+
- name: Generate autoload
59+
run: composer dump-autoload -o
60+
61+
- name: PHPStan
62+
run: |
63+
if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then \
64+
vendor/bin/phpstan analyse --no-progress; \
65+
else \
66+
echo "Skipping PHPStan"; \
67+
fi
68+
69+
- name: PHPCS
70+
run: |
71+
if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then \
72+
vendor/bin/phpcs; \
73+
else \
74+
echo "Skipping PHPCS"; \
75+
fi
76+
77+
- name: PHPUnit
78+
run: |
79+
if [ -f phpunit.xml ] || [ -f phpunit.xml.dist ]; then \
80+
vendor/bin/phpunit -c phpunit.xml; \
81+
else \
82+
echo "Skipping PHPUnit"; \
83+
fi

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ private-vault/**
2929
# IDE and OS
3030
.DS_Store
3131
.idea/
32-
/tests/output/
32+
/tests/output/
33+
34+
# Tool caches (do not commit)
35+
/.phpstan/
36+
/.phpunit.cache/

.phpunit.cache/test-results

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Changelog
22

3+
## 2.0.1 - Type Safety & CI Hardening (2025-11-12)
4+
5+
### ✅ What changed
6+
- Static analysis: Reduced PHPStan issues to zero with precise generics, array-shape docs, and guards across core modules.
7+
- App hardening: Cleaned up Router, RBAC, Cache, Authenticator, ApiController, Monitor, and middlewares for stricter typing and better error handling.
8+
- Tests cleanup: Modernized tests to remove always-true assertions, add return types, guard glob/file reads, and align with updated return shapes.
9+
- CI ready: Ensured the test suite runs green on clean environments.
10+
11+
### 🔧 Highlights
12+
- RBAC: Normalized user roles mapping and removed unused state.
13+
- ApiController: Simplified cache-key logic and removed redundant checks; consistent return tuples.
14+
- Monitor & RequestLogger: Safer I/O guards; added minimal reads to satisfy analyzer without behavior change.
15+
- Cache: Tightened typing in manager and drivers; safer key generation and headers handling.
16+
- Middlewares: Fixed unreachable code in rate limiting; typed CORS config.
17+
- Config: Added explicit types and normalizations in `ApiConfig` and `CacheConfig` getters.
18+
19+
### 🧪 CI (GitHub Actions)
20+
- Added workflow to run Composer install, PHPStan, and PHPUnit on pushes/PRs.
21+
- Provisioned MySQL service (database: `test`) so DB-backed tests run reliably in CI.
22+
- Matrix on PHP 8.2 and 8.3.
23+
24+
### Result
25+
- PHPStan: 0 errors.
26+
- PHPUnit: All tests passing.
27+
28+
---
29+
330
## 2.0.0 - Performance & Architecture Revolution (2025-11-10)
431

532
### 🚀 Major New Features

MIGRATION.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
> Deprecated — Removed in v2.0.0-dev
2+
3+
This migration guide was used during the transition to the new canonical namespaces.
4+
As of v2.0.0-dev, legacy wrappers were removed and migration tooling is no longer
5+
part of the repository. Please refer to README.md for the current architecture.
6+
7+
Note: This file remains only to avoid broken links; it may be deleted in a later release.

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,36 @@ The `list` action endpoint now supports advanced query parameters:
432432

433433
---
434434

435-
### 📝 OpenAPI Path Example
435+
### 📝 OpenAPI Documentation (Swagger)
436436

437-
For `/index.php?action=list&table={table}`:
437+
**Your API automatically generates OpenAPI 3.0 documentation!**
438+
439+
#### Get the OpenAPI Specification (JSON)
440+
441+
```bash
442+
# Access the auto-generated OpenAPI spec
443+
curl http://localhost:8000/index.php?action=openapi
444+
445+
# Or visit in browser:
446+
http://localhost:8000/index.php?action=openapi
447+
```
448+
449+
#### View Interactive Documentation (Swagger UI)
450+
451+
**Option 1: Online Swagger Editor** (Quick & Easy)
452+
1. Copy JSON from: `http://localhost:8000/index.php?action=openapi`
453+
2. Paste into: https://editor.swagger.io/
454+
3. See beautiful interactive documentation!
455+
456+
**Option 2: Use dashboard.html** (Recommended)
457+
Your project includes `dashboard.html` which has API documentation built-in:
458+
```
459+
http://localhost:8000/dashboard.html
460+
```
461+
462+
#### Example OpenAPI Path Structure
463+
464+
This is what the specification includes for `/index.php?action=list&table={table}`:
438465

439466
```yaml
440467
get:
@@ -486,6 +513,8 @@ get:
486513
pages: { type: integer }
487514
```
488515
516+
**Note:** The YAML above is just an example of the structure. The actual API returns JSON format.
517+
489518
## 🛡️ Security Notes
490519
491520
- **Enable authentication for any public deployment!**
@@ -598,4 +627,8 @@ MIT
598627

599628
## 🙌 Credits
600629

601-
Built by [BitHost](https://github.com/BitsHost). PRs/issues welcome!
630+
Built by [BitHost](https://github.com/BitsHost). PRs/issues welcome!
631+
632+
---
633+
634+

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"version": "2.0.0-dev",
23
"name": "bitshost/php-crud-api-generator",
34
"description": "Instant REST API for MySQL/MariaDB with JWT auth, rate limiting, monitoring, and zero code generation",
45
"type": "library",
@@ -24,10 +25,12 @@
2425
}
2526
},
2627
"require-dev": {
27-
"phpunit/phpunit": "^10.0"
28+
"phpunit/phpunit": "^10.0",
29+
"phpstan/phpstan": "^2.1",
30+
"squizlabs/php_codesniffer": "^4.0"
2831
},
2932
"support": {
3033
"issues": "https://github.com/BitsHost/php-crud-api-generator/issues",
3134
"source": "https://github.com/BitsHost/php-crud-api-generator"
3235
}
33-
}
36+
}

0 commit comments

Comments
 (0)