Search by

adachsoft / code-operations-php

Arkadiusz Adach

PHP implementation for validating, testing and running Composer projects with configurable PHP runtimes.

Package info

gitlab.com/a.adach/code-operations-php

Issues

pkg:composer/adachsoft/code-operations-php

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.1 2026-12-01 21:49 UTC

This package is auto-updated.

Last update: 2026-12-01 20:50:07 UTC


README

A PHP 8.3+ implementation of adachsoft/code-operations-contracts for validating, testing and running Composer projects.

The implementation delegates runtime discovery to adachsoft/php-interpreter-resolver, PHPUnit execution and issue parsing to adachsoft/phpunit-runner-lib, and PHPStan execution and issue parsing to adachsoft/phpstan-runner-lib.

Requirements

  • PHP 8.3 or later.
  • Composer.

Installation

composer require adachsoft/code-operations-php

Usage

Create the library runners with their factories and inject them into the PHP implementation:

<?php

declare(strict_types=1);

use AdachSoft\CodeOperationsContracts\ExecutionContextDto;
use AdachSoft\CodeOperationsContracts\RuntimeVo;
use AdachSoft\CodeOperationsPhp\PhpCodeOperations;
use AdachSoft\CodeOperationsPhp\PhpRuntimeResolver;
use AdachSoft\CommandExecutorLib\SimpleCommandExecutor;
use AdachSoft\CommandExecutorLib\SimpleCommandRunner;
use AdachSoft\PhpInterpreterResolver\PhpInterpreterResolverFactory;
use AdachSoft\PhpStanRunnerLib\Config\PhpStanRunnerConfigDto;
use AdachSoft\PhpStanRunnerLib\PhpStanRunnerFactory;
use AdachSoft\PhpUnitRunnerLib\Config\PhpUnitRunnerConfigDto;
use AdachSoft\PhpUnitRunnerLib\PhpUnitRunnerFactory;

$projectPath = getcwd();
$commandExecutor = new SimpleCommandExecutor();
$commandRunner = new SimpleCommandRunner();

$interpreterResolver = PhpInterpreterResolverFactory::create($commandExecutor, $projectPath);
$runtimeResolver = new PhpRuntimeResolver($interpreterResolver);
$phpUnitRunner = PhpUnitRunnerFactory::create(
    new PhpUnitRunnerConfigDto($projectPath),
    $commandExecutor,
);
$phpStanRunner = PhpStanRunnerFactory::create(
    new PhpStanRunnerConfigDto($projectPath),
    $commandExecutor,
);
$operations = new PhpCodeOperations($runtimeResolver, $commandRunner, $phpUnitRunner, $phpStanRunner);

$context = new ExecutionContextDto(
    projectPath: $projectPath,
    runtime: new RuntimeVo('php', '8.3'),
);
$result = $operations->validate($context);

Runtime selection

  • An explicit runtime version selects the highest available logical version beginning with the requested prefix.
  • Without an explicit version, the resolver reads require.php from the project's composer.json and selects the highest available version satisfying that Composer constraint, using composer/semver.
  • Without an explicit version or Composer PHP constraint, the resolver selects the version marked as current by php-interpreter-resolver.
  • If interpreter discovery returns no versions or cannot query the system, the resolver uses PHP_BINARY and PHP_VERSION as its only available runtime.

Validation

validate() runs PHP's syntax checker for PHP files under the requested paths, or under src/ and tests/ when no paths are provided. It excludes vendor/ from linting.

When the project has phpstan.neon or phpstan.neon.dist and vendor/bin/phpstan exists, validation also runs PHPStan. Requested paths are analyzed individually; without requested paths, PHPStan analyzes the project root. Validation succeeds only when linting succeeds and PHPStan reports no errors.

PHPUnit tests

test() uses phpunit-runner-lib for execution and structured diagnostics. It accepts an optional PHPUnit filter and forwards the selected PHP version and timeout. Since the library request accepts one path, only the first requested path is passed to PHPUnit; if no path is provided, PHPUnit runs its configured suite.

Running a target

run() executes the requested target with the resolved PHP interpreter and the supplied arguments.