Skip to content

Commit

Permalink
Add phpstan baseline and bump to level 2 (#5975)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed May 1, 2024
1 parent 9cb5a45 commit 4b22734
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 36 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Expand Up @@ -37,14 +37,14 @@ commands:
fi
executors:
mysql-stable:
mysql-lowest:
docker:
- image: wodby/php:$WODBY_TAG
environment:
- MYSQL_HOST=127.0.0.1
- UNISH_DB_URL=mysql://root:@127.0.0.1/unish_dev?module=mysql
- image: cimg/mysql:5.7.38
sqlite-stable:
sqlite-lowest:
docker:
- image: wodby/php:$WODBY_TAG
environment:
Expand All @@ -56,7 +56,7 @@ executors:
- MYSQL_HOST=127.0.0.1
- UNISH_DB_URL=mysql://root:@127.0.0.1/unish_dev?module=mysql
- image: cimg/mysql:5.7.38
postgres-stable:
postgres-lowest:
docker:
- image: wodby/php:$WODBY_TAG
environment:
Expand Down Expand Up @@ -117,13 +117,13 @@ jobs:
- when:
condition:
and:
- equal: [ stable, << parameters.release >> ]
- equal: [ lowest, << parameters.release >> ]
steps:
- run: composer -n install
- run: composer -n update --prefer-lowest
- unless:
condition:
and:
- equal: [ stable, << parameters.release >> ]
- equal: [ lowest, << parameters.release >> ]
steps:
- run: composer -n config platform.php --unset
- run: composer -n require --dev drupal/core-recommended:11.x-dev --no-update
Expand Down Expand Up @@ -164,7 +164,7 @@ workflows:
#sqlite removed pending https://github.com/wodby/php/issues/194
dbms: [ mysql, postgres ]
suite: [integration, functional]
release: [stable, highest]
release: [ lowest, highest ]
exclude:
# Only run highest test on mysql. Excluding each suite is unfortunate but needed.
- release: highest
Expand Down
46 changes: 46 additions & 0 deletions phpstan-baseline.neon
@@ -0,0 +1,46 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Console\\\\Style\\\\SymfonyStyle\\:\\:askWithCompletion\\(\\)\\.$#"
count: 1
path: src/Commands/DrushCommands.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Console\\\\Style\\\\SymfonyStyle\\:\\:secret\\(\\)\\.$#"
count: 1
path: src/Commands/DrushCommands.php

-
message: "#^Call to an undefined method Drupal\\\\migrate\\\\Plugin\\\\MigrationInterface\\:\\:set\\(\\)\\.$#"
count: 1
path: src/Commands/core/MigrateRunnerCommands.php

-
message: "#^Result of method Drush\\\\Style\\\\DrushStyle\\:\\:text\\(\\) \\(void\\) is used\\.$#"
count: 6
path: src/Commands/core/SiteInstallCommands.php

-
message: "#^Result of method Drush\\\\Style\\\\DrushStyle\\:\\:text\\(\\) \\(void\\) is used\\.$#"
count: 2
path: src/Commands/field/FieldBaseOverrideCreateCommands.php

-
message: "#^Result of method Drush\\\\Style\\\\DrushStyle\\:\\:text\\(\\) \\(void\\) is used\\.$#"
count: 4
path: src/Commands/field/FieldCreateCommands.php

-
message: "#^Call to an undefined method Drupal\\\\Core\\\\DependencyInjection\\\\ServiceModifierInterface\\:\\:check\\(\\)\\.$#"
count: 1
path: src/Drupal/DrupalKernel.php

-
message: "#^Call to an undefined method Drupal\\\\Core\\\\DependencyInjection\\\\ServiceModifierInterface\\:\\:check\\(\\)\\.$#"
count: 1
path: src/Drupal/InstallerKernel.php

-
message: "#^Call to an undefined method Drupal\\\\Core\\\\DependencyInjection\\\\ServiceModifierInterface\\:\\:check\\(\\)\\.$#"
count: 1
path: src/Drupal/UpdateKernel.php
3 changes: 2 additions & 1 deletion phpstan.neon.dist
@@ -1,5 +1,5 @@
parameters:
level: 1
level: 2
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
bootstrapFiles:
- phpstan-bootstrap.php
Expand Down Expand Up @@ -27,3 +27,4 @@ parameters:
- '#Constant TIDEWAYS_XHPROF_FLAGS_MEMORY not found.#'
includes:
- vendor/mglaman/phpstan-drupal/extension.neon
- phpstan-baseline.neon
2 changes: 1 addition & 1 deletion src/Boot/BootstrapManager.php
Expand Up @@ -137,7 +137,7 @@ public function bootstrap(): DrupalBoot8
/**
* For use in testing
*/
public function injectBootstrap(Boot $bootstrap): void
public function injectBootstrap(DrupalBoot8 $bootstrap): void
{
$bootstrap->setLogger($this->logger());
$this->bootstrap = $bootstrap;
Expand Down
2 changes: 2 additions & 0 deletions src/Boot/DrupalBoot8.php
Expand Up @@ -21,6 +21,7 @@
use Robo\Robo;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\TerminableInterface;

class DrupalBoot8 extends DrupalBoot
{
Expand Down Expand Up @@ -321,6 +322,7 @@ public function terminate(): void
} else {
$response = new HtmlResponse();
}
assert($this->kernel instanceof TerminableInterface);
$this->kernel->terminate($this->getRequest(), $response);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/config/ConfigPullCommands.php
Expand Up @@ -9,6 +9,7 @@
use Consolidation\OutputFormatters\StructuredData\PropertyList;
use Consolidation\SiteAlias\HostPath;
use Consolidation\SiteAlias\SiteAliasManagerInterface;
use Consolidation\SiteProcess\SiteProcess;
use Drush\Attributes as CLI;
use Drush\Boot\DrupalBootLevels;
use Drush\Commands\AutowireTrait;
Expand Down Expand Up @@ -96,6 +97,7 @@ public function validateConfigPull(CommandData $commandData): void
{
if ($commandData->input()->getOption('safe')) {
$destinationRecord = $this->siteAliasManager->get($commandData->input()->getArgument('destination'));
/** @var SiteProcess $process */
$process = $this->processManager()->siteProcess($destinationRecord, ['git', 'diff', '--quiet']);
$process->chdirToSiteRoot();
$process->run();
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/core/QueueCommands.php
Expand Up @@ -76,7 +76,9 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items-

while ((!$time_limit || $remaining > 0) && (!$items_limit || $count < $items_limit) && ($item = $queue->claimItem($lease_time))) {
try {
// @phpstan-ignore-next-line
$this->logger()->info(dt('Processing item @id from @name queue.', ['@name' => $name, '@id' => $item->item_id ?? $item->qid]));
// @phpstan-ignore-next-line
$worker->processItem($item->data);
$queue->deleteItem($item);
$count++;
Expand Down
1 change: 1 addition & 0 deletions src/Commands/core/RsyncCommands.php
Expand Up @@ -140,6 +140,7 @@ protected function injectAliasPathParameterOptions($input, $parameterName)
// options into the alias config context so that we pick up
// things like ssh-options.
if ($aliasRecord->isRemote()) {
assert($aliasConfigContext instanceof \Consolidation\Config\Config);
$aliasConfigContext->combine($aliasRecord->export());
}

Expand Down
5 changes: 4 additions & 1 deletion src/Commands/core/SiteInstallCommands.php
Expand Up @@ -13,6 +13,7 @@
use Drupal\Core\Database\Database;
use Drupal\Core\Installer\Exception\AlreadyInstalledException;
use Drupal\Core\Installer\Exception\InstallerException;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Mail\MailFormatHelper;
use Drupal\Core\Site\Settings;
use Drush\Attributes as CLI;
Expand Down Expand Up @@ -201,7 +202,9 @@ protected function determineProfile($profile, $options): string|bool

if (empty($profile)) {
$boot = $this->bootstrapManager->bootstrap();
$profile = $boot->getKernel()->getInstallProfile();
$kernel = $boot->getKernel();
assert($kernel instanceof InstallerKernel);
$profile = $kernel->getInstallProfile();
}

if (empty($profile)) {
Expand Down
11 changes: 2 additions & 9 deletions src/Commands/core/UpdateDBCommands.php
Expand Up @@ -4,11 +4,11 @@

namespace Drush\Commands\core;

use Drupal\Core\Update\UpdateRegistry;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Consolidation\OutputFormatters\StructuredData\UnstructuredListData;
use Consolidation\SiteAlias\SiteAliasManagerInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\Update\UpdateRegistry;
use Drupal\Core\Utility\Error;
use Drush\Attributes as CLI;
use Drush\Boot\DrupalBootLevels;
Expand Down Expand Up @@ -271,14 +271,7 @@ public static function updateDoOnePostUpdate(string $function, array $context):
}

list($extension, $name) = explode('_post_update_', $function, 2);
$update_registry = \Drupal::service('update.post_update_registry');
// https://www.drupal.org/project/drupal/issues/3259188 Support theme's
// having post update functions when it is supported in Drupal core.
if (method_exists($update_registry, 'getUpdateFunctions')) {
\Drupal::service('update.post_update_registry')->getUpdateFunctions($extension);
} else {
\Drupal::service('update.post_update_registry')->getModuleUpdateFunctions($extension);
}
\Drupal::service('update.post_update_registry')->getUpdateFunctions($extension);

if (function_exists($function)) {
if (empty($context['results'][$extension][$name]['type'])) {
Expand Down
1 change: 1 addition & 0 deletions src/Commands/field/FieldCreateCommands.php
Expand Up @@ -489,6 +489,7 @@ protected function createFieldDisplay(string $context): void
$storage->save();
}

assert($storage instanceof EntityDisplayInterface);
$storage->setComponent($fieldName, $values)->save();
}

Expand Down
3 changes: 3 additions & 0 deletions src/Commands/field/FieldDeleteCommands.php
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drush\Attributes as CLI;
use Drush\Commands\AutowireTrait;
use Drush\Commands\DrushCommands;
Expand Down Expand Up @@ -251,6 +252,8 @@ protected function getFieldConfigs(string $entityType, ?string $bundle): array
protected function deleteFieldConfig(FieldConfigInterface $fieldConfig): void
{
$fieldStorage = $fieldConfig->getFieldStorageDefinition();
assert($fieldStorage instanceof FieldStorageConfigInterface);

$bundles = $this->entityTypeBundleInfo->getBundleInfo($fieldConfig->getTargetEntityTypeId());
$bundleLabel = $bundles[$fieldConfig->getTargetBundle()]['label'];

Expand Down
15 changes: 7 additions & 8 deletions src/Config/ConfigLocator.php
Expand Up @@ -5,7 +5,7 @@
namespace Drush\Config;

use Consolidation\Config\ConfigInterface;
use Consolidation\Config\Loader\ConfigLoaderInterface;
use Consolidation\Config\Loader\ConfigLoader;
use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Util\EnvConfig;
use Drush\Config\Loader\YamlConfigLoader;
Expand All @@ -32,12 +32,9 @@
*/
class ConfigLocator
{
/**
* @var ConfigInterface
*/
protected $config;
protected DrushConfig $config;

protected $isLocal;
protected bool $isLocal;

protected $sources = false;

Expand Down Expand Up @@ -194,7 +191,9 @@ public function config(): ConfigInterface
*/
public function addEnvironment(Environment $environment): self
{
$this->config->getContext(self::ENVIRONMENT_CONTEXT)->import($environment->exportConfigData());
/** @var DrushConfig $context */
$context = $this->config->getContext(self::ENVIRONMENT_CONTEXT);
$context->replace($environment->exportConfigData());
return $this;
}

Expand Down Expand Up @@ -317,7 +316,7 @@ public function addConfigPaths(string $contextName, array $paths): self
/**
* Adds $configFiles to the list of config files.
*/
protected function addConfigFiles(ConfigProcessor $processor, ConfigLoaderInterface $loader, array $configFiles): void
protected function addConfigFiles(ConfigProcessor $processor, ConfigLoader $loader, array $configFiles): void
{
foreach ($configFiles as $configFile) {
$processor->extend($loader->load($configFile));
Expand Down
10 changes: 7 additions & 3 deletions src/Drupal/Migrate/MigrateExecutable.php
Expand Up @@ -4,7 +4,6 @@

namespace Drush\Drupal\Migrate;

use Drupal\migrate\MigrateException;
use Drupal\Component\Utility\Timer;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\Event\MigrateImportEvent;
Expand All @@ -22,6 +21,7 @@
use Drush\Drupal\Migrate\MigrateEvents as MigrateRunnerEvents;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class MigrateExecutable extends MigrateExecutableBase
{
Expand Down Expand Up @@ -164,8 +164,10 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa
$this->listeners[MigrateRunnerEvents::DRUSH_MIGRATE_PREPARE_ROW] = [$this, 'onPrepareRow'];
$this->listeners[MigrateMissingSourceRowsEvent::class] = [$this, 'onMissingSourceRows'];

$eventDispatcher = $this->getEventDispatcher();
assert($eventDispatcher instanceof EventDispatcherInterface);
foreach ($this->listeners as $event => $listener) {
$this->getEventDispatcher()->addListener($event, $listener);
$eventDispatcher->addListener($event, $listener);
}
}

Expand Down Expand Up @@ -612,8 +614,10 @@ public function progressFinish(): void
*/
public function unregisterListeners(): void
{
$eventDispatcher = $this->getEventDispatcher();
assert($eventDispatcher instanceof EventDispatcherInterface);
foreach ($this->listeners as $event => $listener) {
$this->getEventDispatcher()->removeListener($event, $listener);
$eventDispatcher->removeListener($event, $listener);
}
}
}
8 changes: 4 additions & 4 deletions src/Preflight/PreflightSiteLocator.php
Expand Up @@ -26,10 +26,10 @@ public function __construct(SiteAliasManager $siteAliasManager)
* If 'false' is returned, that indicates that there was an alias name
* provided on the commandline that is either missing or invalid.
*
* @param PreflightArgsInterface $preflightArgs An alias name or site specification
* @param PreflightArgs $preflightArgs An alias name or site specification
* @param string $root The default Drupal root (from site:set, --root or cwd)
*/
public function findSite(PreflightArgsInterface $preflightArgs, Environment $environment, string $root): SiteAlias|false
public function findSite(PreflightArgs $preflightArgs, Environment $environment, string $root): SiteAlias|false
{
$self = $this->determineSelf($preflightArgs, $environment, $root);

Expand All @@ -47,7 +47,7 @@ public function findSite(PreflightArgsInterface $preflightArgs, Environment $env
* or, if those are invalid, then generate one from
* the provided root and URI.
*/
protected function determineSelf(PreflightArgsInterface $preflightArgs, Environment $environment, $root): SiteAlias|false
protected function determineSelf(PreflightArgs $preflightArgs, Environment $environment, $root): SiteAlias|false
{
if ($preflightArgs->hasAlias()) {
$aliasName = $preflightArgs->alias();
Expand Down Expand Up @@ -85,7 +85,7 @@ protected function determineSelf(PreflightArgsInterface $preflightArgs, Environm
/**
* Generate @self from the provided root and URI.
*/
protected function buildSelf(PreflightArgsInterface $preflightArgs, ?string $root): SiteAlias
protected function buildSelf(PreflightArgs $preflightArgs, ?string $root): SiteAlias
{
// If there is no root, then return '@none'
if (!$root) {
Expand Down
5 changes: 4 additions & 1 deletion src/Psysh/DrushCommand.php
Expand Up @@ -6,8 +6,9 @@

use Consolidation\AnnotatedCommand\AnnotatedCommand;
use Drush\Drush;
use Symfony\Component\Console\Command\Command;
use Psy\Command\Command as BaseCommand;
use Psy\Output\ShellOutput;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -62,6 +63,8 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
assert($output instanceof ShellOutput);

$args = $input->getArguments();
$first = array_shift($args);

Expand Down

0 comments on commit 4b22734

Please sign in to comment.