Skip to content

Commit

Permalink
Inject iointerface instead of factory
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbentley committed Sep 29, 2023
1 parent 841c7f8 commit 60d09e2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
6 changes: 3 additions & 3 deletions resources/config/console.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
- '@GrumPHP\Locator\StdInFiles'
- '@GrumPHP\Locator\RegisteredFiles'
- '@GrumPHP\Runner\TaskRunner'
- '@GrumPHP\IO\IOFactory'
- '@GrumPHP\IO\IOInterface'
tags:
- { name: 'console.command' }
GrumPHP\Console\Command\Git\CommitMsgCommand:
Expand All @@ -39,7 +39,7 @@ services:
- '@GrumPHP\Runner\TaskRunner'
- '@grumphp.util.filesystem'
- '@GrumPHP\Util\Paths'
- '@GrumPHP\IO\IOFactory'
- '@GrumPHP\IO\IOInterface'
tags:
- { name: 'console.command' }
GrumPHP\Console\Command\Git\DeInitCommand:
Expand All @@ -62,7 +62,7 @@ services:
- '@GrumPHP\Locator\StdInFiles'
- '@GrumPHP\Locator\ChangedFiles'
- '@GrumPHP\Runner\TaskRunner'
- '@GrumPHP\IO\IOFactory'
- '@GrumPHP\IO\IOInterface'
tags:
- { name: 'console.command' }

Expand Down
4 changes: 3 additions & 1 deletion resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ services:
- '@OndraM\CiDetector\CiDetector'

grumphp.io:
class: GrumPHP\IO\IOInterface
alias: GrumPHP\IO\IOInterface

GrumPHP\IO\IOInterface:
factory: ['@GrumPHP\IO\IOFactory', 'create']
arguments:
- '@console.input'
Expand Down
13 changes: 6 additions & 7 deletions src/Console/Command/Git/CommitMsgCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CommitMsgCommand extends Command
*/
private $paths;

private IOFactory $IOFactory;
private IOInterface $io;

public function __construct(
TestSuiteCollection $testSuites,
Expand All @@ -70,7 +70,7 @@ public function __construct(
TaskRunner $taskRunner,
Filesystem $filesystem,
Paths $paths,
IOFactory $IOFactory
IOInterface $io
) {
parent::__construct();

Expand All @@ -80,7 +80,7 @@ public function __construct(
$this->filesystem = $filesystem;
$this->paths = $paths;
$this->stdInFilesLocator = $stdInFilesLocator;
$this->IOFactory = $IOFactory;
$this->io = $io;
}

public static function getDefaultName(): string
Expand All @@ -98,8 +98,7 @@ protected function configure(): void

public function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->IOFactory->create($input, $output);
$files = $this->getCommittedFiles($io);
$files = $this->getCommittedFiles();

/** @var string $gitUser */
$gitUser = $input->getOption('git-user');
Expand Down Expand Up @@ -129,9 +128,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
return $results->isFailed() ? self::EXIT_CODE_NOK : self::EXIT_CODE_OK;
}

protected function getCommittedFiles(IOInterface $io): FilesCollection
protected function getCommittedFiles(): FilesCollection
{
if ($stdin = $io->readCommandInput(STDIN)) {
if ($stdin = $this->io->readCommandInput(STDIN)) {
return $this->stdInFilesLocator->locate($stdin);
}

Expand Down
13 changes: 6 additions & 7 deletions src/Console/Command/Git/PreCommitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ class PreCommitCommand extends Command
*/
private $taskRunner;

private IOFactory $IOFactory;
private IOInterface $io;

public function __construct(
TestSuiteCollection $testSuites,
StdInFiles $stdInFilesLocator,
ChangedFiles $changedFilesLocator,
TaskRunner $taskRunner,
IOFactory $IOFactory
IOInterface $io
) {
parent::__construct();

$this->testSuites = $testSuites;
$this->stdInFilesLocator = $stdInFilesLocator;
$this->changedFilesLocator = $changedFilesLocator;
$this->taskRunner = $taskRunner;
$this->IOFactory = $IOFactory;
$this->io = $io;
}

public static function getDefaultName(): string
Expand All @@ -83,8 +83,7 @@ protected function configure(): void

public function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->IOFactory->create($input, $output);
$files = $this->getCommittedFiles($io);
$files = $this->getCommittedFiles();

$context = (
new TaskRunnerContext(
Expand All @@ -100,9 +99,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
return $results->isFailed() ? self::EXIT_CODE_NOK : self::EXIT_CODE_OK;
}

protected function getCommittedFiles(IOInterface $io): FilesCollection
protected function getCommittedFiles(): FilesCollection
{
if ($stdin = $io->readCommandInput(STDIN)) {
if ($stdin = $this->io->readCommandInput(STDIN)) {
return $this->stdInFilesLocator->locate($stdin);
}

Expand Down
14 changes: 6 additions & 8 deletions src/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ class RunCommand extends Command
*/
private $taskRunner;

private IOFactory $IOFactory;
private IOInterface $io;

public function __construct(
TestSuiteCollection $testSuites,
StdInFiles $stdInFileLocator,
RegisteredFiles $registeredFilesLocator,
TaskRunner $taskRunner,
IOFactory $IOFactory
IOInterface $io
) {
parent::__construct();

$this->testSuites = $testSuites;
$this->stdInFileLocator = $stdInFileLocator;
$this->registeredFilesLocator = $registeredFilesLocator;
$this->taskRunner = $taskRunner;
$this->IOFactory = $IOFactory;
$this->io = $io;
}

public static function getDefaultName(): string
Expand Down Expand Up @@ -88,15 +88,13 @@ protected function configure(): void

public function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->IOFactory->create($input, $output);

/** @var string $taskNames */
$taskNames = $input->getOption('tasks') ?? '';

/** @var string $testsSuite */
$testsSuite = $input->getOption('testsuite') ?? '';

$files = $this->detectFiles($io);
$files = $this->detectFiles();
$tasks = Str::explodeWithCleanup(',', $taskNames);

$context = new TaskRunnerContext(
Expand All @@ -112,9 +110,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
return $results->isFailed() ? self::EXIT_CODE_NOK : self::EXIT_CODE_OK;
}

private function detectFiles(IOInterface $io): FilesCollection
private function detectFiles(): FilesCollection
{
if ($stdin = $io->readCommandInput(STDIN)) {
if ($stdin = $this->io->readCommandInput(STDIN)) {
return $this->stdInFileLocator->locate($stdin);
}

Expand Down

0 comments on commit 60d09e2

Please sign in to comment.