Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Formatting-only commits ignored by git blame.
# Enable locally: git config blame.ignoreRevsFile .git-blame-ignore-revs
# Use git blame -w to help attribute reformatted whitespace to earlier commits.

# style: format PHP source and tests with Mago
69d6c6137d3d17a3237d51ca77767c59cbab205d
61 changes: 48 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,87 @@ name: PHP Tests
on:
push:
branches: [ "master" ]
pull_request_review:
types: [ submitted, edited ]

pull_request:
types:
- opened
- edited
- synchronize
- reopened
branches:
- master

workflow_dispatch:

permissions:
contents: read

jobs:
quality:
name: Mago formatter, linter and analyzer
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
- name: Install development dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Run formatter, linter and analyzer without a baseline
run: composer check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

run:
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 15

strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest ]
php-version: [ '8.1', '8.2' ]
php-version: [ '8.1', '8.2', '8.3', '8.4', '8.5' ]

name: PHP ${{ matrix.php-version }} test on ${{ matrix.operating-system }}
name: PHP ${{ matrix.php-version }} tests on ${{ matrix.operating-system }}

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v7

- name: Install PHP
id: php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug

- name: Check PHP version
run: php -v

- name: Cache Composer packages
- name: Get Composer cache directory
id: composer-cache
uses: actions/cache@v3
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache Composer downloads
uses: actions/cache@v6
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.operating-system }}-php-${{ steps.php.outputs.php-version }}-composer-${{ hashFiles('**/composer.json') }}
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json', 'composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.operating-system }}-php-${{ steps.php.outputs.php-version }}
${{ runner.os }}-php-${{ matrix.php-version }}-composer-

- if: steps.composer-cache.outputs.cache-hit != 'true'
name: Install Composer dependencies
run: composer install --prefer-dist --no-progress
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: PHPUnit Tests
run: vendor/bin/phpunit --coverage-clover ./tests/coverage.xml --display-notices
run: vendor/bin/phpunit --testsuite=Tests --coverage-clover ./tests/coverage.xml --display-notices

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./tests/coverage.xml
Expand Down
32 changes: 32 additions & 0 deletions MAGO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Mago checks

Mago is pinned to [1.59.0](https://github.com/carthage-software/mago/releases/tag/1.59.0)
as a development dependency. Install dependencies with `composer install`, then run:

```sh
composer check # formatting, linter, and analyzer for source and tests
composer format-check # check formatting without changing files
composer lint
composer analyze
composer format # apply formatting
```

`mago.toml` checks both `src` and `tests`, targeting PHP 8.1, the minimum supported
version. Dependencies provide type information but are not
checked. Generated files in `tests/cache`, `tests/coverage`, and `tests/tmp` are
excluded.

The linter settings follow PHP-AOP: strict types, named arguments, boolean flags,
and `isset` retain the existing API conventions. Aggregate complexity metrics are
left to review, and the parameter-count threshold is 10. Analyzer missing-type
checks are enabled, and checks fail on findings at note severity or higher.

Formatting, lint, and analyzer checks pass without a baseline or vendor type patch.
`Metadata` has one documented `too-many-properties` expectation because its public
fields mirror PHP stream metadata. All other findings are addressed in source and
tests. The CI quality job runs `composer check`.

The scripts invoke the project-local PHP launcher. Its first invocation downloads
the matching native binary; CI supplies `GITHUB_TOKEN` for that download. On
Windows, the launcher needs PHP's ZIP extension and a trusted CA certificate
bundle configured for HTTPS downloads.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
],
"scripts": {
"test": "phpunit --display-notices",
"test-coverage": "phpunit --coverage-html tests/coverage --display-notices"
"test-coverage": "phpunit --coverage-html tests/coverage --display-notices",
"format": "@php vendor/bin/mago format",
"format-check": "@php vendor/bin/mago format --check",
"lint": "@php vendor/bin/mago lint --minimum-fail-level note",
"analyze": "@php vendor/bin/mago analyze --minimum-fail-level note",
"check": ["@format-check", "@lint", "@analyze"]
},
"require": {
"php": ">=8.1",
Expand All @@ -32,6 +37,7 @@
"roave/better-reflection": "^6.8"
},
"require-dev": {
"carthage-software/mago": "1.59.0",
"phpunit/phpunit": "^10",
"symfony/var-dumper": "^6.2"
},
Expand Down
39 changes: 39 additions & 0 deletions mago.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
php-version = "8.1"

[source]
paths = ["src", "tests"]
includes = ["vendor"]
excludes = ["tests/cache", "tests/coverage", "tests/tmp"]

[linter]
integrations = ["phpunit"]

[linter.rules.disallowed-functions]
enabled = true
level = "error"
functions = ["assert"]

# Preserve the library's coercion contract and existing public call signatures.
[linter.rules.strict-types]
enabled = false
[linter.rules.literal-named-argument]
enabled = false
[linter.rules.no-boolean-flag-parameter]
enabled = false
# isset intentionally distinguishes null from a usable value throughout this code.
[linter.rules.no-isset]
enabled = false
# Complexity metrics are review aids, not correctness gates for a code transformation library.
[linter.rules.halstead]
enabled = false
[linter.rules.kan-defect]
enabled = false
[linter.rules.cyclomatic-complexity]
enabled = false
[linter.rules.too-many-methods]
enabled = false
[linter.rules.excessive-parameter-list]
threshold = 10

[analyzer]
check-missing-type-hints = true
Loading
Loading