fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -16,14 +16,12 @@ namespace Symfony\Component\Console\Output;
*/
class BufferedOutput extends Output
{
private $buffer = '';
private string $buffer = '';
/**
* Empties buffer and returns its content.
*
* @return string
*/
public function fetch()
public function fetch(): string
{
$content = $this->buffer;
$this->buffer = '';

View File

@@ -30,7 +30,7 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface;
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
{
private $stderr;
private $consoleSectionOutputs = [];
private array $consoleSectionOutputs = [];
/**
* @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
@@ -94,7 +94,7 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
/**
* {@inheritdoc}
*/
public function getErrorOutput()
public function getErrorOutput(): OutputInterface
{
return $this->stderr;
}
@@ -110,10 +110,8 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
/**
* Returns true if current environment supports writing console output to
* STDOUT.
*
* @return bool
*/
protected function hasStdoutSupport()
protected function hasStdoutSupport(): bool
{
return false === $this->isRunningOS400();
}
@@ -121,10 +119,8 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
/**
* Returns true if current environment supports writing console output to
* STDERR.
*
* @return bool
*/
protected function hasStderrSupport()
protected function hasStderrSupport(): bool
{
return false === $this->isRunningOS400();
}

View File

@@ -21,10 +21,8 @@ interface ConsoleOutputInterface extends OutputInterface
{
/**
* Gets the OutputInterface for errors.
*
* @return OutputInterface
*/
public function getErrorOutput();
public function getErrorOutput(): OutputInterface;
public function setErrorOutput(OutputInterface $error);

View File

@@ -21,9 +21,9 @@ use Symfony\Component\Console\Terminal;
*/
class ConsoleSectionOutput extends StreamOutput
{
private $content = [];
private $lines = 0;
private $sections;
private array $content = [];
private int $lines = 0;
private array $sections;
private $terminal;
/**
@@ -63,10 +63,8 @@ class ConsoleSectionOutput extends StreamOutput
/**
* Overwrites the previous output with a new message.
*
* @param array|string $message
*/
public function overwrite($message)
public function overwrite(string|iterable $message)
{
$this->clear();
$this->writeln($message);

View File

@@ -37,13 +37,10 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function getFormatter()
public function getFormatter(): OutputFormatterInterface
{
if ($this->formatter) {
return $this->formatter;
}
// to comply with the interface we must return a OutputFormatterInterface
return $this->formatter = new NullOutputFormatter();
return $this->formatter ??= new NullOutputFormatter();
}
/**
@@ -57,7 +54,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function isDecorated()
public function isDecorated(): bool
{
return false;
}
@@ -73,7 +70,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function getVerbosity()
public function getVerbosity(): int
{
return self::VERBOSITY_QUIET;
}
@@ -81,7 +78,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function isQuiet()
public function isQuiet(): bool
{
return true;
}
@@ -89,7 +86,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function isVerbose()
public function isVerbose(): bool
{
return false;
}
@@ -97,7 +94,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function isVeryVerbose()
public function isVeryVerbose(): bool
{
return false;
}
@@ -105,7 +102,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function isDebug()
public function isDebug(): bool
{
return false;
}
@@ -113,7 +110,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function writeln($messages, int $options = self::OUTPUT_NORMAL)
public function writeln(string|iterable $messages, int $options = self::OUTPUT_NORMAL)
{
// do nothing
}
@@ -121,7 +118,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)
public function write(string|iterable $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)
{
// do nothing
}

View File

@@ -29,7 +29,7 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface;
*/
abstract class Output implements OutputInterface
{
private $verbosity;
private int $verbosity;
private $formatter;
/**
@@ -55,7 +55,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function getFormatter()
public function getFormatter(): OutputFormatterInterface
{
return $this->formatter;
}
@@ -71,7 +71,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function isDecorated()
public function isDecorated(): bool
{
return $this->formatter->isDecorated();
}
@@ -87,7 +87,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function getVerbosity()
public function getVerbosity(): int
{
return $this->verbosity;
}
@@ -95,7 +95,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function isQuiet()
public function isQuiet(): bool
{
return self::VERBOSITY_QUIET === $this->verbosity;
}
@@ -103,7 +103,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function isVerbose()
public function isVerbose(): bool
{
return self::VERBOSITY_VERBOSE <= $this->verbosity;
}
@@ -111,7 +111,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function isVeryVerbose()
public function isVeryVerbose(): bool
{
return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
}
@@ -119,7 +119,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function isDebug()
public function isDebug(): bool
{
return self::VERBOSITY_DEBUG <= $this->verbosity;
}
@@ -127,7 +127,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function writeln($messages, int $options = self::OUTPUT_NORMAL)
public function writeln(string|iterable $messages, int $options = self::OUTPUT_NORMAL)
{
$this->write($messages, true, $options);
}
@@ -135,7 +135,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)
public function write(string|iterable $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)
{
if (!is_iterable($messages)) {
$messages = [$messages];

View File

@@ -33,19 +33,17 @@ interface OutputInterface
/**
* Writes a message to the output.
*
* @param string|iterable $messages The message as an iterable of strings or a single string
* @param bool $newline Whether to add a newline
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
* @param $newline Whether to add a newline
* @param $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public function write($messages, bool $newline = false, int $options = 0);
public function write(string|iterable $messages, bool $newline = false, int $options = 0);
/**
* Writes a message to the output and adds a newline at the end.
*
* @param string|iterable $messages The message as an iterable of strings or a single string
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
* @param $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public function writeln($messages, int $options = 0);
public function writeln(string|iterable $messages, int $options = 0);
/**
* Sets the verbosity of the output.
@@ -54,38 +52,28 @@ interface OutputInterface
/**
* Gets the current verbosity of the output.
*
* @return int
*/
public function getVerbosity();
public function getVerbosity(): int;
/**
* Returns whether verbosity is quiet (-q).
*
* @return bool
*/
public function isQuiet();
public function isQuiet(): bool;
/**
* Returns whether verbosity is verbose (-v).
*
* @return bool
*/
public function isVerbose();
public function isVerbose(): bool;
/**
* Returns whether verbosity is very verbose (-vv).
*
* @return bool
*/
public function isVeryVerbose();
public function isVeryVerbose(): bool;
/**
* Returns whether verbosity is debug (-vvv).
*
* @return bool
*/
public function isDebug();
public function isDebug(): bool;
/**
* Sets the decorated flag.
@@ -94,17 +82,13 @@ interface OutputInterface
/**
* Gets the decorated flag.
*
* @return bool
*/
public function isDecorated();
public function isDecorated(): bool;
public function setFormatter(OutputFormatterInterface $formatter);
/**
* Returns current output formatter instance.
*
* @return OutputFormatterInterface
*/
public function getFormatter();
public function getFormatter(): OutputFormatterInterface;
}

View File

@@ -91,7 +91,7 @@ class StreamOutput extends Output
*
* @return bool true if the stream supports colorization, false otherwise
*/
protected function hasColorSupport()
protected function hasColorSupport(): bool
{
// Follow https://no-color.org/
if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) {

View File

@@ -21,8 +21,8 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface;
*/
class TrimmedBufferOutput extends Output
{
private $maxLength;
private $buffer = '';
private int $maxLength;
private string $buffer = '';
public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null)
{
@@ -36,10 +36,8 @@ class TrimmedBufferOutput extends Output
/**
* Empties buffer and returns its content.
*
* @return string
*/
public function fetch()
public function fetch(): string
{
$content = $this->buffer;
$this->buffer = '';