From e258ce6c28c69c8faaf0286b24b44654e65554a3 Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Thu, 20 Mar 2025 15:56:15 +0100
Subject: [PATCH 1/2] Issue #3514018 by grimreaper: Code cleanup

---
 .../src/HookHandler/FormBlockFormAlter.php    |  7 ++---
 .../src/HookHandler/PreprocessBlock.php       | 31 ++-----------------
 .../Plugin/CKEditor5Plugin/UiStylesBase.php   | 27 ++--------------
 .../src/HookHandler/EntityView.php            | 19 ++----------
 .../BlockComponentRenderArraySubscriber.php   | 19 ++----------
 .../src/HookHandler/EntityViewAlter.php       | 19 ++----------
 .../Controller/StylesLibraryController.php    | 18 +++--------
 .../src/Plugin/Derivative/RegionStyles.php    | 31 ++-----------------
 .../Plugin/views/display_extender/Styles.php  |  3 +-
 .../src/MachineNameTraitTestClass.php         | 12 ++-----
 10 files changed, 26 insertions(+), 160 deletions(-)

diff --git a/modules/ui_styles_block/src/HookHandler/FormBlockFormAlter.php b/modules/ui_styles_block/src/HookHandler/FormBlockFormAlter.php
index 4c5996b..b2e240d 100644
--- a/modules/ui_styles_block/src/HookHandler/FormBlockFormAlter.php
+++ b/modules/ui_styles_block/src/HookHandler/FormBlockFormAlter.php
@@ -24,15 +24,14 @@ class FormBlockFormAlter {
    *   The form state.
    */
   public function blockFormAlter(array &$form, FormStateInterface $formState): void {
-    /** @var \Drupal\block\BlockForm $form_object */
     $form_object = $formState->getFormObject();
-    /** @var \Drupal\block\BlockInterface $block */
-    $block = $form_object->getEntity();
-
     if (!($form_object instanceof EntityFormInterface)) {
       return;
     }
 
+    /** @var \Drupal\block\BlockInterface $block */
+    $block = $form_object->getEntity();
+
     $theme = $block->getTheme();
     if ($theme == NULL) {
       return;
diff --git a/modules/ui_styles_block/src/HookHandler/PreprocessBlock.php b/modules/ui_styles_block/src/HookHandler/PreprocessBlock.php
index 3a80ca7..08351d5 100644
--- a/modules/ui_styles_block/src/HookHandler/PreprocessBlock.php
+++ b/modules/ui_styles_block/src/HookHandler/PreprocessBlock.php
@@ -16,35 +16,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  */
 class PreprocessBlock implements ContainerInjectionInterface {
 
-  /**
-   * The entity type manager.
-   *
-   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
-   */
-  protected EntityTypeManagerInterface $entityTypeManager;
-
-  /**
-   * The styles plugin manager.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected StylePluginManagerInterface $stylesManager;
-
-  /**
-   * Constructor.
-   *
-   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
-   *   The entity type manager.
-   * @param \Drupal\ui_styles\StylePluginManagerInterface $stylesManager
-   *   The styles plugin manager.
-   */
   public function __construct(
-    EntityTypeManagerInterface $entityTypeManager,
-    StylePluginManagerInterface $stylesManager,
-  ) {
-    $this->entityTypeManager = $entityTypeManager;
-    $this->stylesManager = $stylesManager;
-  }
+    protected EntityTypeManagerInterface $entityTypeManager,
+    protected StylePluginManagerInterface $stylesManager,
+  ) {}
 
   /**
    * {@inheritdoc}
diff --git a/modules/ui_styles_ckeditor5/src/Plugin/CKEditor5Plugin/UiStylesBase.php b/modules/ui_styles_ckeditor5/src/Plugin/CKEditor5Plugin/UiStylesBase.php
index ecfd675..f9af91b 100644
--- a/modules/ui_styles_ckeditor5/src/Plugin/CKEditor5Plugin/UiStylesBase.php
+++ b/modules/ui_styles_ckeditor5/src/Plugin/CKEditor5Plugin/UiStylesBase.php
@@ -39,13 +39,6 @@ abstract class UiStylesBase extends CKEditor5PluginDefault implements CKEditor5P
     'enabled_styles' => [],
   ];
 
-  /**
-   * The styles plugin manager.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected StylePluginManagerInterface $stylesManager;
-
   /**
    * The CKE5 config key.
    *
@@ -53,30 +46,14 @@ abstract class UiStylesBase extends CKEditor5PluginDefault implements CKEditor5P
    */
   protected string $ckeditor5ConfigKey;
 
-  /**
-   * Constructor.
-   *
-   * @param array $configuration
-   *   A configuration array containing information about the plugin instance.
-   * @param string $plugin_id
-   *   The plugin_id for the plugin instance.
-   * @param \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition $plugin_definition
-   *   The plugin implementation definition.
-   * @param \Drupal\ui_styles\StylePluginManagerInterface $stylesManager
-   *   The styles plugin manager.
-   * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
-   *   The transliteration service.
-   */
   public function __construct(
     array $configuration,
     string $plugin_id,
     CKEditor5PluginDefinition $plugin_definition,
-    StylePluginManagerInterface $stylesManager,
-    TransliterationInterface $transliteration,
+    protected StylePluginManagerInterface $stylesManager,
+    protected TransliterationInterface $transliteration,
   ) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
-    $this->stylesManager = $stylesManager;
-    $this->transliteration = $transliteration;
   }
 
   /**
diff --git a/modules/ui_styles_entity_status/src/HookHandler/EntityView.php b/modules/ui_styles_entity_status/src/HookHandler/EntityView.php
index bdd1e1b..9bdd81b 100644
--- a/modules/ui_styles_entity_status/src/HookHandler/EntityView.php
+++ b/modules/ui_styles_entity_status/src/HookHandler/EntityView.php
@@ -22,24 +22,9 @@ class EntityView implements ContainerInjectionInterface {
 
   use SectionStorageTrait;
 
-  /**
-   * The styles plugin manager.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected StylePluginManagerInterface $stylesManager;
-
-  /**
-   * Constructor.
-   *
-   * @param \Drupal\ui_styles\StylePluginManagerInterface $stylesManager
-   *   The styles plugin manager.
-   */
   public function __construct(
-    StylePluginManagerInterface $stylesManager,
-  ) {
-    $this->stylesManager = $stylesManager;
-  }
+    protected StylePluginManagerInterface $stylesManager,
+  ) {}
 
   /**
    * {@inheritdoc}
diff --git a/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php b/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php
index bc9eca5..f8310cf 100644
--- a/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php
+++ b/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php
@@ -15,22 +15,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  */
 class BlockComponentRenderArraySubscriber implements EventSubscriberInterface {
 
-  /**
-   * The style manager.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected $styleManager;
-
-  /**
-   * Constructor.
-   *
-   * @param \Drupal\ui_styles\StylePluginManagerInterface $style_manager
-   *   The style manager.
-   */
-  public function __construct(StylePluginManagerInterface $style_manager) {
-    $this->styleManager = $style_manager;
-  }
+  public function __construct(
+    protected StylePluginManagerInterface $styleManager
+  ) {}
 
   /**
    * {@inheritdoc}
diff --git a/modules/ui_styles_layout_builder/src/HookHandler/EntityViewAlter.php b/modules/ui_styles_layout_builder/src/HookHandler/EntityViewAlter.php
index 5a71273..4d58b9e 100644
--- a/modules/ui_styles_layout_builder/src/HookHandler/EntityViewAlter.php
+++ b/modules/ui_styles_layout_builder/src/HookHandler/EntityViewAlter.php
@@ -22,24 +22,9 @@ class EntityViewAlter implements ContainerInjectionInterface {
 
   use SectionStorageTrait;
 
-  /**
-   * The styles plugin manager.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected StylePluginManagerInterface $stylesManager;
-
-  /**
-   * Constructor.
-   *
-   * @param \Drupal\ui_styles\StylePluginManagerInterface $stylesManager
-   *   The styles plugin manager.
-   */
   public function __construct(
-    StylePluginManagerInterface $stylesManager,
-  ) {
-    $this->stylesManager = $stylesManager;
-  }
+    protected StylePluginManagerInterface $stylesManager,
+  ) {}
 
   /**
    * {@inheritdoc}
diff --git a/modules/ui_styles_library/src/Controller/StylesLibraryController.php b/modules/ui_styles_library/src/Controller/StylesLibraryController.php
index a9ddd5d..023a7d6 100644
--- a/modules/ui_styles_library/src/Controller/StylesLibraryController.php
+++ b/modules/ui_styles_library/src/Controller/StylesLibraryController.php
@@ -13,24 +13,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  */
 class StylesLibraryController extends ControllerBase {
 
-  /**
-   * Styles manager service.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected $stylesManager;
-
-  /**
-   * {@inheritdoc}
-   */
-  final public function __construct(StylePluginManagerInterface $styles_manager) {
-    $this->stylesManager = $styles_manager;
-  }
+  public function __construct(
+    protected StylePluginManagerInterface $stylesManager
+  ) {}
 
   /**
    * {@inheritdoc}
    */
-  public static function create(ContainerInterface $container): self {
+  public static function create(ContainerInterface $container): static {
     return new static($container->get('plugin.manager.ui_styles'));
   }
 
diff --git a/modules/ui_styles_page/src/Plugin/Derivative/RegionStyles.php b/modules/ui_styles_page/src/Plugin/Derivative/RegionStyles.php
index 2707aeb..22cb563 100644
--- a/modules/ui_styles_page/src/Plugin/Derivative/RegionStyles.php
+++ b/modules/ui_styles_page/src/Plugin/Derivative/RegionStyles.php
@@ -15,35 +15,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  */
 class RegionStyles extends DeriverBase implements ContainerDeriverInterface {
 
-  /**
-   * The theme handler.
-   *
-   * @var \Drupal\Core\Extension\ThemeHandlerInterface
-   */
-  protected ThemeHandlerInterface $themeHandler;
-
-  /**
-   * The plugin manager.
-   *
-   * @var \Drupal\ui_styles\StylePluginManagerInterface
-   */
-  protected StylePluginManagerInterface $stylesManager;
-
-  /**
-   * Constructor.
-   *
-   * @param \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler
-   *   The theme handler.
-   * @param \Drupal\ui_styles\StylePluginManagerInterface $stylesManager
-   *   The styles plugin manager.
-   */
   public function __construct(
-    ThemeHandlerInterface $themeHandler,
-    StylePluginManagerInterface $stylesManager,
-  ) {
-    $this->themeHandler = $themeHandler;
-    $this->stylesManager = $stylesManager;
-  }
+    protected ThemeHandlerInterface $themeHandler,
+    protected StylePluginManagerInterface $stylesManager,
+  ) {}
 
   /**
    * {@inheritdoc}
diff --git a/modules/ui_styles_views/src/Plugin/views/display_extender/Styles.php b/modules/ui_styles_views/src/Plugin/views/display_extender/Styles.php
index 63f4a3a..24cc8e9 100644
--- a/modules/ui_styles_views/src/Plugin/views/display_extender/Styles.php
+++ b/modules/ui_styles_views/src/Plugin/views/display_extender/Styles.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
 namespace Drupal\ui_styles_views\Plugin\views\display_extender;
 
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\ui_styles\StylePluginManagerInterface;
 use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
@@ -27,7 +28,7 @@ class Styles extends DisplayExtenderPluginBase {
    *
    * @var \Drupal\ui_styles\StylePluginManagerInterface
    */
-  protected $stylesManager;
+  protected StylePluginManagerInterface $stylesManager;
 
   /**
    * {@inheritdoc}
diff --git a/tests/modules/ui_styles_test/src/MachineNameTraitTestClass.php b/tests/modules/ui_styles_test/src/MachineNameTraitTestClass.php
index 39be1fc..54892a3 100644
--- a/tests/modules/ui_styles_test/src/MachineNameTraitTestClass.php
+++ b/tests/modules/ui_styles_test/src/MachineNameTraitTestClass.php
@@ -14,17 +14,9 @@ class MachineNameTraitTestClass {
 
   use MachineNameTrait;
 
-  /**
-   * Constructor.
-   *
-   * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
-   *   The transliteration service.
-   */
   public function __construct(
-    TransliterationInterface $transliteration,
-  ) {
-    $this->transliteration = $transliteration;
-  }
+    protected TransliterationInterface $transliteration,
+  ) {}
 
   /**
    * Wrapper around protected method.
-- 
GitLab


From 89f63006684eb8a608e5b7e7fc7955ee5e6fe1fc Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Thu, 20 Mar 2025 16:04:18 +0100
Subject: [PATCH 2/2] Issue #3514018 by grimreaper: Code cleanup

---
 .../src/EventSubscriber/BlockComponentRenderArraySubscriber.php | 2 +-
 .../src/Controller/StylesLibraryController.php                  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php b/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php
index f8310cf..aaaa4f9 100644
--- a/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php
+++ b/modules/ui_styles_layout_builder/src/EventSubscriber/BlockComponentRenderArraySubscriber.php
@@ -16,7 +16,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 class BlockComponentRenderArraySubscriber implements EventSubscriberInterface {
 
   public function __construct(
-    protected StylePluginManagerInterface $styleManager
+    protected StylePluginManagerInterface $styleManager,
   ) {}
 
   /**
diff --git a/modules/ui_styles_library/src/Controller/StylesLibraryController.php b/modules/ui_styles_library/src/Controller/StylesLibraryController.php
index 023a7d6..454b2f7 100644
--- a/modules/ui_styles_library/src/Controller/StylesLibraryController.php
+++ b/modules/ui_styles_library/src/Controller/StylesLibraryController.php
@@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 class StylesLibraryController extends ControllerBase {
 
   public function __construct(
-    protected StylePluginManagerInterface $stylesManager
+    protected StylePluginManagerInterface $stylesManager,
   ) {}
 
   /**
-- 
GitLab