adachsoft / phpstan-runner-lib
Run PHPStan from PHP and parse its JSON output into structured result DTOs.
Requires
- php: >=8.3
- adachsoft/collection: ^3.0
- adachsoft/command-executor-lib: ^2.0
- adachsoft/normalized-safe-path: ^0.1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.2
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
- rector/rector: ^2.3
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 17:21:38 UTC
README
A PHP library for running PHPStan against paths inside a project and working with its JSON results as structured DTOs. It provides a runner interface, configurable executable and timeout, safe path normalization, and collections of per-file issues.
Features
- Run PHPStan through an injected command executor.
- Parse PHPStan JSON output into result and file-issue DTOs.
- Inspect issue identifiers and retrieve unique affected files.
- Inject a custom command executor for integration with different execution environments.
Installation
composer require adachsoft/phpstan-runner-lib
The library expects PHPStan to be available in the target project's vendor/bin/phpstan by default. Configure a different executable path with PhpStanRunnerConfigDto if needed.
Basic usage
<?php
declare(strict_types=1);
use AdachSoft\CommandExecutorLib\SimpleCommandExecutor;
use AdachSoft\PhpStanRunnerLib\Config\PhpStanRunnerConfigDto;
use AdachSoft\PhpStanRunnerLib\Dto\RunPhpStanRequestDto;
use AdachSoft\PhpStanRunnerLib\PhpStanRunnerFactory;
$projectRoot = dirname(__DIR__);
$runner = PhpStanRunnerFactory::create(
new PhpStanRunnerConfigDto(
basePath: $projectRoot,
phpStanPath: 'vendor/bin/phpstan',
defaultTimeout: 60,
),
new SimpleCommandExecutor(),
);
$result = $runner->run(new RunPhpStanRequestDto(path: 'src'));
if (!$result->success) {
foreach ($result->fileIssues->all() as $issue) {
printf("%s:%d: %s\n", $issue->file, $issue->line, $issue->message);
}
}
Request paths are resolved relative to basePath and normalized as safe paths before PHPStan is invoked. See the usage example for additional result handling.