Skip to content

Commit

Permalink
Rector simplifies class names (#4984)
Browse files Browse the repository at this point in the history
* Rector simplifies class names

* Fix param hint

* Not nullable array
  • Loading branch information
weitzman committed Jan 6, 2022
1 parent 661e4a0 commit 0254f34
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 86 deletions.
3 changes: 0 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::PATHS, [
__DIR__ . '/src',
]);

$services = $containerConfigurator->services();
$services->set(ParamTypeDeclarationRector::class);
Expand Down
57 changes: 33 additions & 24 deletions src/Boot/BootstrapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

namespace Drush\Boot;

use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputAwareInterface;
use Robo\Contract\OutputAwareInterface;
use Robo\Contract\ProgressIndicatorAwareInterface;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface;
use Robo\Contract\VerbosityThresholdInterface;
use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
use Consolidation\SiteProcess\ProcessManagerAwareInterface;
use Consolidation\AnnotatedCommand\Input\StdinAwareInterface;
use Consolidation\AnnotatedCommand\AnnotationData;
use DrupalFinder\DrupalFinder;
use Drush\Config\ConfigAwareTrait;
Expand All @@ -24,12 +33,12 @@ class BootstrapManager implements LoggerAwareInterface, AutoloaderAwareInterface
protected $drupalFinder;

/**
* @var \Drush\Boot\Boot[]
* @var Boot[]
*/
protected $bootstrapCandidates = [];

/**
* @var \Drush\Boot\Boot
* @var Boot
*/
protected $bootstrap;

Expand Down Expand Up @@ -69,7 +78,7 @@ public function add($candidateList): void
}
}

