From e4169a9fcd6b7ee6ac7125698ee2ffd66f5560a4 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner <27807-mkalkbrenner@users.noreply.drupalcode.org> Date: Tue, 5 Dec 2023 18:15:30 +0100 Subject: [PATCH] Issue #3406269 by mkalkbrenner: Fix phpcs, phpstan, stylelint findings --- .../suggester/Suggester.php | 5 +-- .../AbstractSolrEntityListBuilder.php | 40 ++++++++++--------- src/Controller/SolrFieldTypeListBuilder.php | 22 +++++----- src/Entity/AbstractSolrEntity.php | 8 ---- src/EnvironmentAwareSolrConfigInterface.php | 18 +++++++++ src/SolrCacheInterface.php | 12 +----- src/SolrConfigInterface.php | 8 ++++ src/SolrFieldTypeInterface.php | 6 +-- src/SolrRequestDispatcherInterface.php | 10 +---- src/SolrRequestHandlerInterface.php | 10 +---- 10 files changed, 67 insertions(+), 72 deletions(-) create mode 100644 src/EnvironmentAwareSolrConfigInterface.php diff --git a/modules/search_api_solr_autocomplete/src/Plugin/search_api_autocomplete/suggester/Suggester.php b/modules/search_api_solr_autocomplete/src/Plugin/search_api_autocomplete/suggester/Suggester.php index 64c52f1b..6384b443 100644 --- a/modules/search_api_solr_autocomplete/src/Plugin/search_api_autocomplete/suggester/Suggester.php +++ b/modules/search_api_solr_autocomplete/src/Plugin/search_api_autocomplete/suggester/Suggester.php @@ -12,13 +12,12 @@ use Drupal\search_api_autocomplete\Suggester\SuggesterPluginBase; use Drupal\search_api_autocomplete\Suggestion\SuggestionFactory; use Drupal\search_api_solr\Solarium\Autocomplete\Query as AutocompleteQuery; +use Drupal\search_api_solr\Solarium\Autocomplete\Result; use Drupal\search_api_solr\SolrAutocompleteBackendTrait; use Drupal\search_api_solr\SolrBackendInterface; use Drupal\search_api_solr\Utility\Utility; use Drupal\search_api_solr_autocomplete\Event\PreSuggesterQueryEvent; use Solarium\Component\ComponentAwareQueryInterface; -use Solarium\Core\Query\Result\ResultInterface; -use Solarium\QueryType\Select\Result\Result; /** * Provides a suggester plugin that retrieves suggestions from the server. @@ -259,7 +258,7 @@ protected function setAutocompleteSuggesterQuery(QueryInterface $query, Autocomp /** * Get the term suggestions from the autocomplete query result. * - * @param \Solarium\QueryType\Select\Result\Result $result + * @param \Drupal\search_api_solr\Solarium\Autocomplete\Result $result * An autocomplete query result. * @param \Drupal\search_api_autocomplete\Suggestion\SuggestionFactory $suggestion_factory * The suggestion factory. diff --git a/src/Controller/AbstractSolrEntityListBuilder.php b/src/Controller/AbstractSolrEntityListBuilder.php index 5c4279b8..c7b79aa7 100644 --- a/src/Controller/AbstractSolrEntityListBuilder.php +++ b/src/Controller/AbstractSolrEntityListBuilder.php @@ -60,17 +60,17 @@ public function buildHeader() { /** * {@inheritdoc} */ - public function buildRow(EntityInterface $solr_entity) { - /** @var \Drupal\search_api_solr\SolrConfigInterface $solr_entity */ - $options = $solr_entity->getOptions(); + public function buildRow(EntityInterface $entity) { + /** @var \Drupal\search_api_solr\SolrConfigInterface $entity */ + $options = $entity->getOptions(); if (empty($options)) { $options = [$this->default_option]; } - $enabled_label = $solr_entity->isDisabledOnServer() ? $this->t('Disabled') : $this->t('Enabled'); + $enabled_label = $entity->isDisabledOnServer() ? $this->t('Disabled') : $this->t('Enabled'); $enabled_icon = [ '#theme' => 'image', - '#uri' => !$solr_entity->isDisabledOnServer() ? 'core/misc/icons/73b355/check.svg' : 'core/misc/icons/e32700/error.svg', + '#uri' => !$entity->isDisabledOnServer() ? 'core/misc/icons/73b355/check.svg' : 'core/misc/icons/e32700/error.svg', '#width' => 18, '#height' => 18, '#alt' => $enabled_label, @@ -78,17 +78,17 @@ public function buildRow(EntityInterface $solr_entity) { ]; $row = [ - 'label' => $solr_entity->label(), - 'minimum_solr_version' => $solr_entity->getMinimumSolrVersion(), + 'label' => $entity->label(), + 'minimum_solr_version' => $entity->getMinimumSolrVersion(), // @todo format 'options' => implode(', ', $options), - 'id' => $solr_entity->id(), + 'id' => $entity->id(), 'enabled' => [ 'data' => $enabled_icon, 'class' => ['checkbox'], ], ]; - return $row + parent::buildRow($solr_entity); + return $row + parent::buildRow($entity); } /** @@ -151,14 +151,17 @@ public function getDefaultOperations(EntityInterface $solr_entity) { /** * Get all disabled entities. */ - abstract protected function getDisabledEntities() : array; + abstract protected function getDisabledEntities(): array; - /** + /** @var \Drupal\search_api_solr\Entity\AbstractSolrEntity[] $entities /** * {@inheritdoc} * + * @return \Drupal\search_api_solr\Entity\AbstractSolrEntity[] + * Solr entities. + * * @throws \Drupal\search_api\SearchApiException */ - public function load() { + public function load(): array { static $entities; if (!$entities || $this->reset) { @@ -186,9 +189,8 @@ public function load() { // We need the whole list to work on. $this->limit = FALSE; $entity_ids = $this->getEntityIds(); - /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */ $storage = $this->getStorage(); - /** @var \Drupal\search_api_solr\SolrConfigInterface[] $entities */ + /** @var \Drupal\search_api_solr\EnvironmentAwareSolrConfigInterface[] $entities */ $entities = $storage->loadMultipleOverrideFree($entity_ids); // We filter those entities that are relevant for the current server. @@ -196,9 +198,7 @@ public function load() { // values for minimum_solr_version and environment. $selection = []; foreach ($entities as $key => $entity) { - $entities[$key]->setDisabledOnServer(in_array($entity->id(), $disabled_entities)); - /** @var \Drupal\search_api_solr\SolrConfigInterface $entity - */ + $entity->setDisabledOnServer(in_array($entity->id(), $disabled_entities)); $version = $entity->getMinimumSolrVersion(); $environments = $entity->getEnvironments(); if ( @@ -274,7 +274,7 @@ public function load() { * @param \Drupal\search_api_solr\SolrConfigInterface $source * The source Solr config entity. */ - protected function mergeSolrConfigs(SolrConfigInterface $target, SolrConfigInterface $source) { + protected function mergeSolrConfigs(SolrConfigInterface $target, SolrConfigInterface $source): void { if (empty($target->getSolrConfigs()) && !empty($source->getSolrConfigs())) { $target->setSolrConfigs($source->getSolrConfigs()); } @@ -288,7 +288,7 @@ protected function mergeSolrConfigs(SolrConfigInterface $target, SolrConfigInter * * @throws \Drupal\search_api\SearchApiException */ - public function getXml() { + public function getXml(): string { $xml = ''; /** @var \Drupal\search_api_solr\SolrConfigInterface $solr_entities */ foreach ($this->getEnabledEntities() as $solr_entities) { @@ -346,6 +346,7 @@ public function getAllRecommendedEntities(): array { // Bypass AbstractSolrEntityListBuilder::load() by calling the parent. But // don't use parent::load() in case someone copies this function in an // inherited class. + /** @var \Drupal\search_api_solr\Entity\AbstractSolrEntity[] $entities */ $entities = ConfigEntityListBuilder::load(); foreach ($entities as $key => $entity) { if (!$entity->isRecommended()) { @@ -365,6 +366,7 @@ public function getAllNotRecommendedEntities(): array { // Bypass AbstractSolrEntityListBuilder::load() by calling the parent. But // don't use parent::load() in case someone copies this function in an // inherited class. + /** @var \Drupal\search_api_solr\Entity\AbstractSolrEntity[] $entities */ $entities = ConfigEntityListBuilder::load(); foreach ($entities as $key => $entity) { if ($entity->isRecommended()) { diff --git a/src/Controller/SolrFieldTypeListBuilder.php b/src/Controller/SolrFieldTypeListBuilder.php index f9c8765d..ff9c0840 100644 --- a/src/Controller/SolrFieldTypeListBuilder.php +++ b/src/Controller/SolrFieldTypeListBuilder.php @@ -31,17 +31,17 @@ public function buildHeader() { /** * {@inheritdoc} */ - public function buildRow(EntityInterface $solr_field_type) { - /** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */ - $domains = $solr_field_type->getDomains(); + public function buildRow(EntityInterface $_field_type) { + /** @var \Drupal\search_api_solr\SolrFieldTypeInterface $_field_type */ + $domains = $_field_type->getDomains(); if (empty($domains)) { $domains = ['generic']; } - $enabled_label = $solr_field_type->isDisabledOnServer() ? $this->t('Disabled') : $this->t('Enabled'); + $enabled_label = $_field_type->isDisabledOnServer() ? $this->t('Disabled') : $this->t('Enabled'); $enabled_icon = [ '#theme' => 'image', - '#uri' => !$solr_field_type->isDisabledOnServer() ? 'core/misc/icons/73b355/check.svg' : 'core/misc/icons/e32700/error.svg', + '#uri' => !$_field_type->isDisabledOnServer() ? 'core/misc/icons/73b355/check.svg' : 'core/misc/icons/e32700/error.svg', '#width' => 18, '#height' => 18, '#alt' => $enabled_label, @@ -49,21 +49,21 @@ public function buildRow(EntityInterface $solr_field_type) { ]; $row = [ - 'label' => $solr_field_type->label(), - 'minimum_solr_version' => $solr_field_type->getMinimumSolrVersion(), + 'label' => $_field_type->label(), + 'minimum_solr_version' => $_field_type->getMinimumSolrVersion(), // @todo format - 'managed_schema' => $solr_field_type->requiresManagedSchema(), + 'managed_schema' => $_field_type->requiresManagedSchema(), // @todo format - 'langcode' => $solr_field_type->getFieldTypeLanguageCode(), + 'langcode' => $_field_type->getFieldTypeLanguageCode(), // @todo format 'domains' => implode(', ', $domains), - 'id' => $solr_field_type->id(), + 'id' => $_field_type->id(), 'enabled' => [ 'data' => $enabled_icon, 'class' => ['checkbox'], ], ]; - return $row + parent::buildRow($solr_field_type); + return $row + parent::buildRow($_field_type); } /** diff --git a/src/Entity/AbstractSolrEntity.php b/src/Entity/AbstractSolrEntity.php index ece5d89d..f32d085d 100644 --- a/src/Entity/AbstractSolrEntity.php +++ b/src/Entity/AbstractSolrEntity.php @@ -243,14 +243,6 @@ protected static function getAvailableOptions(string $key, string $default, stri return $options; } - /** - * Get Options. - * - * @return string[] - * An array of options as strings. - */ - abstract public function getOptions(); - /** * {@inheritdoc} */ diff --git a/src/EnvironmentAwareSolrConfigInterface.php b/src/EnvironmentAwareSolrConfigInterface.php new file mode 100644 index 00000000..54cd0553 --- /dev/null +++ b/src/EnvironmentAwareSolrConfigInterface.php @@ -0,0 +1,18 @@ +