Skip to content

Commit

Permalink
fix(php): Fix PHP 8.4 deprecations for nullable types (#6234)
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi authored Feb 18, 2025
1 parent b244433 commit 5f98607
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BufferedConsoleOutput extends BufferedOutput implements ConsoleOutputInter
* @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($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null)
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, ?OutputFormatterInterface $formatter = null)
{
parent::__construct($verbosity, $decorated, $formatter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LessStrictArgvInput extends ArgvInput
* @param array|null $argv An array of parameters from the CLI (in the argv format)
* @param InputDefinition|null $definition A InputDefinition instance
*/
public function __construct(array $argv = null, InputDefinition $definition = null)
public function __construct(?array $argv = null, ?InputDefinition $definition = null)
{
// We have to duplicate the implementation of ArgvInput
// because of liberal use of `private`
Expand Down
8 changes: 4 additions & 4 deletions src/Boot/BootstrapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function bootstrapPhases(bool $function_names = false): array
* TRUE if the specified bootstrap phase has completed.
* @see \Drush\Boot\Boot::bootstrapPhases()
*/
public function doBootstrap(int $phase, $phase_max = false, AnnotationData $annotationData = null): bool
public function doBootstrap(int $phase, $phase_max = false, ?AnnotationData $annotationData = null): bool
{
$bootstrap = $this->bootstrap();
$phases = $this->bootstrapPhases(true);
Expand Down Expand Up @@ -314,7 +314,7 @@ public function bootstrapValidate(int $phase): bool
* Thrown when an unknown bootstrap phase is passed in the annotation
* data.
*/
public function bootstrapToPhase(string $bootstrapPhase, AnnotationData $annotationData = null): bool
public function bootstrapToPhase(string $bootstrapPhase, ?AnnotationData $annotationData = null): bool
{
$this->logger->info('Starting bootstrap to {phase}', ['phase' => $bootstrapPhase]);
$phase = $this->bootstrap()->lookUpPhaseIndex($bootstrapPhase);
Expand Down Expand Up @@ -348,7 +348,7 @@ protected function maxPhaseLimit($bootstrap_str)
* Optional annotation data from the command.
* TRUE if the specified bootstrap phase has completed.
*/
public function bootstrapToPhaseIndex(int $max_phase_index, AnnotationData $annotationData = null): bool
public function bootstrapToPhaseIndex(int $max_phase_index, ?AnnotationData $annotationData = null): bool
{
if ($max_phase_index == DRUSH_BOOTSTRAP_MAX) {
// Try get a max phase.
Expand Down Expand Up @@ -396,7 +396,7 @@ public function bootstrapToPhaseIndex(int $max_phase_index, AnnotationData $anno
*
* The maximum phase to which we bootstrapped.
*/
public function bootstrapMax($max_phase_index = false, AnnotationData $annotationData = null): int
public function bootstrapMax($max_phase_index = false, ?AnnotationData $annotationData = null): int
{
// Bootstrap as far as we can without throwing an error, but log for
// debugging purposes.
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/DrupalBoot8.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function bootstrapDrupalDatabase(BootstrapManager $manager): void
parent::bootstrapDrupalDatabase($manager);
}

public function bootstrapDrupalConfiguration(BootstrapManager $manager, AnnotationData $annotationData = null): void
public function bootstrapDrupalConfiguration(BootstrapManager $manager, ?AnnotationData $annotationData = null): void
{
// Coax \Drupal\Core\DrupalKernel::discoverServiceProviders to add our logger.
$GLOBALS['conf']['container_service_providers'][] = DrushLoggerServiceProvider::class;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/ArchiveRestoreCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class ArchiveRestoreCommands extends DrushCommands implements SiteAliasMan
#[CLI\Bootstrap(level: DrupalBootLevels::NONE)]
#[CLI\ValidatePhpExtensions(extensions: ['Phar'])]
public function restore(
string $path = null,
?string $path = null,
?string $site = null,
array $options = [
'destination-path' => null,
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/LocaleCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ private function convertTypesToPoDbReaderOptions(array $types = []): array
* @param array $options The export options for PoDatabaseReader.
* @return bool True if successful.
*/
private function writePoFile(string $file_uri, LanguageInterface $language = null, array $options = []): bool
private function writePoFile(string $file_uri, ?LanguageInterface $language = null, array $options = []): bool
{
$reader = new PoDatabaseReader();

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/WatchdogCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function showOne($id, $options = ['format' => 'yaml']): PropertyList
* @param $severity_min
* Int or String for the minimum severity to return.
*/
protected function where(?string $type = null, $severity = null, ?string $filter = null, string $criteria = 'AND', int|string $severity_min = null): array
protected function where(?string $type = null, $severity = null, ?string $filter = null, string $criteria = 'AND', int|string|null $severity_min = null): array
{
$args = [];
$conditions = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/field/FieldCreateCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function create(ContainerInterface $container): self
return $commandHandler;
}

public function setContentTranslationManager(ContentTranslationManagerInterface $manager = null): void
public function setContentTranslationManager(?ContentTranslationManagerInterface $manager = null): void
{
if ($manager) {
$this->contentTranslationManager = $manager;
Expand Down
2 changes: 1 addition & 1 deletion src/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public static function process($commandline, $cwd = null, $env = null, $input =
* @return
* A wrapper around Symfony Process.
*/
public static function shell(string $command, $cwd = null, array $env = null, $input = null, $timeout = 60): ProcessBase
public static function shell(string $command, $cwd = null, ?array $env = null, $input = null, $timeout = 60): ProcessBase
{
return self::processManager()->shell($command, $cwd, $env, $input, $timeout);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CommandFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class CommandFailedException extends \Exception
{
public function __construct($message = "Failed.", $code = 1, \Throwable $previous = null)
public function __construct($message = "Failed.", $code = 1, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/UserAbortException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class UserAbortException extends \Exception
{
public function __construct($message = "Cancelled.", $code = 0, \Exception $previous = null)
public function __construct($message = "Cancelled.", $code = 0, ?\Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
4 changes: 2 additions & 2 deletions src/SiteAlias/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function siteProcess(SiteAliasInterface $siteAlias, $args = [], $options
*
* A wrapper around Symfony Process.
*/
public function process($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60): ProcessBase
public function process($commandline, $cwd = null, ?array $env = null, $input = null, $timeout = 60): ProcessBase
{
$process = parent::process($commandline, $cwd, $env, $input, $timeout);
return $this->configureProcess($process);
Expand All @@ -154,7 +154,7 @@ public function process($commandline, $cwd = null, array $env = null, $input = n
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
* @param int|float|null $timeout The timeout in seconds or null to disable
*/
public function shell($command, $cwd = null, array $env = null, $input = null, $timeout = 60): ProcessBase
public function shell($command, $cwd = null, ?array $env = null, $input = null, $timeout = 60): ProcessBase
{
$process = parent::shell($command, $cwd, $env, $input, $timeout);
return $this->configureProcess($process);
Expand Down
2 changes: 1 addition & 1 deletion src/TestTraits/OutputUtilsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getErrorOutputAsList(): array
* @param $key
* Optionally return only a top level element from the json object.
*/
public function getOutputFromJSON(string|int $key = null): mixed
public function getOutputFromJSON(string|int|null $key = null): mixed
{
$output = $this->getOutput();
$json = json_decode($output, true);
Expand Down

0 comments on commit 5f98607

Please sign in to comment.