diff --git a/analyze.module b/analyze.module index d7fad0f..d42cf68 100644 --- a/analyze.module +++ b/analyze.module @@ -107,6 +107,10 @@ function analyze_local_tasks_alter(array &$local_tasks): void { * Implements hook_form_alter(). * * @phpstan-param array $form + * @phpstan-param \Drupal\Core\Form\FormStateInterface $form_state + * @phpstan-param string $form_id + * + * @param-out array $form */ function analyze_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void { if ($form_id !== 'analyze_analyze_settings') { @@ -144,12 +148,14 @@ function analyze_form_alter(array &$form, FormStateInterface $form_state, string /** * Helper to add Analyze settings to a form. * - * @param mixed[] $form - * The form. + * @param array $form + * The form array. * @param string $entity_type * The entity type the settings are for. * @param string|null $bundle * The bundle the settings are for. + * + * @param-out array $form */ function analyze_add_settings_form(array &$form, string $entity_type, ?string $bundle = NULL): void { // If the user doesn't have the permission. diff --git a/docker-compose.yml b/docker-compose.yml index 4bde22c..6a771c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: working_dir: /src command: bash -c "./scripts/run-drupal-lint.sh" environment: - TARGET_DRUPAL_CORE_VERSION: 10 + TARGET_DRUPAL_CORE_VERSION: 11 volumes: - .:/src @@ -16,7 +16,7 @@ services: working_dir: /src command: bash -c "./scripts/run-drupal-lint-auto-fix.sh" environment: - TARGET_DRUPAL_CORE_VERSION: 10 + TARGET_DRUPAL_CORE_VERSION: 11 volumes: - .:/src @@ -27,6 +27,6 @@ services: command: bash -c "/src/scripts/run-drupal-check.sh" tty: true environment: - DRUPAL_RECOMMENDED_PROJECT: 10.3.x-dev + DRUPAL_RECOMMENDED_PROJECT: 11.x-dev volumes: - .:/src diff --git a/modules/analyze_basic_content_info/src/Plugin/Analyze/ContentInfo.php b/modules/analyze_basic_content_info/src/Plugin/Analyze/ContentInfo.php index 55d2645..04d290d 100644 --- a/modules/analyze_basic_content_info/src/Plugin/Analyze/ContentInfo.php +++ b/modules/analyze_basic_content_info/src/Plugin/Analyze/ContentInfo.php @@ -133,9 +133,7 @@ private function getImageCount(EntityInterface $entity): int { $matches = []; preg_match_all('/renderer->render($view); // Handle both string and Markup object cases. - return is_object($rendered) && method_exists($rendered, '__toString') - ? $rendered->__toString() - : (string) $rendered; + return (string) $rendered; } /** diff --git a/src/AnalyzePluginBase.php b/src/AnalyzePluginBase.php index cb0898f..acb49f1 100644 --- a/src/AnalyzePluginBase.php +++ b/src/AnalyzePluginBase.php @@ -53,6 +53,7 @@ public function __construct( * @phpstan-param array $configuration */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static { + // @phpstan-ignore-next-line - This is intended to be called by subclasses return new static( $configuration, $plugin_id, @@ -71,7 +72,7 @@ public static function create(ContainerInterface $container, array $configuratio */ protected function getConfigFactory(): ConfigFactoryInterface { if (!$this->configFactory) { - $this->configFactory = \Drupal::service('config.factory'); + throw new \RuntimeException('Config factory not injected. Please ensure the plugin is created using dependency injection.'); } return $this->configFactory; } @@ -302,7 +303,7 @@ protected function saveEntityTypeSettings(string $entity_type_id, array $setting * The settings to save. */ public function saveSettings(string $entity_type_id, ?string $bundle, array $settings): void { - $config = \Drupal::configFactory()->getEditable('analyze.settings'); + $config = $this->getConfigFactory()->getEditable('analyze.settings'); $current = $config->get('status') ?? []; // Save enabled state. @@ -313,7 +314,7 @@ public function saveSettings(string $entity_type_id, ?string $bundle, array $set // Save detailed settings if present. if (isset($settings['settings'])) { - $detailed_config = \Drupal::configFactory()->getEditable('analyze.plugin_settings'); + $detailed_config = $this->getConfigFactory()->getEditable('analyze.plugin_settings'); $key = sprintf('%s.%s.%s', $entity_type_id, $bundle, $this->getPluginId()); $detailed_config->set($key, $settings['settings'])->save(); } diff --git a/src/Controller/AnalyzeController.php b/src/Controller/AnalyzeController.php index 9c3f373..4ce5dd9 100644 --- a/src/Controller/AnalyzeController.php +++ b/src/Controller/AnalyzeController.php @@ -29,7 +29,8 @@ public function __construct( /** * {@inheritdoc} */ - public static function create(ContainerInterface $container) { + public static function create(ContainerInterface $container): static { + // @phpstan-ignore-next-line - This is a final class, safe to use new static() return new static( $container->get('analyze.helper') ); diff --git a/src/Form/AnalyzeSettingsForm.php b/src/Form/AnalyzeSettingsForm.php index 1146b9f..758629e 100644 --- a/src/Form/AnalyzeSettingsForm.php +++ b/src/Form/AnalyzeSettingsForm.php @@ -118,7 +118,12 @@ public function buildForm(array $form, FormStateInterface $form_state): array { /** * {@inheritdoc} * - * @phpstan-param array $form + * @param array $form + * The form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * + * @param-out array $form */ public function submitForm(array &$form, FormStateInterface $form_state): void { $values = $form_state->cleanValues()->getValues(); @@ -137,6 +142,7 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { $this->config('analyze.settings') ->set('status', $settings) ->save(); + // @phpstan-ignore-next-line - Parent method accepts array reference parent::submitForm($form, $form_state); }