Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
],
"require": {
"php": ">=8.3",
"illuminate/container": "12.38.*",
"nette/robot-loader": "^4.0",
"nette/utils": "^4.0",
"nikic/php-parser": "^5.5",
"entropy/entropy": "dev-main",
"nette/robot-loader": "^4.1",
"nette/utils": "^4.1",
"nikic/php-parser": "^5.7",
"symfony/console": "^6.4.24",
"symfony/finder": "^7.3",
"symfony/yaml": "^7.3",
"webmozart/assert": "^1.11"
"symfony/finder": "^7.4",
"symfony/yaml": "^7.4",
"webmozart/assert": "^1.12"
},
"require-dev": {
"symplify/easy-coding-standard": "^13.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^12.3",
"phpunit/phpunit": "^12.5",
"rector/jack": "^0.5.1",
"rector/rector": "^2.3",
"shipmonk/composer-dependency-analyser": "^1.8",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symplify/phpstan-extensions": "^12.0",
"symplify/vendor-patches": "^11.4",
"tomasvotruba/class-leak": "^2.0",
"tomasvotruba/unused-public": "^2.0",
"tracy/tracy": "^2.10"
"tomasvotruba/class-leak": "^2.1",
"tomasvotruba/unused-public": "^2.2",
"tracy/tracy": "^2.11"
},
"autoload": {
"psr-4": {
Expand All @@ -49,7 +48,6 @@
"sort-packages": true,
"platform-check": false,
"allow-plugins": {
"cweagans/composer-patches": true,
"phpstan/extension-installer": true
}
},
Expand Down
45 changes: 9 additions & 36 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Rector\SwissKnife\DependencyInjection;

use Illuminate\Container\Container;
use Entropy\Container\Container;
use PhpParser\Parser;
use PhpParser\ParserFactory;
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;
use Symfony\Component\Finder\Finder;
use Webmozart\Assert\Assert;

/**
* @api used in tests
Expand All @@ -23,17 +22,14 @@ public function create(): Container
{
$container = new Container();

$container->autodiscover(__DIR__ . '/../Command');

// console
$container->singleton(Application::class, function (Container $container): Application {
$container->service(Application::class, function (Container $container): Application {
$application = new Application('Rector Swiss Knife');

$commandClasses = $this->findCommandClasses();

// register commands
foreach ($commandClasses as $commandClass) {
$command = $container->make($commandClass);
$application->add($command);
}
$commands = $container->findByContract(Command::class);
$application->addCommands($commands);

// remove basic command to make output clear
$this->hideDefaultCommands($application);
Expand All @@ -42,12 +38,12 @@ public function create(): Container
});

// parser
$container->singleton(Parser::class, static function (): Parser {
$container->service(Parser::class, static function (): Parser {
$phpParserFactory = new ParserFactory();
return $phpParserFactory->createForNewestSupportedVersion();
});

$container->singleton(
$container->service(
SymfonyStyle::class,
static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())
);
Expand All @@ -64,27 +60,4 @@ public function hideDefaultCommands(Application $application): void
$application->get('help')
->setHidden(true);
}

/**
* @return string[]
*/
private function findCommandClasses(): array
{
$commandFinder = Finder::create()
->files()
->name('*Command.php')
->in(__DIR__ . '/../Command');

$commandClasses = [];
foreach ($commandFinder as $commandFile) {
$commandClass = 'Rector\\SwissKnife\\Command\\' . $commandFile->getBasename('.php');

// make sure it exists
Assert::classExists($commandClass);

$commandClasses[] = $commandClass;
}

return $commandClasses;
}
}
2 changes: 1 addition & 1 deletion tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\SwissKnife\Tests;

use Illuminate\Container\Container;
use Entropy\Container\Container;
use PHPUnit\Framework\TestCase;
use Rector\SwissKnife\DependencyInjection\ContainerFactory;

Expand Down