Skip to content

Commit

Permalink
drop redundant interface and factory
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 10, 2020
1 parent a21b805 commit 595d419
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 88 deletions.
8 changes: 2 additions & 6 deletions compiler/bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
declare(strict_types = 1);

use Rector\Compiler\Console\CompileCommand;
use Rector\Compiler\Process\ProcessFactory;
use Symfony\Component\Console\Application;

require_once __DIR__ . '/../vendor/autoload.php';

$compileCommand = new CompileCommand(
new ProcessFactory(),
__DIR__ . '/../build',
__DIR__ . '/../..'
);
$compileCommand = new CompileCommand(__DIR__ . '/../build', __DIR__ . '/../..');

/** @var Application $application */

$application = new Application();
$application->add($compileCommand);
$application->setDefaultCommand($compileCommand->getName(), true);
Expand Down
25 changes: 7 additions & 18 deletions compiler/src/Console/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\FileSystem as NetteFileSystem;
use Nette\Utils\Json;
use Rector\Compiler\Process\InstantlyRunningSymfonyProcess;
use Rector\Compiler\Process\ProcessFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,21 +18,11 @@
*/
final class CompileCommand extends Command
{
/**
* @var string
*/
public const NAME = 'rector:compile';

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var ProcessFactory
*/
private $processFactory;

/**
* @var string
*/
Expand All @@ -47,37 +38,35 @@ final class CompileCommand extends Command
*/
private $originalComposerJsonFileContent;

public function __construct(ProcessFactory $processFactory, string $dataDir, string $buildDir)
public function __construct(string $dataDir, string $buildDir)
{
parent::__construct();
$this->filesystem = new Filesystem();
$this->processFactory = $processFactory;
$this->dataDir = $dataDir;
$this->buildDir = $buildDir;
}

protected function configure(): void
{
$this->setName(self::NAME);
$this->setName('rector:compile');
$this->setDescription('Compile prefixed rector.phar');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->processFactory->setOutput($output);

$composerJsonFile = $this->buildDir . '/composer.json';

$this->fixComposerJson($composerJsonFile);
// @see https://github.com/dotherightthing/wpdtrt-plugin-boilerplate/issues/52
$this->processFactory->create(
new InstantlyRunningSymfonyProcess(
['composer', 'update', '--no-dev', '--prefer-dist', '--no-interaction', '--classmap-authoritative'],
$this->buildDir
$this->buildDir,
$output
);

// the '--no-parallel' is needed, so "scoper.php.inc" can "require __DIR__ ./vendor/autoload.php"
// and "Nette\Neon\Neon" class can be used there
$this->processFactory->create(['php', 'box.phar', 'compile', '--no-parallel'], $this->dataDir);
new InstantlyRunningSymfonyProcess(['php', 'box.phar', 'compile', '--no-parallel'], $this->dataDir, $output);

$this->restoreComposerJson($composerJsonFile);

Expand Down
12 changes: 0 additions & 12 deletions compiler/src/Contract/Process/ProcessInterface.php

This file was deleted.

23 changes: 23 additions & 0 deletions compiler/src/Process/InstantlyRunningSymfonyProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Rector\Compiler\Process;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

final class InstantlyRunningSymfonyProcess
{
/**
* @param string[] $command
*/
public function __construct(array $command, string $cwd, OutputInterface $output)
{
$process = new Process($command, $cwd, null, null, null);

$process->mustRun(static function (string $type, string $buffer) use ($output): void {
$output->write($buffer);
});
}
}
21 changes: 2 additions & 19 deletions compiler/src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,15 @@

namespace Rector\Compiler\Process;

use Rector\Compiler\Contract\Process\ProcessInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

final class ProcessFactory
{
/**
* @var OutputInterface
*/
private $output;

public function __construct()
{
$this->output = new NullOutput();
}

/**
* @param string[] $command
*/
public function create(array $command, string $cwd): ProcessInterface
{
return new SymfonyProcess($command, $cwd, $this->output);
}

public function setOutput(OutputInterface $output): void
public function create(array $command, string $cwd, OutputInterface $output): InstantlyRunningSymfonyProcess
{
$this->output = $output;
return new InstantlyRunningSymfonyProcess($command, $cwd, $output);
}
}
33 changes: 0 additions & 33 deletions compiler/src/Process/SymfonyProcess.php

This file was deleted.

0 comments on commit 595d419

Please sign in to comment.