adachsoft/composer-editor
A PHP library for programmatic reading and editing of composer.json files while preserving formatting and indentation. Provides a clean facade + builder pattern with integration to adachsoft/composer-json-fixer for robust JSON handling.
Requirements
- PHP: 8.3 or higher
- Dependencies:
adachsoft/composer-json-fixer - JSON parsing and formatting
adachsoft/collection - immutable collections
- Development tools (configured via
adachsoft/php-code-style):
- PHPUnit
- PHPStan
- Rector
- PHP-CS-Fixer
Installation
Install via Composer:
composer require adachsoft/composer-editor
Development tools are automatically configured through adachsoft/php-code-style.
Basic usage
use AdachSoft\ComposerEditor\PublicApi\ComposerEditorBuilder;
$builder = new ComposerEditorBuilder();
$editor = $builder->load('composer.json');
$editor->setDescription('My awesome package');
$editor->addRequire('symfony/console', '^6.0');
$editor->addKeyword('php');
$editor->save();
$dto = new CreateComposerJsonDto(
'vendor/package',
'Description goes here'
);
$newEditor = $builder->create('composer.json', $dto);
$newEditor->save();
Quality tools
Run quality checks using Composer scripts:
composer cs:check
composer cs:fix
composer stan
composer rector
License
MIT