Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db12bb6

Browse files
committed
fixed CS, simplified code
1 parent 4639345 commit db12bb6

File tree

6 files changed

+112
-263
lines changed

6 files changed

+112
-263
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
3636
use Symfony\Component\Console\Exception\CommandNotFoundException;
3737
use Symfony\Component\Console\Exception\LogicException;
38-
use Symfony\Component\Console\Terminal\TerminalDimensionsProvider;
38+
use Symfony\Component\Console\Terminal;
3939
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4040

4141
/**
@@ -65,23 +65,18 @@ class Application
6565
private $definition;
6666
private $helperSet;
6767
private $dispatcher;
68+
private $terminal;
6869
private $defaultCommand;
6970

7071
/**
71-
* @var TerminalDimensionsProvider
72+
* @param string $name The name of the application
73+
* @param string $version The version of the application
7274
*/
73-
private $terminalDimensionsProvider;
74-
75-
/**
76-
* @param string $name The name of the application
77-
* @param string $version The version of the application
78-
* @param TerminalDimensionsProvider $terminalDimensionsProvider
79-
*/
80-
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', TerminalDimensionsProvider $terminalDimensionsProvider = null)
75+
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
8176
{
8277
$this->name = $name;
8378
$this->version = $version;
84-
$this->terminalDimensionsProvider = $terminalDimensionsProvider ?: new TerminalDimensionsProvider();
79+
$this->terminal = new Terminal();
8580
$this->defaultCommand = 'list';
8681
$this->helperSet = $this->getDefaultHelperSet();
8782
$this->definition = $this->getDefaultInputDefinition();
@@ -688,7 +683,7 @@ public function renderException(\Exception $e, OutputInterface $output)
688683
*/
689684
protected function getTerminalWidth()
690685
{
691-
return $this->terminalDimensionsProvider->getTerminalWidth();
686+
return $this->terminal->getWidth();
692687
}
693688

694689
/**
@@ -698,7 +693,7 @@ protected function getTerminalWidth()
698693
*/
699694
protected function getTerminalHeight()
700695
{
701-
return $this->terminalDimensionsProvider->getTerminalWidth();
696+
return $this->terminal->getHeight();
702697
}
703698

704699
/**
@@ -708,7 +703,7 @@ protected function getTerminalHeight()
708703
*/
709704
public function getTerminalDimensions()
710705
{
711-
return $this->terminalDimensionsProvider->getTerminalDimensions();
706+
return $this->terminal->getDimensions();
712707
}
713708

714709
/**
@@ -723,7 +718,7 @@ public function getTerminalDimensions()
723718
*/
724719
public function setTerminalDimensions($width, $height)
725720
{
726-
$this->terminalDimensionsProvider->setTerminalDimensions($width, $height);
721+
$this->terminal->setDimensions($width, $height);
727722

728723
return $this;
729724
}

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\Console\Exception\LogicException;
17-
use Symfony\Component\Console\Terminal\TerminalDimensionsProvider;
17+
use Symfony\Component\Console\Terminal;
1818

1919
/**
2020
* The ProgressBar provides helpers to display progress output.
@@ -45,29 +45,24 @@ class ProgressBar
4545
private $formatLineCount;
4646
private $messages;
4747
private $overwrite = true;
48+
private $terminal;
4849

4950
private static $formatters;
5051
private static $formats;
5152

5253
/**
53-
* @var TerminalDimensionsProvider
54+
* @param OutputInterface $output An OutputInterface instance
55+
* @param int $max Maximum steps (0 if unknown)
5456
*/
55-
private $terminalDimensionsProvider;
56-
57-
/**
58-
* @param OutputInterface $output An OutputInterface instance
59-
* @param int $max Maximum steps (0 if unknown)
60-
* @param TerminalDimensionsProvider $terminalDimensionsProvider
61-
*/
62-
public function __construct(OutputInterface $output, $max = 0, TerminalDimensionsProvider $terminalDimensionsProvider = null)
57+
public function __construct(OutputInterface $output, $max = 0)
6358
{
6459
if ($output instanceof ConsoleOutputInterface) {
6560
$output = $output->getErrorOutput();
6661
}
6762

6863
$this->output = $output;
6964
$this->setMaxSteps($max);
70-
$this->terminalDimensionsProvider = $terminalDimensionsProvider ?: new TerminalDimensionsProvider();
65+
$this->terminal = new Terminal();
7166

7267
if (!$this->output->isDecorated()) {
7368
// disable overwrite when output does not support ANSI codes.
@@ -433,6 +428,20 @@ public function clear()
433428
$this->overwrite('');
434429
}
435430

431+
/**
432+
* Gets the terminal.
433+
*
434+
* Can be useful to force terminal dimensions for functional tests.
435+
*
436+
* @return Terminal
437+
*
438+
* @internal
439+
*/
440+
public function getTerminal()
441+
{
442+
return $this->terminal;
443+
}
444+
436445
/**
437446
* Sets the progress bar format.
438447
*
@@ -607,7 +616,7 @@ private function buildLine()
607616
private function adjustLineWidthToTerminalWidth($line)
608617
{
609618
$lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
610-
$terminalWidth = $this->terminalDimensionsProvider->getTerminalWidth();
619+
$terminalWidth = $this->terminal->getWidth();
611620
if ($lineLength > $terminalWidth) {
612621
$newBarWidth = $this->barWidth - $lineLength + $terminalWidth;
613622
$this->setBarWidth($newBarWidth);

src/Symfony/Component/Console/Terminal/TerminalDimensionsProvider.php

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)