diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 335bdd3..750e289 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,3 +46,27 @@ jobs: - name: Run tests run: vendor/bin/phpunit + + quality: + runs-on: ubuntu-latest + name: Code quality + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + extensions: mbstring, pdo, sqlite3, pdo_sqlite + coverage: none + + - name: Install dependencies + run: composer update --prefer-dist --no-interaction --no-progress + + - name: Check code style (Pint) + run: composer lint + + - name: Run static analysis (PHPStan) + run: composer analyse diff --git a/composer.json b/composer.json index d3b39b8..de026bc 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,9 @@ }, "require-dev": { "orchestra/testbench": "^9.0|^10.0|^11.0", - "phpunit/phpunit": "^10.5|^11.0|^12.0" + "phpunit/phpunit": "^10.5|^11.0|^12.0", + "laravel/pint": "^1.29", + "larastan/larastan": "^3.10" }, "autoload": { "psr-4": { @@ -37,6 +39,9 @@ } }, "scripts": { + "analyse": "vendor/bin/phpstan analyse --memory-limit=1G", + "format": "vendor/bin/pint", + "lint": "vendor/bin/pint --test", "test": "phpunit" }, "minimum-stability": "dev", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..7b0b522 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,15 @@ +includes: + - vendor/larastan/larastan/extension.neon + +parameters: + paths: + - src + + level: 5 + + ignoreErrors: + # Package traits are consumed by userland models, not by the + # package itself, so they are never "used" from PHPStan's view. + - + identifier: trait.unused + path: src/Traits/HasApiLogs.php diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..93061b6 --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "laravel" +} diff --git a/src/Models/ApiLog.php b/src/Models/ApiLog.php index 4d51f73..143b825 100644 --- a/src/Models/ApiLog.php +++ b/src/Models/ApiLog.php @@ -8,7 +8,7 @@ class ApiLog extends Model { /** - * @inheritdoc + * {@inheritdoc} */ protected $fillable = [ 'duration', diff --git a/src/Support/Redactor.php b/src/Support/Redactor.php index 1b48434..b14d56a 100644 --- a/src/Support/Redactor.php +++ b/src/Support/Redactor.php @@ -10,7 +10,7 @@ class Redactor */ public static function redact(array $data, array $keys, string $replacement): array { - return static::apply($data, static::lookup($keys), $replacement); + return self::apply($data, self::lookup($keys), $replacement); } /** @@ -19,7 +19,7 @@ public static function redact(array $data, array $keys, string $replacement): ar */ public static function redactHeaders(array $headers, array $names, string $replacement): array { - $lookup = static::lookup($names); + $lookup = self::lookup($names); foreach ($headers as $name => $values) { if (isset($lookup[strtolower((string) $name)])) { @@ -36,7 +36,7 @@ private static function apply(array $data, array $lookup, string $replacement): if (isset($lookup[strtolower((string) $key)])) { $data[$key] = $replacement; } elseif (is_array($value)) { - $data[$key] = static::apply($value, $lookup, $replacement); + $data[$key] = self::apply($value, $lookup, $replacement); } }