public function drupalFinder(): \DrupalFinder\DrupalFinder
public function drupalFinder(): DrupalFinder
{
if (!isset($this->drupalFinder)) {
$this->drupalFinder = new DrupalFinder();
Expand All @@ -85,15 +94,15 @@ public function setDrupalFinder(DrupalFinder $drupalFinder): void
/**
* Return the framework root selected by the user.
*/
public function getRoot()
public function getRoot(): string
{
return $this->drupalFinder()->getDrupalRoot();
}

/**
* Return the composer root for the selected Drupal site.
*/
public function getComposerRoot()
public function getComposerRoot(): string
{
return $this->drupalFinder()->getComposerRoot();
}
Expand Down Expand Up @@ -143,7 +152,7 @@ public function setUri($uri): void
* bootstrapping; otherwise, it will be whichever bootstrap
* object is best for the selected root.
*/
public function bootstrap(): \Drush\Boot\Boot
public function bootstrap(): Boot
{
if (!$this->bootstrap) {
$this->bootstrap = $this->selectBootstrapClass();
Expand All @@ -154,7 +163,7 @@ public function bootstrap(): \Drush\Boot\Boot
/**
* For use in testing
*/
public function injectBootstrap(\Drush\Boot\Boot $bootstrap): void
public function injectBootstrap(Boot $bootstrap): void
{
$this->inflect($bootstrap);
$this->bootstrap = $bootstrap;
Expand All @@ -168,7 +177,7 @@ public function injectBootstrap(\Drush\Boot\Boot $bootstrap): void
* Look up the best bootstrap class for the given location
* from the set of available candidates.
*/
public function bootstrapObjectForRoot($path): \Drush\Boot\Boot
public function bootstrapObjectForRoot($path): Boot
{
foreach ($this->bootstrapCandidates as $candidate) {
if ($candidate->validRoot($path)) {
Expand All @@ -191,7 +200,7 @@ public function bootstrapObjectForRoot($path): \Drush\Boot\Boot
* be 'latched', and further calls to Drush::bootstrap()
* will always return the same object.
*/
protected function selectBootstrapClass(): \Drush\Boot\Boot
protected function selectBootstrapClass(): Boot
{
// Once we have selected a Drupal root, we will reduce our bootstrap
// candidates down to just the one used to select this site root.
Expand All @@ -203,7 +212,7 @@ protected function selectBootstrapClass(): \Drush\Boot\Boot
* object being used, and do not allow it to change any
* longer.
*/
public function latch(\Drush\Boot\Boot $bootstrap): void
public function latch(Boot $bootstrap): void
{
$this->bootstrap = $bootstrap;
}
Expand Down Expand Up @@ -245,7 +254,7 @@ public function bootstrapPhases(bool $function_names = false): array
* function itself but can be useful for other code called from within this
* function, to know if e.g. a caller is in the process of booting to the
* specified level. If specified, it should never be lower than $phase.
* @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData
* @param AnnotationData $annotationData
* Optional annotation data from the command.
*
* TRUE if the specified bootstrap phase has completed.
Expand Down Expand Up @@ -441,7 +450,7 @@ public function bootstrapToPhaseIndex(int $max_phase_index, AnnotationData $anno
*
* @param int $max_phase_index
* (optional) Only attempt bootstrap to the specified level.
* @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData
* @param AnnotationData $annotationData
* Optional annotation data from the command.
*
* The maximum phase to which we bootstrapped.
Expand Down Expand Up @@ -486,7 +495,7 @@ public function bootstrapMax($max_phase_index = false, AnnotationData $annotatio
/**
* Allow those with an instance to us to the BootstrapManager to use its logger
*/
public function logger(): ?\Psr\Log\LoggerInterface
public function logger(): ?LoggerInterface
{
return $this->logger;
}
Expand All @@ -496,37 +505,37 @@ public function inflect($object): void
// See \Drush\Runtime\DependencyInjection::addDrushServices and
// \Robo\Robo\addInflectors
$container = $this->getContainer();
if ($object instanceof \Robo\Contract\ConfigAwareInterface) {
if ($object instanceof ConfigAwareInterface) {
$object->setConfig($container->get('config'));
}
if ($object instanceof \Psr\Log\LoggerAwareInterface) {
if ($object instanceof LoggerAwareInterface) {
$object->setLogger($container->get('logger'));
}
if ($object instanceof \League\Container\ContainerAwareInterface) {
if ($object instanceof ContainerAwareInterface) {
$object->setContainer($container->get('container'));
}
if ($object instanceof \Symfony\Component\Console\Input\InputAwareInterface) {
if ($object instanceof InputAwareInterface) {
$object->setInput($container->get('input'));
}
if ($object instanceof \Robo\Contract\OutputAwareInterface) {
if ($object instanceof OutputAwareInterface) {
$object->setOutput($container->get('output'));
}
if ($object instanceof \Robo\Contract\ProgressIndicatorAwareInterface) {
if ($object instanceof ProgressIndicatorAwareInterface) {
$object->setProgressIndicator($container->get('progressIndicator'));
}
if ($object instanceof \Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface) {
if ($object instanceof CustomEventAwareInterface) {
$object->setHookManager($container->get('hookManager'));
}
if ($object instanceof \Robo\Contract\VerbosityThresholdInterface) {
if ($object instanceof VerbosityThresholdInterface) {
$object->setOutputAdapter($container->get('outputAdapter'));
}
if ($object instanceof \Consolidation\SiteAlias\SiteAliasManagerAwareInterface) {
if ($object instanceof SiteAliasManagerAwareInterface) {
$object->setSiteAliasManager($container->get('site.alias.manager'));
}
if ($object instanceof \Consolidation\SiteProcess\ProcessManagerAwareInterface) {
if ($object instanceof ProcessManagerAwareInterface) {
$object->setProcessManager($container->get('process.manager'));
}
if ($object instanceof \Consolidation\AnnotatedCommand\Input\StdinAwareInterface) {
if ($object instanceof StdinAwareInterface) {
$object->setStdinHandler($container->get('stdinHandler'));
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/Boot/DrupalBoot8.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drush\Boot;

use Drupal\Core\DrupalKernelInterface;
use Consolidation\AnnotatedCommand\AnnotationData;
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
Expand All @@ -24,26 +25,26 @@ class DrupalBoot8 extends DrupalBoot implements AutoloaderAwareInterface
protected $drupalLoggerAdapter;

/**
* @var \Drupal\Core\DrupalKernelInterface
* @var DrupalKernelInterface
*/
protected $kernel;

/**
* @var \Symfony\Component\HttpFoundation\Request
* @var Request
*/
protected $request;

public function getRequest(): \Symfony\Component\HttpFoundation\Request
public function getRequest(): Request
{
return $this->request;
}

public function setRequest(\Symfony\Component\HttpFoundation\Request $request): void
public function setRequest(Request $request): void
{
$this->request = $request;
}

public function getKernel(): \Drupal\Core\DrupalKernelInterface
public function getKernel(): DrupalKernelInterface
{
return $this->kernel;
}
Expand Down Expand Up @@ -79,7 +80,7 @@ public function validRoot($path)
}
}

public function getVersion($drupal_root)
public function getVersion($drupal_root): string
{
// Are the class constants available?
if (!$this->hasAutoloader()) {
Expand Down Expand Up @@ -215,7 +216,7 @@ public function bootstrapDrupalConfiguration(BootstrapManager $manager, Annotati
$request = $this->getRequest();
$kernel_factory = Kernels::getKernelFactory($kernel);
$allow_dumping = $kernel !== Kernels::UPDATE;
/** @var \Drupal\Core\DrupalKernelInterface kernel */
/** @var DrupalKernelInterface kernel */
$this->kernel = $kernel_factory($request, $classloader, 'prod', $allow_dumping, $manager->getRoot());
// Include Drush services in the container.
// @see Drush\Drupal\DrupalKernel::addServiceModifier()
Expand Down
2 changes: 1 addition & 1 deletion src/Config/ConfigAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait ConfigAwareTrait
*
* @see https://stackoverflow.com/a/37687295.
*
* @return \Drush\Config\DrushConfig
* @return DrushConfig
*/
public function getConfig()
{
Expand Down
8 changes: 5 additions & 3 deletions src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Drush\Config;

use Consolidation\Config\ConfigInterface;
use Robo\Config\Config;
use Consolidation\Config\Loader\ConfigLoaderInterface;
use Drush\Config\Loader\YamlConfigLoader;
use Consolidation\Config\Loader\ConfigProcessor;
Expand Down Expand Up @@ -30,7 +31,7 @@
class ConfigLocator
{
/**
* @var \Robo\Config
* @var Config
*/
protected $config;

Expand Down Expand Up @@ -372,7 +373,7 @@ protected function identifyCandidatesAtPath(string $path, array $candidates): ar
/**
* Get the site aliases according to preflight arguments and environment.
*
* @param $preflightArgs
* @param $paths
* @param Environment $environment
*/
public function getSiteAliasPaths($paths, Environment $environment): array
Expand Down Expand Up @@ -400,7 +401,8 @@ function ($item) {
/**
* Get the commandfile paths according to preflight arguments.
*
* @param $preflightArgs
* @param $commandPaths
* @param $root
*/
public function getCommandFilePaths($commandPaths, $root): array
{
Expand Down
3 changes: 2 additions & 1 deletion src/Config/DrushConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Drush\Config;

use Robo\Config\Config;
use Consolidation\Config\Util\ConfigOverlay;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function drushScript()
*/
public function simulate()
{
return $this->get(\Robo\Config\Config::SIMULATE);
return $this->get(Config::SIMULATE);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Config/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ public function vendorPath(): string
/**
* The class loader returned when the autoload.php file is included.
*/
public function loader(): ?\Composer\Autoload\ClassLoader
public function loader(): ?ClassLoader
{
return $this->loader;
}

/**
* Set the class loader from the autload.php file, if available.
*
* @param \Composer\Autoload\ClassLoader $loader
* @param ClassLoader $loader
*/
public function setLoader(ClassLoader $loader): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/ArgsPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function isAliasOrSiteSpec(string $arg): bool
* @param $opt The option string to check
* @return [$methodName, $optionValue, $acceptsValueFromNextArg]
*/
protected function findMethodForOptionWithValues($optionsTable, $opt)
protected function findMethodForOptionWithValues($optionsTable, $opt): array
{
// Skip $opt if it is empty, or if it is not an option.
if (empty($opt) || ($opt[0] != '-')) {
Expand Down

0 comments on commit 0254f34

Please sign in to comment.