Skip to content

Commit

Permalink
Minor cleanup of Drush.php (#5982)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman authored May 4, 2024
1 parent 4893f27 commit 63c5599
Showing 1 changed file with 16 additions and 44 deletions.
60 changes: 16 additions & 44 deletions src/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,16 @@
class Drush
{
/**
* The version of Drush from the drush.info file, or FALSE if not read yet.
*
* @var string|FALSE
* The version of Drush from Composer Runtime, or FALSE if not populated yet.
*/
protected static $version = false;
protected static $majorVersion = false;
protected static $minorVersion = false;
protected static string|false $version = false;
protected static string|false $majorVersion = false;
protected static string|false $minorVersion = false;

/**
* The Robo Runner -- manages and constructs all commandfile classes
*
* @var Runner
*/
protected static $runner;
protected static Runner $runner;

/**
* Number of seconds before timeout for subprocesses. Can be customized via setTimeout() method.
Expand All @@ -84,7 +80,7 @@ public static function getTimeout(): int
* n.b. Called before the DI container is initialized.
* Do not log, etc. here.
*/
public static function getVersion()
public static function getVersion(): string|false
{
if (!self::$version) {
self::$version = InstalledVersions::getVersion('drush/drush');
Expand All @@ -95,7 +91,7 @@ public static function getVersion()
/**
* Convert internal Composer dev version to ".x"
*/
public static function sanitizeVersionString($version)
public static function sanitizeVersionString($version): string
{
return preg_replace('#\.9+\.9+\.9+#', '.x', $version);
}
Expand Down Expand Up @@ -283,31 +279,7 @@ public static function output(): OutputInterface
* as shown above.
*
* Note, however, that an alias record is required to use the `drush` method.
* The alias manager will provide an alias record, but the alias manager is
* not injected by default into Drush commands. In order to use it, it is
* necessary to use SiteAliasManagerAwareTrait:
* <code>
* use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
* use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
*
* class SiteInstallCommands extends DrushCommands implements SiteAliasManagerAwareInterface
* {
* use SiteAliasManagerAwareTrait;
*
* public function install(array $profile, ...)
* {
* $selfRecord = $this->siteAliasManager()->getSelf();
* $args = ['system.site', ...];
* $options = ['yes' => true];
* $process = $this->processManager()->drush($selfRecord, 'config-set', $args, $options);
* $process->mustRun();
* }
* }
* </code>
* Objects that are fetched from the DI container, or any Drush command will
* automatically be given a reference to the alias manager if SiteAliasManagerAwareTrait
* is used. Other objects will need to be manually provided with a reference
* to the alias manager once it is created (call $obj->setAliasManager($aliasManager);).
* Dependency inject the site alias manager to get an alias record.
*
* Clients that are using Drush::drush(), and need a reference to the alias
* manager may use Drush::aliasManager().
Expand Down Expand Up @@ -336,15 +308,15 @@ public static function siteProcess(SiteAliasInterface $siteAlias, array $args =
* The timeout parameter on this method doesn't work. It exists for compatibility with parent.
* Call this method to get a Process and then call setters as needed.
*
* Tip: Consider using injected process manager instead of this method.
* Tip: Commandfiles should use processmanager() instead of this method.
*
* @param string|array $commandline The command line to run
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
* @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
* @param $commandline The command line to run
* @param $cwd The working directory or null to use the working dir of the current PHP process
* @param $env The environment variables or null to use the same environment as the current PHP process
* @param $input The input as stream resource, scalar or \Traversable, or null for no input
* @param $timeout The timeout in seconds or null to disable
*/
public static function process($commandline, $cwd = null, $env = null, $input = null, $timeout = 60): ProcessBase
public static function process(string|array $commandline, ?string $cwd = null, ?array $env = null, mixed $input = null, int|float|null $timeout = 60): ProcessBase
{
return self::processManager()->process($commandline, $cwd, $env, $input, $timeout);
}
Expand Down Expand Up @@ -438,7 +410,7 @@ public static function bootstrap(): DrupalBoot8
return self::bootstrapManager()->bootstrap();
}

public static function redispatchOptions($input = null)
public static function redispatchOptions($input = null): array
{
$input = $input ?: self::input();
$command_name = $input->getFirstArgument();
Expand Down

0 comments on commit 63c5599

Please sign in to comment.