Skip to content

Commit

Permalink
DEAD Code rector (#5938)
Browse files Browse the repository at this point in the history
* DEAD Code rector

* PHPCS
  • Loading branch information
weitzman committed Mar 26, 2024
1 parent 68e5d4b commit f691782
Show file tree
Hide file tree
Showing 36 changed files with 17 additions and 108 deletions.
6 changes: 5 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
$config->sets([
SetList::CODE_QUALITY,
SetList::PHP_81,
SetList::DEAD_CODE
]);

$config->skip([
Expand All @@ -38,6 +39,9 @@
FinalizePublicClassConstantRector::class,
NullToStrictStringFuncCallArgRector::class,
\Rector\Php81\Rector\Array_\FirstClassCallableRector::class,
\Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class
\Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector::class,
\Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector::class
]);
};
1 change: 0 additions & 1 deletion src/Boot/DrupalBoot8.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public function bootstrapDrupalConfiguration(BootstrapManager $manager, ?Annotat
$request = $this->getRequest();
$kernel_factory = Kernels::getKernelFactory($kernel);
$allow_dumping = $kernel !== Kernels::UPDATE;
/** @var DrupalKernelInterface kernel */
$this->kernel = $kernel_factory($request, $this->autoloader, 'prod', $allow_dumping, $manager->getRoot());

// Unset drupal error handler and restore Drush's one.
Expand Down
5 changes: 0 additions & 5 deletions src/Command/GlobalOptionsEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ public static function getSubscribedEvents(): array
* Before a Console command runs, examine the global
* commandline options from the event Input, and set
* configuration values as appropriate.
*
* @param ConsoleCommandEvent $event
*/
public function setGlobalOptions(ConsoleCommandEvent $event): void
{
$input = $event->getInput();
$output = $event->getOutput();

// TODO: We need a good strategy for managing global options.
// $simulate = $input->getOption('simulate');
}
Expand Down
1 change: 0 additions & 1 deletion src/Commands/ConfiguresPrompts.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ trait ConfiguresPrompts
/**
* Configure the prompt fallbacks.
*
* @param InputInterface $input
* @return void
*/
protected function configurePrompts(InputInterface $input)
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/config/ConfigImportCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ public function import(array $options = ['source' => self::REQ, 'partial' => fal
$source_storage = $this->getImportTransformer()->transform($source_storage);
}

$config_manager = $this->getConfigManager();
$storage_comparer = new StorageComparer($source_storage, $active_storage);


if (!$storage_comparer->createChangelist()->hasChanges()) {
$this->logger()->notice(('There are no changes to import.'));
return;
Expand Down
10 changes: 0 additions & 10 deletions src/Commands/core/ArchiveDumpCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ private function createManifestFile(array $options): void
/**
* Returns TRUE if the site is a "web" docroot site.
*
* @return bool
*
* @throws \Exception
*/
Expand All @@ -252,7 +251,6 @@ private function isWebRootSite(): bool
/**
* Returns site's docroot name.
*
* @return string
*
* @throws \Exception
*/
Expand All @@ -270,7 +268,6 @@ private function getComposerRoot(): string
/**
* Returns site's docroot path.
*
* @return string
*
* @throws \Exception
*/
Expand Down Expand Up @@ -393,7 +390,6 @@ private function getDrupalFilesComponentPath(): string
/**
* Returns the path to Drupal files directory.
*
* @return string
*
* @throws \Exception
*/
Expand Down Expand Up @@ -422,8 +418,6 @@ private function getDrupalFilesDir(): string
* Directory.
* @param array $excludes
* The list of file exclude rules (regular expressions).
*
* @return \Traversable
*/
private function getFileIterator(string $path, array $excludes): Traversable
{
Expand Down Expand Up @@ -490,8 +484,6 @@ private function getDatabaseComponentPath(array $options): string
*
* @param array $paths
* The list of paths to match.
*
* @return array
*/
private function getRegexpsForPaths(array $paths): array
{
Expand All @@ -504,7 +496,6 @@ private function getRegexpsForPaths(array $paths): array
/**
* Returns docroot directory name with trailing escaped slash for a "web" docroot site for use in regular expressions, otherwise - empty string.
*
* @return string
*
* @throws \Exception
*/
Expand All @@ -516,7 +507,6 @@ private function getDocrootRegexpPrefix(): string
/**
* Returns the list of regular expressions to match Drupal files paths and sites/@/settings.@.php files.
*
* @return array
*
* @throws \Exception
*/
Expand Down
1 change: 0 additions & 1 deletion src/Commands/core/CliCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ protected function getCasters(): array
*
* This can either be site specific (default) or Drupal version specific.
*
* @param array $options
*
* @return string.
*/
Expand Down
5 changes: 0 additions & 5 deletions src/Commands/core/DeployCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public function deploy(): void
$process->mustRun($process->showRealtime());
}

/**
* @param ProcessManager $manager
* @param SiteAlias $self
* @param array $redispatchOptions
*/
public function cacheRebuild(ProcessManager $manager, SiteAlias $self, array $redispatchOptions): void
{
// It is possible that no updates were pending and thus no caches cleared yet.
Expand Down
7 changes: 0 additions & 7 deletions src/Commands/core/EntityCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public function delete(string $entity_type, $ids = null, array $options = ['bund
/**
* Actual delete method.
*
* @param string $entity_type
* @param array $ids
*
* @throws InvalidPluginDefinitionException
* @throws PluginNotFoundException
Expand Down Expand Up @@ -124,8 +122,6 @@ public function loadSave(string $entity_type, $ids = null, array $options = ['bu
/**
* Actual save method.
*
* @param string $entity_type
* @param array $ids
*
* @throws InvalidPluginDefinitionException
* @throws PluginNotFoundException
Expand All @@ -141,10 +137,7 @@ public function doSave(string $entity_type, array $ids): void
}

/**
* @param string $entity_type
* @param string|null $ids
* @param array $options
* @return QueryInterface
* @throws InvalidPluginDefinitionException
* @throws PluginNotFoundException
*/
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/core/EntityCreateCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Drush\Commands\core;

use Drupal\Core\Entity\EntityInterface;
use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\AnnotatedCommand\Hooks\HookManager;
use Consolidation\SiteProcess\Util\Escape;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityConstraintViolationListInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
Expand Down Expand Up @@ -186,7 +185,7 @@ private function showField(FieldDefinitionInterface $instance): bool
}

#[CLI\Hook(type: HookManager::ARGUMENT_VALIDATOR)]
private function validate(CommandData $commandData): void
private function validate(): void
{
if (!$this->input()->isInteractive()) {
throw new \RuntimeException('entity:create is designed for an interactive terminal.');
Expand Down
2 changes: 0 additions & 2 deletions src/Commands/core/LocaleCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ private function getTranslatableLanguage(string $langcode, bool $addLanguage = f

/**
* Check if language is translatable.
*
* @param LanguageInterface $language
*/
private function isTranslatable(LanguageInterface $language): bool
{
Expand Down
4 changes: 0 additions & 4 deletions src/Commands/core/MkCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ protected function prepare($destination): void
/**
* Build an array since that's what HelpCLIFormatter expects.
*
* @param InputArgument $arg
*
* @return iterable
*/
public static function argToArray(InputArgument $arg): iterable
{
Expand All @@ -294,9 +292,7 @@ public static function argToArray(InputArgument $arg): iterable
/**
* Build an array since that's what HelpCLIFormatter expects.
*
* @param InputOption $opt
*
* @return iterable
*/
public static function optionToArray(InputOption $opt): iterable
{
Expand Down
1 change: 0 additions & 1 deletion src/Commands/core/SiteInstallCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ public function serverGlobals($drupal_base_url): void
/**
* Assure that a config directory exists and is populated.
*
* @param CommandData $commandData
* @param $directory
* @throws \Exception
*/
Expand Down
16 changes: 5 additions & 11 deletions src/Commands/core/StatusCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,12 @@ public function getPropertyList($options): array
$status_table['alias-searchpaths'] = array_map([Path::class, 'canonicalize'], $alias_searchpaths);

$paths = self::pathAliases($options, $boot_manager, $boot_object);
if ($paths !== []) {
foreach ($paths as $target => $one_path) {
$name = $target;
if (str_starts_with($name, '%')) {
$name = substr($name, 1);
}
$status_table[$name] = $one_path;
foreach ($paths as $target => $one_path) {
$name = $target;
if (str_starts_with($name, '%')) {
$name = substr($name, 1);
}
$status_table[$name] = $one_path;
}

// Store the paths into the '%paths' index; this will be
Expand Down Expand Up @@ -205,10 +203,6 @@ public function adjustStatusOptions(CommandData $commandData): void
}
}

/**
* @param array $options
* @param BootstrapManager $boot_manager
*/
public static function pathAliases(array $options, BootstrapManager $boot_manager, $boot): array
{
$paths = [];
Expand Down
1 change: 0 additions & 1 deletion src/Commands/core/UserCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ public function infoArray($account): array
/**
* Get accounts from name variables or uid & mail options.
*
* @param string $names
* @param array $options
*
* A array of loaded accounts.
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/generate/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public function discover(): array

/**
* Check each class for existence.
*
* @param array $classes
* @return array
*/
public function filterClassExists(array $classes): array
{
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/generate/GenerateCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Drush\Commands\core\DocsCommands;
use Drush\Commands\DrushCommands;
use Drush\Commands\help\ListCommands;
use Psr\Container\ContainerInterface;
use Psr\Container\ContainerInterface as DrushContainer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
Expand All @@ -20,15 +19,13 @@ final class GenerateCommands extends DrushCommands
const GENERATE = 'generate';

protected function __construct(
private readonly DrushContainer $container,
private readonly DrushContainer $drush_container,
) {
}

public static function create(DrushContainer $container): self
{
return new self(
$container->get('service_container'),
$container,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/pm/PmCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function validateUninstall(CommandData $commandData): void
$modules = StringUtils::csvToArray($modules);
if ($validation_reasons = $this->getModuleInstaller()->validateUninstall($modules)) {
foreach ($validation_reasons as $module => $reason) {
$reasons[$module] = "$module: " . (string)$reason;
$reasons[$module] = "$module: " . $reason;
}
throw new \Exception(implode("/n", $reasons));
}
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/pm/ThemeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function __construct(
parent::__construct();
}

/**
* @return mixed
*/
public function getThemeInstaller(): ThemeInstallerInterface
{
return $this->themeInstaller;
Expand Down
1 change: 0 additions & 1 deletion src/Commands/sql/SqlSyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public function dump(array $options, array $global_options, SiteAlias $sourceRec
}

/**
* @param array $options
* @param $source_dump_path
* Path to the target file.
* @throws \Exception
Expand Down
2 changes: 0 additions & 2 deletions src/Config/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public function loader(): ?ClassLoader

/**
* Set the class loader from the autload.php file, if available.
*
* @param ClassLoader $loader
*/
public function setLoader(ClassLoader $loader): void
{
Expand Down

0 comments on commit f691782

Please sign in to comment.