From de9a8d9180443d953e5cefc89bd164d5867851fd Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 14:51:25 +0100 Subject: [PATCH 1/2] Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value --- Application.php | 6 +++--- CI/GithubActionReporter.php | 8 ++++---- Command/Command.php | 8 ++++---- Command/LazyCommand.php | 6 +++--- Command/LockableTrait.php | 2 +- Descriptor/ApplicationDescription.php | 2 +- Descriptor/XmlDescriptor.php | 2 +- Event/ConsoleErrorEvent.php | 2 +- EventListener/ErrorListener.php | 2 +- Exception/CommandNotFoundException.php | 2 +- Formatter/NullOutputFormatterStyle.php | 4 ++-- Formatter/OutputFormatterStyle.php | 6 +++--- Formatter/OutputFormatterStyleInterface.php | 4 ++-- Formatter/OutputFormatterStyleStack.php | 4 ++-- Helper/Dumper.php | 2 +- Helper/Helper.php | 4 ++-- Helper/HelperInterface.php | 2 +- Helper/HelperSet.php | 4 ++-- Helper/ProcessHelper.php | 6 +++--- Helper/ProgressBar.php | 4 ++-- Helper/ProgressIndicator.php | 2 +- Helper/Table.php | 4 ++-- Helper/TableStyle.php | 6 +++--- Input/ArgvInput.php | 2 +- Input/ArrayInput.php | 2 +- Input/Input.php | 2 +- Input/InputArgument.php | 2 +- Input/InputOption.php | 2 +- Output/ConsoleOutput.php | 2 +- Output/ConsoleSectionOutput.php | 2 +- Output/Output.php | 2 +- Output/StreamOutput.php | 2 +- Output/TrimmedBufferOutput.php | 2 +- Question/Question.php | 4 ++-- SingleCommandApplication.php | 2 +- Style/StyleInterface.php | 4 ++-- Style/SymfonyStyle.php | 10 +++++----- Tests/CI/GithubActionReporterTest.php | 2 +- Tests/Formatter/OutputFormatterTest.php | 2 +- Tests/Helper/HelperSetTest.php | 2 +- 40 files changed, 69 insertions(+), 69 deletions(-) diff --git a/Application.php b/Application.php index 29951e9c1..bb5341882 100644 --- a/Application.php +++ b/Application.php @@ -134,7 +134,7 @@ public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent) * * @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}. */ - public function run(InputInterface $input = null, OutputInterface $output = null) + public function run(?InputInterface $input = null, ?OutputInterface $output = null) { if (\function_exists('putenv')) { @putenv('LINES='.$this->terminal->getHeight()); @@ -778,7 +778,7 @@ public function find(string $name) * * @return Command[] */ - public function all(string $namespace = null) + public function all(?string $namespace = null) { $this->init(); @@ -1147,7 +1147,7 @@ private function getAbbreviationSuggestions(array $abbrevs): string * * @return string */ - public function extractNamespace(string $name, int $limit = null) + public function extractNamespace(string $name, ?int $limit = null) { $parts = explode(':', $name, -1); diff --git a/CI/GithubActionReporter.php b/CI/GithubActionReporter.php index a15c1ff18..065717854 100644 --- a/CI/GithubActionReporter.php +++ b/CI/GithubActionReporter.php @@ -57,7 +57,7 @@ public static function isGithubActionEnvironment(): bool * * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message */ - public function error(string $message, string $file = null, int $line = null, int $col = null): void + public function error(string $message, ?string $file = null, ?int $line = null, ?int $col = null): void { $this->log('error', $message, $file, $line, $col); } @@ -67,7 +67,7 @@ public function error(string $message, string $file = null, int $line = null, in * * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message */ - public function warning(string $message, string $file = null, int $line = null, int $col = null): void + public function warning(string $message, ?string $file = null, ?int $line = null, ?int $col = null): void { $this->log('warning', $message, $file, $line, $col); } @@ -77,12 +77,12 @@ public function warning(string $message, string $file = null, int $line = null, * * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message */ - public function debug(string $message, string $file = null, int $line = null, int $col = null): void + public function debug(string $message, ?string $file = null, ?int $line = null, ?int $col = null): void { $this->log('debug', $message, $file, $line, $col); } - private function log(string $type, string $message, string $file = null, int $line = null, int $col = null): void + private function log(string $type, string $message, ?string $file = null, ?int $line = null, ?int $col = null): void { // Some values must be encoded. $message = strtr($message, self::ESCAPED_DATA); diff --git a/Command/Command.php b/Command/Command.php index cfa18361e..d18103670 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -96,7 +96,7 @@ public static function getDefaultDescription(): ?string * * @throws LogicException When the command name is empty */ - public function __construct(string $name = null) + public function __construct(?string $name = null) { $this->definition = new InputDefinition(); @@ -132,7 +132,7 @@ public function ignoreValidationErrors() $this->ignoreValidationErrors = true; } - public function setApplication(Application $application = null) + public function setApplication(?Application $application = null) { $this->application = $application; if ($application) { @@ -433,7 +433,7 @@ public function getNativeDefinition() * * @throws InvalidArgumentException When argument mode is not valid */ - public function addArgument(string $name, int $mode = null, string $description = '', $default = null) + public function addArgument(string $name, ?int $mode = null, string $description = '', $default = null) { $this->definition->addArgument(new InputArgument($name, $mode, $description, $default)); if (null !== $this->fullDefinition) { @@ -454,7 +454,7 @@ public function addArgument(string $name, int $mode = null, string $description * * @throws InvalidArgumentException If option mode is invalid or incompatible */ - public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null) + public function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null) { $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default)); if (null !== $this->fullDefinition) { diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index e576ad03f..302a0809e 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -43,7 +43,7 @@ public function ignoreValidationErrors(): void $this->getCommand()->ignoreValidationErrors(); } - public function setApplication(Application $application = null): void + public function setApplication(?Application $application = null): void { if ($this->command instanceof parent) { $this->command->setApplication($application); @@ -117,7 +117,7 @@ public function getNativeDefinition(): InputDefinition /** * @return $this */ - public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self + public function addArgument(string $name, ?int $mode = null, string $description = '', $default = null): self { $this->getCommand()->addArgument($name, $mode, $description, $default); @@ -127,7 +127,7 @@ public function addArgument(string $name, int $mode = null, string $description /** * @return $this */ - public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null): self + public function addOption(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null): self { $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); diff --git a/Command/LockableTrait.php b/Command/LockableTrait.php index b1856dca7..d21edc2c0 100644 --- a/Command/LockableTrait.php +++ b/Command/LockableTrait.php @@ -30,7 +30,7 @@ trait LockableTrait /** * Locks a command. */ - private function lock(string $name = null, bool $blocking = false): bool + private function lock(?string $name = null, bool $blocking = false): bool { if (!class_exists(SemaphoreStore::class)) { throw new LogicException('To enable the locking feature you must install the symfony/lock component.'); diff --git a/Descriptor/ApplicationDescription.php b/Descriptor/ApplicationDescription.php index 2a3acc99b..eb11b4f91 100644 --- a/Descriptor/ApplicationDescription.php +++ b/Descriptor/ApplicationDescription.php @@ -43,7 +43,7 @@ class ApplicationDescription */ private $aliases; - public function __construct(Application $application, string $namespace = null, bool $showHidden = false) + public function __construct(Application $application, ?string $namespace = null, bool $showHidden = false) { $this->application = $application; $this->namespace = $namespace; diff --git a/Descriptor/XmlDescriptor.php b/Descriptor/XmlDescriptor.php index 4f7cd8b3e..f17e5f1f2 100644 --- a/Descriptor/XmlDescriptor.php +++ b/Descriptor/XmlDescriptor.php @@ -79,7 +79,7 @@ public function getCommandDocument(Command $command, bool $short = false): \DOMD return $dom; } - public function getApplicationDocument(Application $application, string $namespace = null, bool $short = false): \DOMDocument + public function getApplicationDocument(Application $application, ?string $namespace = null, bool $short = false): \DOMDocument { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($rootXml = $dom->createElement('symfony')); diff --git a/Event/ConsoleErrorEvent.php b/Event/ConsoleErrorEvent.php index 57d9b38ba..d4c26493f 100644 --- a/Event/ConsoleErrorEvent.php +++ b/Event/ConsoleErrorEvent.php @@ -25,7 +25,7 @@ final class ConsoleErrorEvent extends ConsoleEvent private $error; private $exitCode; - public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null) + public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, ?Command $command = null) { parent::__construct($command, $input, $output); diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index 897d9853f..e9c9e3ea4 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -26,7 +26,7 @@ class ErrorListener implements EventSubscriberInterface { private $logger; - public function __construct(LoggerInterface $logger = null) + public function __construct(?LoggerInterface $logger = null) { $this->logger = $logger; } diff --git a/Exception/CommandNotFoundException.php b/Exception/CommandNotFoundException.php index 910ae1928..81ec318ab 100644 --- a/Exception/CommandNotFoundException.php +++ b/Exception/CommandNotFoundException.php @@ -26,7 +26,7 @@ class CommandNotFoundException extends \InvalidArgumentException implements Exce * @param int $code Exception code * @param \Throwable|null $previous Previous exception used for the exception chaining */ - public function __construct(string $message, array $alternatives = [], int $code = 0, \Throwable $previous = null) + public function __construct(string $message, array $alternatives = [], int $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); diff --git a/Formatter/NullOutputFormatterStyle.php b/Formatter/NullOutputFormatterStyle.php index 9232510f4..afd3d0043 100644 --- a/Formatter/NullOutputFormatterStyle.php +++ b/Formatter/NullOutputFormatterStyle.php @@ -27,7 +27,7 @@ public function apply(string $text): string /** * {@inheritdoc} */ - public function setBackground(string $color = null): void + public function setBackground(?string $color = null): void { // do nothing } @@ -35,7 +35,7 @@ public function setBackground(string $color = null): void /** * {@inheritdoc} */ - public function setForeground(string $color = null): void + public function setForeground(?string $color = null): void { // do nothing } diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 8370ba058..d7ae66494 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -33,7 +33,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @param string|null $foreground The style foreground color name * @param string|null $background The style background color name */ - public function __construct(string $foreground = null, string $background = null, array $options = []) + public function __construct(?string $foreground = null, ?string $background = null, array $options = []) { $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); } @@ -41,7 +41,7 @@ public function __construct(string $foreground = null, string $background = null /** * {@inheritdoc} */ - public function setForeground(string $color = null) + public function setForeground(?string $color = null) { $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); } @@ -49,7 +49,7 @@ public function setForeground(string $color = null) /** * {@inheritdoc} */ - public function setBackground(string $color = null) + public function setBackground(?string $color = null) { $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); } diff --git a/Formatter/OutputFormatterStyleInterface.php b/Formatter/OutputFormatterStyleInterface.php index b30560d22..89e4d2438 100644 --- a/Formatter/OutputFormatterStyleInterface.php +++ b/Formatter/OutputFormatterStyleInterface.php @@ -21,12 +21,12 @@ interface OutputFormatterStyleInterface /** * Sets style foreground color. */ - public function setForeground(string $color = null); + public function setForeground(?string $color = null); /** * Sets style background color. */ - public function setBackground(string $color = null); + public function setBackground(?string $color = null); /** * Sets some specific style option. diff --git a/Formatter/OutputFormatterStyleStack.php b/Formatter/OutputFormatterStyleStack.php index fc48dc0e1..1b9356301 100644 --- a/Formatter/OutputFormatterStyleStack.php +++ b/Formatter/OutputFormatterStyleStack.php @@ -26,7 +26,7 @@ class OutputFormatterStyleStack implements ResetInterface private $emptyStyle; - public function __construct(OutputFormatterStyleInterface $emptyStyle = null) + public function __construct(?OutputFormatterStyleInterface $emptyStyle = null) { $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); $this->reset(); @@ -55,7 +55,7 @@ public function push(OutputFormatterStyleInterface $style) * * @throws InvalidArgumentException When style tags incorrectly nested */ - public function pop(OutputFormatterStyleInterface $style = null) + public function pop(?OutputFormatterStyleInterface $style = null) { if (empty($this->styles)) { return $this->emptyStyle; diff --git a/Helper/Dumper.php b/Helper/Dumper.php index b013b6c52..605e4d70b 100644 --- a/Helper/Dumper.php +++ b/Helper/Dumper.php @@ -26,7 +26,7 @@ final class Dumper private $cloner; private $handler; - public function __construct(OutputInterface $output, CliDumper $dumper = null, ClonerInterface $cloner = null) + public function __construct(OutputInterface $output, ?CliDumper $dumper = null, ?ClonerInterface $cloner = null) { $this->output = $output; $this->dumper = $dumper; diff --git a/Helper/Helper.php b/Helper/Helper.php index c7d3e25d0..6b3f7f43a 100644 --- a/Helper/Helper.php +++ b/Helper/Helper.php @@ -26,7 +26,7 @@ abstract class Helper implements HelperInterface /** * {@inheritdoc} */ - public function setHelperSet(HelperSet $helperSet = null) + public function setHelperSet(?HelperSet $helperSet = null) { $this->helperSet = $helperSet; } @@ -96,7 +96,7 @@ public static function length(?string $string): int * * @return string */ - public static function substr(?string $string, int $from, int $length = null) + public static function substr(?string $string, int $from, ?int $length = null) { $string ?? $string = ''; diff --git a/Helper/HelperInterface.php b/Helper/HelperInterface.php index fc952b486..5bf4d6327 100644 --- a/Helper/HelperInterface.php +++ b/Helper/HelperInterface.php @@ -21,7 +21,7 @@ interface HelperInterface /** * Sets the helper set associated with this helper. */ - public function setHelperSet(HelperSet $helperSet = null); + public function setHelperSet(?HelperSet $helperSet = null); /** * Gets the helper set associated with this helper. diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index 719762d24..c870ab997 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -37,7 +37,7 @@ public function __construct(array $helpers = []) } } - public function set(HelperInterface $helper, string $alias = null) + public function set(HelperInterface $helper, ?string $alias = null) { $this->helpers[$helper->getName()] = $helper; if (null !== $alias) { @@ -76,7 +76,7 @@ public function get(string $name) /** * @deprecated since Symfony 5.4 */ - public function setCommand(Command $command = null) + public function setCommand(?Command $command = null) { trigger_deprecation('symfony/console', '5.4', 'Method "%s()" is deprecated.', __METHOD__); diff --git a/Helper/ProcessHelper.php b/Helper/ProcessHelper.php index 4ea3d724d..86a250b27 100644 --- a/Helper/ProcessHelper.php +++ b/Helper/ProcessHelper.php @@ -32,7 +32,7 @@ class ProcessHelper extends Helper * @param callable|null $callback A PHP callback to run whenever there is some * output available on STDOUT or STDERR */ - public function run(OutputInterface $output, $cmd, string $error = null, callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process + public function run(OutputInterface $output, $cmd, ?string $error = null, ?callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process { if (!class_exists(Process::class)) { throw new \LogicException('The ProcessHelper cannot be run as the Process component is not installed. Try running "compose require symfony/process".'); @@ -98,7 +98,7 @@ public function run(OutputInterface $output, $cmd, string $error = null, callabl * * @see run() */ - public function mustRun(OutputInterface $output, $cmd, string $error = null, callable $callback = null): Process + public function mustRun(OutputInterface $output, $cmd, ?string $error = null, ?callable $callback = null): Process { $process = $this->run($output, $cmd, $error, $callback); @@ -112,7 +112,7 @@ public function mustRun(OutputInterface $output, $cmd, string $error = null, cal /** * Wraps a Process callback to add debugging output. */ - public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null): callable + public function wrapCallback(OutputInterface $output, Process $process, ?callable $callback = null): callable { if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index eb6aacb1a..1d7b8d456 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -293,7 +293,7 @@ public function maxSecondsBetweenRedraws(float $seconds): void * * @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable */ - public function iterate(iterable $iterable, int $max = null): iterable + public function iterate(iterable $iterable, ?int $max = null): iterable { $this->start($max ?? (is_countable($iterable) ? \count($iterable) : 0)); @@ -311,7 +311,7 @@ public function iterate(iterable $iterable, int $max = null): iterable * * @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged */ - public function start(int $max = null) + public function start(?int $max = null) { $this->startTime = time(); $this->step = 0; diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index a5a04ee19..3cc0e1451 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -50,7 +50,7 @@ class ProgressIndicator * @param int $indicatorChangeInterval Change interval in milliseconds * @param array|null $indicatorValues Animated indicator characters */ - public function __construct(OutputInterface $output, string $format = null, int $indicatorChangeInterval = 100, array $indicatorValues = null) + public function __construct(OutputInterface $output, ?string $format = null, int $indicatorChangeInterval = 100, ?array $indicatorValues = null) { $this->output = $output; diff --git a/Helper/Table.php b/Helper/Table.php index 5c3447ab3..408a76d67 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -451,7 +451,7 @@ public function render() * * +-----+-----------+-------+ */ - private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $title = null, string $titleFormat = null) + private function renderRowSeparator(int $type = self::SEPARATOR_MID, ?string $title = null, ?string $titleFormat = null) { if (0 === $count = $this->numberOfColumns) { return; @@ -516,7 +516,7 @@ private function renderColumnSeparator(int $type = self::BORDER_OUTSIDE): string * * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | */ - private function renderRow(array $row, string $cellFormat, string $firstCellFormat = null) + private function renderRow(array $row, string $cellFormat, ?string $firstCellFormat = null) { $rowContent = $this->renderColumnSeparator(self::BORDER_OUTSIDE); $columns = $this->getRowColumns($row); diff --git a/Helper/TableStyle.php b/Helper/TableStyle.php index dfc41e6a4..0643c79eb 100644 --- a/Helper/TableStyle.php +++ b/Helper/TableStyle.php @@ -90,7 +90,7 @@ public function getPaddingChar() * * @return $this */ - public function setHorizontalBorderChars(string $outside, string $inside = null): self + public function setHorizontalBorderChars(string $outside, ?string $inside = null): self { $this->horizontalOutsideBorderChar = $outside; $this->horizontalInsideBorderChar = $inside ?? $outside; @@ -115,7 +115,7 @@ public function setHorizontalBorderChars(string $outside, string $inside = null) * * @return $this */ - public function setVerticalBorderChars(string $outside, string $inside = null): self + public function setVerticalBorderChars(string $outside, ?string $inside = null): self { $this->verticalOutsideBorderChar = $outside; $this->verticalInsideBorderChar = $inside ?? $outside; @@ -169,7 +169,7 @@ public function getBorderChars(): array * * @return $this */ - public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): self + public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, ?string $topLeftBottom = null, ?string $topMidBottom = null, ?string $topRightBottom = null): self { $this->crossingChar = $cross; $this->crossingTopLeftChar = $topLeft; diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index 675b9ef58..0c4b2d25b 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -43,7 +43,7 @@ class ArgvInput extends Input private $tokens; private $parsed; - public function __construct(array $argv = null, InputDefinition $definition = null) + public function __construct(?array $argv = null, ?InputDefinition $definition = null) { $argv = $argv ?? $_SERVER['argv'] ?? []; diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index c65161484..21a517cfb 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -27,7 +27,7 @@ class ArrayInput extends Input { private $parameters; - public function __construct(array $parameters, InputDefinition $definition = null) + public function __construct(array $parameters, ?InputDefinition $definition = null) { $this->parameters = $parameters; diff --git a/Input/Input.php b/Input/Input.php index d37460ed3..0faab2cf1 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -33,7 +33,7 @@ abstract class Input implements InputInterface, StreamableInputInterface protected $arguments = []; protected $interactive = true; - public function __construct(InputDefinition $definition = null) + public function __construct(?InputDefinition $definition = null) { if (null === $definition) { $this->definition = new InputDefinition(); diff --git a/Input/InputArgument.php b/Input/InputArgument.php index 8a64f7ac8..1a8bf44b7 100644 --- a/Input/InputArgument.php +++ b/Input/InputArgument.php @@ -38,7 +38,7 @@ class InputArgument * * @throws InvalidArgumentException When argument mode is not valid */ - public function __construct(string $name, int $mode = null, string $description = '', $default = null) + public function __construct(string $name, ?int $mode = null, string $description = '', $default = null) { if (null === $mode) { $mode = self::OPTIONAL; diff --git a/Input/InputOption.php b/Input/InputOption.php index 07a2a7a70..1d8dbca31 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -59,7 +59,7 @@ class InputOption * * @throws InvalidArgumentException If option mode is invalid or incompatible */ - public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null) + public function __construct(string $name, $shortcut = null, ?int $mode = null, string $description = '', $default = null) { if (str_starts_with($name, '--')) { $name = substr($name, 2); diff --git a/Output/ConsoleOutput.php b/Output/ConsoleOutput.php index f19f9ebf4..560aeb581 100644 --- a/Output/ConsoleOutput.php +++ b/Output/ConsoleOutput.php @@ -37,7 +37,7 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface * @param bool|null $decorated Whether to decorate messages (null for auto-guessing) * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) */ - public function __construct(int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) + public function __construct(int $verbosity = self::VERBOSITY_NORMAL, ?bool $decorated = null, ?OutputFormatterInterface $formatter = null) { parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter); diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index 8f1649758..70d70c50b 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -43,7 +43,7 @@ public function __construct($stream, array &$sections, int $verbosity, bool $dec * * @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared */ - public function clear(int $lines = null) + public function clear(?int $lines = null) { if (empty($this->content) || !$this->isDecorated()) { return; diff --git a/Output/Output.php b/Output/Output.php index d7c5fb2d1..28c40bb3e 100644 --- a/Output/Output.php +++ b/Output/Output.php @@ -37,7 +37,7 @@ abstract class Output implements OutputInterface * @param bool $decorated Whether to decorate messages * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) */ - public function __construct(?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null) + public function __construct(?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, ?OutputFormatterInterface $formatter = null) { $this->verbosity = $verbosity ?? self::VERBOSITY_NORMAL; $this->formatter = $formatter ?? new OutputFormatter(); diff --git a/Output/StreamOutput.php b/Output/StreamOutput.php index dcd9e54c1..0ef15cf31 100644 --- a/Output/StreamOutput.php +++ b/Output/StreamOutput.php @@ -39,7 +39,7 @@ class StreamOutput extends Output * * @throws InvalidArgumentException When first argument is not a real stream */ - public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) + public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, ?bool $decorated = null, ?OutputFormatterInterface $formatter = null) { if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) { throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); diff --git a/Output/TrimmedBufferOutput.php b/Output/TrimmedBufferOutput.php index 3f4d375f4..b08503b3a 100644 --- a/Output/TrimmedBufferOutput.php +++ b/Output/TrimmedBufferOutput.php @@ -24,7 +24,7 @@ class TrimmedBufferOutput extends Output private $maxLength; private $buffer = ''; - public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null) + public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, ?OutputFormatterInterface $formatter = null) { if ($maxLength <= 0) { throw new InvalidArgumentException(sprintf('"%s()" expects a strictly positive maxLength. Got %d.', __METHOD__, $maxLength)); diff --git a/Question/Question.php b/Question/Question.php index 3a73f04b2..ba5744283 100644 --- a/Question/Question.php +++ b/Question/Question.php @@ -186,7 +186,7 @@ public function getAutocompleterCallback(): ?callable * * @return $this */ - public function setAutocompleterCallback(callable $callback = null): self + public function setAutocompleterCallback(?callable $callback = null): self { if ($this->hidden && null !== $callback) { throw new LogicException('A hidden question cannot use the autocompleter.'); @@ -202,7 +202,7 @@ public function setAutocompleterCallback(callable $callback = null): self * * @return $this */ - public function setValidator(callable $validator = null) + public function setValidator(?callable $validator = null) { $this->validator = $validator; diff --git a/SingleCommandApplication.php b/SingleCommandApplication.php index e93c1821b..774e5d8c4 100644 --- a/SingleCommandApplication.php +++ b/SingleCommandApplication.php @@ -46,7 +46,7 @@ public function setAutoExit(bool $autoExit): self return $this; } - public function run(InputInterface $input = null, OutputInterface $output = null): int + public function run(?InputInterface $input = null, ?OutputInterface $output = null): int { if ($this->running) { return parent::run($input, $output); diff --git a/Style/StyleInterface.php b/Style/StyleInterface.php index 38d23b77e..9f25a43f6 100644 --- a/Style/StyleInterface.php +++ b/Style/StyleInterface.php @@ -85,14 +85,14 @@ public function table(array $headers, array $rows); * * @return mixed */ - public function ask(string $question, string $default = null, callable $validator = null); + public function ask(string $question, ?string $default = null, ?callable $validator = null); /** * Asks a question with the user input hidden. * * @return mixed */ - public function askHidden(string $question, callable $validator = null); + public function askHidden(string $question, ?callable $validator = null); /** * Asks for confirmation. diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index e3c5ac8e7..00edf3882 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -61,7 +61,7 @@ public function __construct(InputInterface $input, OutputInterface $output) * * @param string|array $messages The message to write in the block */ - public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) + public function block($messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) { $messages = \is_array($messages) ? array_values($messages) : [$messages]; @@ -250,7 +250,7 @@ public function definitionList(...$list) /** * {@inheritdoc} */ - public function ask(string $question, string $default = null, callable $validator = null) + public function ask(string $question, ?string $default = null, ?callable $validator = null) { $question = new Question($question, $default); $question->setValidator($validator); @@ -261,7 +261,7 @@ public function ask(string $question, string $default = null, callable $validato /** * {@inheritdoc} */ - public function askHidden(string $question, callable $validator = null) + public function askHidden(string $question, ?callable $validator = null) { $question = new Question($question); @@ -338,7 +338,7 @@ public function createProgressBar(int $max = 0) /** * @see ProgressBar::iterate() */ - public function progressIterate(iterable $iterable, int $max = null): iterable + public function progressIterate(iterable $iterable, ?int $max = null): iterable { yield from $this->createProgressBar()->iterate($iterable, $max); @@ -463,7 +463,7 @@ private function writeBuffer(string $message, bool $newLine, int $type): void $this->bufferedOutput->write($message, $newLine, $type); } - private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array + private function createBlock(iterable $messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array { $indentLength = 0; $prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix)); diff --git a/Tests/CI/GithubActionReporterTest.php b/Tests/CI/GithubActionReporterTest.php index 23f7a3bd9..fb5885808 100644 --- a/Tests/CI/GithubActionReporterTest.php +++ b/Tests/CI/GithubActionReporterTest.php @@ -34,7 +34,7 @@ public function testIsGithubActionEnvironment() /** * @dataProvider annotationsFormatProvider */ - public function testAnnotationsFormat(string $type, string $message, string $file = null, int $line = null, int $col = null, string $expected) + public function testAnnotationsFormat(string $type, string $message, ?string $file = null, ?int $line = null, ?int $col = null, string $expected) { $reporter = new GithubActionReporter($buffer = new BufferedOutput()); diff --git a/Tests/Formatter/OutputFormatterTest.php b/Tests/Formatter/OutputFormatterTest.php index 0b1772107..21905f475 100644 --- a/Tests/Formatter/OutputFormatterTest.php +++ b/Tests/Formatter/OutputFormatterTest.php @@ -162,7 +162,7 @@ public function testInlineStyle() /** * @dataProvider provideInlineStyleOptionsCases */ - public function testInlineStyleOptions(string $tag, string $expected = null, string $input = null, bool $truecolor = false) + public function testInlineStyleOptions(string $tag, ?string $expected = null, ?string $input = null, bool $truecolor = false) { if ($truecolor && 'truecolor' !== getenv('COLORTERM')) { $this->markTestSkipped('The terminal does not support true colors.'); diff --git a/Tests/Helper/HelperSetTest.php b/Tests/Helper/HelperSetTest.php index 78d22939c..c83b9d5a3 100644 --- a/Tests/Helper/HelperSetTest.php +++ b/Tests/Helper/HelperSetTest.php @@ -117,7 +117,7 @@ public function testIteration() } } - private function getGenericMockHelper($name, HelperSet $helperset = null) + private function getGenericMockHelper($name, ?HelperSet $helperset = null) { $mock_helper = $this->createMock(HelperInterface::class); $mock_helper->expects($this->any()) From dbdf6adcb88d5f83790e1efb57ef4074309d3931 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 15:23:03 +0100 Subject: [PATCH 2/2] Fix implicitly-required parameters --- Tests/CI/GithubActionReporterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/CI/GithubActionReporterTest.php b/Tests/CI/GithubActionReporterTest.php index fb5885808..a35927950 100644 --- a/Tests/CI/GithubActionReporterTest.php +++ b/Tests/CI/GithubActionReporterTest.php @@ -34,7 +34,7 @@ public function testIsGithubActionEnvironment() /** * @dataProvider annotationsFormatProvider */ - public function testAnnotationsFormat(string $type, string $message, ?string $file = null, ?int $line = null, ?int $col = null, string $expected) + public function testAnnotationsFormat(string $type, string $message, ?string $file, ?int $line, ?int $col, string $expected) { $reporter = new GithubActionReporter($buffer = new BufferedOutput());