-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DX: Progress output refactor (#6848)
- Loading branch information
Showing
14 changed files
with
327 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Console\Output; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class OutputContext | ||
{ | ||
private ?OutputInterface $output; | ||
private int $terminalWidth; | ||
private int $filesCount; | ||
|
||
public function __construct( | ||
?OutputInterface $output, | ||
int $terminalWidth, | ||
int $filesCount | ||
) { | ||
$this->output = $output; | ||
$this->terminalWidth = $terminalWidth; | ||
$this->filesCount = $filesCount; | ||
} | ||
|
||
public function getOutput(): ?OutputInterface | ||
{ | ||
return $this->output; | ||
} | ||
|
||
public function getTerminalWidth(): int | ||
{ | ||
return $this->terminalWidth; | ||
} | ||
|
||
public function getFilesCount(): int | ||
{ | ||
return $this->filesCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Console\Output\Progress; | ||
|
||
use PhpCsFixer\Console\Output\OutputContext; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ProgressOutputFactory | ||
{ | ||
public function create(string $outputType, OutputContext $context): ProgressOutputInterface | ||
{ | ||
if (null === $context->getOutput()) { | ||
$outputType = ProgressOutputType::NONE; | ||
} | ||
|
||
if (!$this->isBuiltInType($outputType)) { | ||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'Something went wrong, "%s" output type is not supported', | ||
$outputType | ||
) | ||
); | ||
} | ||
|
||
return ProgressOutputType::NONE === $outputType | ||
? new NullOutput() | ||
: new DotsOutput($context); | ||
} | ||
|
||
private function isBuiltInType(string $outputType): bool | ||
{ | ||
return \in_array($outputType, [ | ||
ProgressOutputType::NONE, | ||
ProgressOutputType::DOTS, | ||
], true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.