Shared formatting and static analysis configuration.
This package provides:
- dPrint formatting via a shared
dprint.json - PHPStan at level
9, with custom rules for@requires-*and@abstractmember contracts
The conventions here prioritize ergonomics over PSR alignment.
- PHP 8.4+
- Composer
- dPrint CLI
- PHPStan
2.2+
composer require --dev northrook/php-csAdd the package, then run the setup script from your project root:
composer require --dev northrook/php-cs
vendor/bin/php-cs-config.phpThe script copies the shared dprint.json, and updates composer.json:
require-devphpstan/extension-installerconfig.allow-pluginsphpstan/extension-installerscripts.phpstanvendor/bin/phpstan analysescripts.fmtdprint fmt
Pass --force to overwrite an existing dprint.json or refresh values that were already set.
Install the dPrint CLI before using composer fmt.
With phpstan/extension-installer, this package registers itself automatically.
Your project only needs a minimal phpstan.neon at the root if you want project-specific overrides.
Otherwise, PHPStan will pick up the extension config on its own.
If you prefer not to use the extension installer, include the config manually:
includes:
- vendor/northrook/php-cs/phpstan.neonThe shipped config enforces level 9, and analyses ./src and ./tests.
Run PHPStan from the project root:
composer phpstanInstall the dPrint CLI.
The setup script copies the shared config into the project.
Format PHP files:
composer fmtOr invoke dPrint directly:
dprint fmtDeclare members that implementing or extending types must provide.
Checked on concrete classes, and on interfaces themselves.
| Tag | Example |
|---|---|
@requires-const |
@requires-const STATUS_CODE |
@requires-property |
@requires-property string $name |
@requires-method |
@requires-method run(): string |
Tags can specify modifiers and types.
On concrete classes, mismatches are reported with stable identifiers (e.g.requiresMember.method.TypeMissing).
Unexpected-but-compatible modifiers/types produce ignorable warnings.
Requirements check the class's parents, interfaces, and traits.
Mark members on abstract classes or traits that every concrete descendant must redeclare.
abstract class Base
{
/** @abstract */
public const string LABEL = 'base';
/** @abstract */
protected string $name = 'base';
/** @abstract */
public function label(): string
{
return self::LABEL;
}
}A concrete class must declare its own versions of these members, inheritance alone is not enough.
The package ships .phpstorm.meta.php.
PhpStorm recognizes @requires-const, @requires-property, @requires-method, and @abstract in docblocks.
In this repository:
composer check # phpstan + phpunit
composer phpstan
composer test