mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 10:43:35 +01:00
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\Composer\Rector;
|
|
|
|
use Rector\Composer\Contract\Rector\ComposerRectorInterface;
|
|
use Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
|
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|
|
|
/**
|
|
* @see \Rector\Tests\Composer\Rector\RemovePackageComposerRector\RemovePackageComposerRectorTest
|
|
*/
|
|
final class RemovePackageComposerRector implements ComposerRectorInterface
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
public const PACKAGE_NAMES = 'package_names';
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
private $packageNames = [];
|
|
|
|
public function refactor(ComposerJson $composerJson): void
|
|
{
|
|
foreach ($this->packageNames as $packageName) {
|
|
$composerJson->removePackage($packageName);
|
|
}
|
|
}
|
|
|
|
public function getRuleDefinition(): RuleDefinition
|
|
{
|
|
return new RuleDefinition('Remove package from "require" and "require-dev" in `composer.json`', [new ConfiguredCodeSample(
|
|
<<<'CODE_SAMPLE'
|
|
{
|
|
"require": {
|
|
"symfony/console": "^3.4"
|
|
}
|
|
}
|
|
CODE_SAMPLE
|
|
,
|
|
<<<'CODE_SAMPLE'
|
|
{
|
|
}
|
|
CODE_SAMPLE
|
|
,
|
|
[
|
|
self::PACKAGE_NAMES => ['symfony/console'],
|
|
]
|
|
),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, string[]> $configuration
|
|
*/
|
|
public function configure(array $configuration): void
|
|
{
|
|
$this->packageNames = $configuration[self::PACKAGE_NAMES] ?? [];
|
|
}
|
|
}
|