Search by

adachsoft / phpstan-runner-lib

Arkadiusz Adach

Run PHPStan from PHP and parse its JSON output into structured result DTOs.

Package info

gitlab.com/a.adach/phpstan-runner-lib

Issues

pkg:composer/adachsoft/phpstan-runner-lib

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-11 18:04 UTC

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.