From 892545c3011cff19f4611c8570fec2b3a066bfd8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 14 Dec 2025 11:55:26 +0100 Subject: [PATCH 1/3] make use of entropy container --- bin/monitor.php | 4 +- composer.json | 2 +- .../TooLowPackagesRulesProcessor.php | 2 +- .../DependencyInjection/ContainerFactory.php | 61 ------------------- src/DependencyInjection/ContainerFactory.php | 55 ++++++----------- tests/AbstractTestCase.php | 2 +- 6 files changed, 22 insertions(+), 104 deletions(-) delete mode 100644 src/Compare/DependencyInjection/ContainerFactory.php diff --git a/bin/monitor.php b/bin/monitor.php index 65977be..f44a2a6 100755 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -2,8 +2,8 @@ declare(strict_types=1); +use Rector\Monitor\Console\MonitorConsoleApplication; use Rector\Monitor\DependencyInjection\ContainerFactory; -use Symfony\Component\Console\Application; $scoperAutoloadFilepath = __DIR__ . '/../vendor/scoper-autoload.php'; if (file_exists($scoperAutoloadFilepath)) { @@ -30,5 +30,5 @@ $containerFactory = new ContainerFactory(); $container = $containerFactory->create(); -$application = $container->make(Application::class); +$application = $container->make(MonitorConsoleApplication::class); exit($application->run()); diff --git a/composer.json b/composer.json index b73d570..b09e1ec 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": ">=8.3", "composer/semver": "^3.4", - "illuminate/container": "12.40.*", + "entropy/entropy": "dev-main", "nette/neon": "^3.4", "nette/utils": "^4.1", "symfony/console": "^6.4", diff --git a/src/Analyze/RuleProcessor/TooLowPackagesRulesProcessor.php b/src/Analyze/RuleProcessor/TooLowPackagesRulesProcessor.php index 1b4900d..edd7ccc 100644 --- a/src/Analyze/RuleProcessor/TooLowPackagesRulesProcessor.php +++ b/src/Analyze/RuleProcessor/TooLowPackagesRulesProcessor.php @@ -11,7 +11,7 @@ use Rector\Monitor\ValueObject\ComposerJson; /** - * @see \Rector\Monitor\Tests\RuleProcessor\TooLowPackagesRulesProcessor\TooLowPackagesRulesProcessorTest + * @see \Rector\Monitor\Tests\Analyze\RuleProcessor\TooLowPackagesRulesProcessor\TooLowPackagesRulesProcessorTest */ final class TooLowPackagesRulesProcessor implements RuleProcessorInterface { diff --git a/src/Compare/DependencyInjection/ContainerFactory.php b/src/Compare/DependencyInjection/ContainerFactory.php deleted file mode 100644 index cc29e15..0000000 --- a/src/Compare/DependencyInjection/ContainerFactory.php +++ /dev/null @@ -1,61 +0,0 @@ -singleton( - SymfonyStyle::class, - static function (): SymfonyStyle { - // use null output ofr tests to avoid printing - $consoleOutput = defined('PHPUNIT_COMPOSER_INSTALL') ? new NullOutput() : new ConsoleOutput(); - return new SymfonyStyle(new ArrayInput([]), $consoleOutput); - } - ); - - $container->singleton(Application::class, function (Container $container): Application { - /** @var CompareProjectsCommand $compareProjectsCommand */ - $compareProjectsCommand = $container->make(CompareProjectsCommand::class); - - $application = new Application(); - $application->add($compareProjectsCommand); - - $this->hideDefaultCommands($application); - - return $application; - }); - - return $container; - } - - /** - * @see https://tomasvotruba.com/blog/how-make-your-tool-commands-list-easy-to-read - */ - private function hideDefaultCommands(Application $application): void - { - $application->get('completion') - ->setHidden(); - $application->get('help') - ->setHidden(); - } -} diff --git a/src/DependencyInjection/ContainerFactory.php b/src/DependencyInjection/ContainerFactory.php index 11215d2..bb18962 100644 --- a/src/DependencyInjection/ContainerFactory.php +++ b/src/DependencyInjection/ContainerFactory.php @@ -4,19 +4,12 @@ namespace Rector\Monitor\DependencyInjection; -use Illuminate\Container\Container; -use Rector\Monitor\Analyze\Command\AnalyzeCommand; +use Entropy\Container\Container; use Rector\Monitor\Compare\Command\CompareProjectsCommand; -use Rector\Monitor\Compare\Comparator\ComposerAutoloadComparator; -use Rector\Monitor\Compare\Comparator\MutuallyMissingPackagesComparator; -use Rector\Monitor\Compare\Comparator\PHPStanExtensionsComparator; -use Rector\Monitor\Compare\Comparator\PHPStanLevelComparator; -use Rector\Monitor\Compare\Comparator\PHPStanPathsComparator; -use Rector\Monitor\Compare\Comparator\SymfonyConfigFilesComparator; use Rector\Monitor\Compare\Contract\ComparatorInterface; use Rector\Monitor\Console\MonitorConsoleApplication; -use Rector\Monitor\Matrix\Command\MatrixCommand; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Style\SymfonyStyle; @@ -30,17 +23,13 @@ public function create(): Container { $container = new Container(); - // console - $container->singleton(Application::class, function (Container $container): MonitorConsoleApplication { + $container->service(MonitorConsoleApplication::class, function ( + Container $container + ): MonitorConsoleApplication { $monitorConsoleApplication = new MonitorConsoleApplication('Rector Monitor'); - $commandClasses = [AnalyzeCommand::class, MatrixCommand::class, CompareProjectsCommand::class]; - - // register commands - foreach ($commandClasses as $commandClass) { - $command = $container->make($commandClass); - $monitorConsoleApplication->add($command); - } + $commands = $container->findByContract(Command::class); + $monitorConsoleApplication->addCommands($commands); // remove basic command to make output clear $this->hideDefaultCommands($monitorConsoleApplication); @@ -48,18 +37,17 @@ public function create(): Container return $monitorConsoleApplication; }); - $this->registerComparator($container, ComposerAutoloadComparator::class); - $this->registerComparator($container, MutuallyMissingPackagesComparator::class); - $this->registerComparator($container, SymfonyConfigFilesComparator::class); - $this->registerComparator($container, PHPStanExtensionsComparator::class); - $this->registerComparator($container, PHPStanPathsComparator::class); - $this->registerComparator($container, PHPStanLevelComparator::class); - - $container->when(CompareProjectsCommand::class) - ->needs('$comparators') - ->giveTagged(ComparatorInterface::class); + $container->service( + CompareProjectsCommand::class, + function (Container $container): CompareProjectsCommand { + return new CompareProjectsCommand( + $container->make(SymfonyStyle::class), + $container->findByContract(ComparatorInterface::class) + ); + } + ); - $container->singleton( + $container->service( SymfonyStyle::class, static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()) ); @@ -76,13 +64,4 @@ public function hideDefaultCommands(Application $application): void $application->get('help') ->setHidden(true); } - - /** - * @param class-string $comparatorClass - */ - private function registerComparator(Container $container, string $comparatorClass): void - { - $container->singleton($comparatorClass); - $container->tag($comparatorClass, ComparatorInterface::class); - } } diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 77bcb2f..7b10d32 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -4,7 +4,7 @@ namespace Rector\Monitor\Tests; -use Illuminate\Container\Container; +use Entropy\Container\Container; use PHPUnit\Framework\TestCase; use Rector\Monitor\DependencyInjection\ContainerFactory; From 845dea6b4687cba6a2223c398a90a74b05c46a89 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 14 Dec 2025 14:03:56 +0100 Subject: [PATCH 2/3] fixup! make use of entropy container --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b09e1ec..54c74a8 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ "entropy/entropy": "dev-main", "nette/neon": "^3.4", "nette/utils": "^4.1", - "symfony/console": "^6.4", "symfony/filesystem": "^7.4", + "symfony/console": "^6.4", "symfony/finder": "^7.4", "symfony/process": "^7.4", "webmozart/assert": "^1.12" From 1c7e0aaa751113d7338e17c6c48b42aba0a21c64 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 14 Dec 2025 14:08:32 +0100 Subject: [PATCH 3/3] fixup! fixup! make use of entropy container --- .github/workflows/code_analysis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index bdaefc8..ba6ccf2 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -34,7 +34,7 @@ jobs: - name: 'Check Active Classes' - run: vendor/bin/class-leak check bin src tests --ansi + run: vendor/bin/class-leak check bin src tests --ansi --skip-type="Rector\Monitor\Compare\Contract\ComparatorInterface" - name: 'Run "Compare Projects" command'