-
Notifications
You must be signed in to change notification settings - Fork 0
enh: Add phpmd, phpstan and phpcs #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: Lint & Sniffs | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - dev | ||
| jobs: | ||
| php-lint-sniffs: | ||
| name: PHP (Sniffs) | ||
| runs-on: ubuntu-latest | ||
| # timeout-minutes: 20 | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
|
|
||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: '8.3' | ||
| tools: composer | ||
|
|
||
| - name: Install Composer dependencies | ||
| run: composer install --prefer-dist --no-progress --no-suggest --no-interaction | ||
|
|
||
| - name: PHP Code Standards | ||
| run: composer phpcs:test | ||
|
|
||
| - name: PHP Static Analysis | ||
| run: composer phpstan | ||
|
|
||
| - name: PHP Mess Detector | ||
| run: composer phpmd | ||
|
|
||
| - name: Laravel Pint | ||
| run: composer pint:test | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,14 +1,18 @@ | ||||||
| name: Code checks | ||||||
| name: Tests | ||||||
|
|
||||||
| on: | ||||||
| pull_request: | ||||||
| push: | ||||||
| branches: | ||||||
| - main | ||||||
| - dev | ||||||
|
|
||||||
| jobs: | ||||||
| tests: | ||||||
| runs-on: ubuntu-latest | ||||||
| strategy: | ||||||
| matrix: | ||||||
| php-version: [ '8.3', '8.4', '8.5' ] | ||||||
| services: | ||||||
| mysql-service: | ||||||
| image: mysql:5.7 | ||||||
|
|
@@ -42,16 +46,35 @@ jobs: | |||||
| echo "DB_USERNAME=root" >> workbench/.env | ||||||
| echo "DB_PASSWORD=password" >> workbench/.env | ||||||
| echo "APP_ENV=testing" >> workbench/.env | ||||||
| - name: Testing on PHP ${{ matrix.php-version }} | ||||||
| uses: shivammathur/setup-php@v2 | ||||||
| with: | ||||||
| php-version: ${{ matrix.php-version }} | ||||||
| tools: composer | ||||||
| extensions: pcov | ||||||
| coverage: pcov | ||||||
| - name: Install dependencies | ||||||
| run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist | ||||||
| - name: Publish roles migrations | ||||||
| run: vendor/bin/testbench vendor:publish --tag roles-migrations | ||||||
| - name: Run migrations | ||||||
| run: vendor/bin/testbench migrate | ||||||
| - name: Run tests | ||||||
| run: vendor/bin/testbench package:test | ||||||
| - name: Run linter test | ||||||
| run: composer pint:test | ||||||
| run: vendor/bin/testbench package:test --coverage --coverage-clover=reports/coverage/coverage.xml | ||||||
| - name: Check code coverage | ||||||
| run: | | ||||||
| COVERAGE=$(php -r " | ||||||
| \$xml = simplexml_load_file('reports/coverage/coverage.xml'); | ||||||
| \$metrics = \$xml->project->metrics; | ||||||
| \$coverage = ((int)\$metrics['coveredstatements'] / (int)\$metrics['statements']) * 100; | ||||||
| echo round(\$coverage, 2); | ||||||
| ") | ||||||
| echo "Code coverage: $COVERAGE%" | ||||||
| MIN_COVERAGE=59.1 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The minimum coverage threshold is set to a very specific value (59.1). It is recommended to round this to an integer or use a more standard threshold (e.g., 60 or 80) to avoid failures on minor, non-logical line shifts.
Suggested change
|
||||||
| if (( $(echo "$COVERAGE < $MIN_COVERAGE" | bc -l) )); then | ||||||
| echo "❌ Code coverage ($COVERAGE%) is below the minimum threshold of $MIN_COVERAGE%" | ||||||
| exit 1 | ||||||
| else | ||||||
| echo "✅ Code coverage ($COVERAGE%) meets the minimum threshold of $MIN_COVERAGE%" | ||||||
| fi | ||||||
| - name: Clean up SSH key | ||||||
| if: always() | ||||||
| run: rm -f ~/.ssh/id_rsa | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ vendor/ | |
| .idea/ | ||
| .phpunit.result.cache | ||
| workbench/storage | ||
| .vscode | ||
| .vscode | ||
| reports/ | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |||||
| } | ||||||
| ], | ||||||
| "require": { | ||||||
| "php": "^8.2", | ||||||
| "php": "^8.3", | ||||||
| "laravel/framework": "^12.0", | ||||||
| "laravel/sanctum": "^4.0", | ||||||
| "whilesmart/eloquent-roles": "*", | ||||||
|
|
@@ -22,7 +22,11 @@ | |||||
| "zircote/swagger-php": "^5.1", | ||||||
| "nunomaduro/collision": "^8.8", | ||||||
| "laravel/pint": "^1.22", | ||||||
| "fakerphp/faker": "^1.24" | ||||||
| "fakerphp/faker": "^1.24", | ||||||
| "phpmd/phpmd": "@stable", | ||||||
| "phpstan/phpstan": "^2.1", | ||||||
| "larastan/larastan": "^3.0", | ||||||
| "squizlabs/php_codesniffer": "^4.0" | ||||||
| }, | ||||||
| "suggest": { | ||||||
| "whilesmart/organizations": "For organization/customer management within workspaces", | ||||||
|
|
@@ -47,16 +51,22 @@ | |||||
| } | ||||||
| }, | ||||||
| "scripts": { | ||||||
| "test": "vendor/bin/testbench package:test", | ||||||
| "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", | ||||||
| "prepare": "@php vendor/bin/testbench package:discover --ansi", | ||||||
| "build": "@php vendor/bin/testbench workbench:build --ansi", | ||||||
| "pint": [ | ||||||
| "./vendor/bin/pint" | ||||||
| "./vendor/bin/pint --preset psr12" | ||||||
| ], | ||||||
| "pint:test": [ | ||||||
| "./vendor/bin/pint --test" | ||||||
| ] | ||||||
| "./vendor/bin/pint --preset psr12 --test" | ||||||
| ], | ||||||
| "phpmd": [ | ||||||
| "vendor/bin/phpmd src text phpmd.xml" | ||||||
| ], | ||||||
| "phpstan": "phpstan analyse src --memory-limit=2048M --level=5", | ||||||
| "phpcs": "phpcbf src", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| "phpcs:test": "phpcs src", | ||||||
| "test": "vendor/bin/testbench package:test --coverage" | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uncomment the timeout or remove it if not needed. It's better to have a reasonable timeout (e.g., 10 minutes) to prevent hung actions from consuming billing minutes.