Skip to content

Commit

Permalink
Issue #3406269 by mkalkbrenner: Fix phpcs, phpstan, stylelint findings
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kalkbrenner authored and mkalkbrenner committed Dec 5, 2023
1 parent 8cd5a9c commit e4169a9
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
40 changes: 21 additions & 19 deletions src/Controller/AbstractSolrEntityListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,35 @@ 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,
'#title' => $enabled_label,
];

$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);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -186,19 +189,16 @@ 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.
// There are multiple entities having the same entity name but different
// 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 (
Expand Down Expand Up @@ -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());
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down
22 changes: 11 additions & 11 deletions src/Controller/SolrFieldTypeListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,39 @@ 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,
'#title' => $enabled_label,
];

$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);
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/Entity/AbstractSolrEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
18 changes: 18 additions & 0 deletions src/EnvironmentAwareSolrConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Drupal\search_api_solr;

/**
* Provides an interface defining a SolrCache entity.
*/
interface EnvironmentAwareSolrConfigInterface extends SolrConfigInterface {

/**
* Gets the environments targeted by this Solr Config.
*
* @return string[]
* Environments.
*/
public function getEnvironments();

}
12 changes: 2 additions & 10 deletions src/SolrCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
namespace Drupal\search_api_solr;

/**
* Provides an interface defining a SolrCache entity.
* Provides an interface defining a environment aware Solr entity.
*/
interface SolrCacheInterface extends SolrConfigInterface {

/**
* Gets the environments targeted by this Solr Cache.
*
* @return string[]
* Environments.
*/
public function getEnvironments();
interface SolrCacheInterface extends EnvironmentAwareSolrConfigInterface {

/**
* Gets the Solr Cache definition as nested associative array.
Expand Down
8 changes: 8 additions & 0 deletions src/SolrConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,12 @@ public function setDisabledOnServer(bool $disabled_on_server): void;
*/
public function isDisabledOnServer(): bool;

/**
* Get Options.
*
* @return string[]
* An array of options as strings.
*/
public function getOptions(): array;

}
6 changes: 3 additions & 3 deletions src/SolrFieldTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ public function getSpellcheckFieldTypeAsJson(bool $pretty = FALSE);
public function setSpellcheckFieldTypeAsJson($spellcheck_field_type);

/**
* Gets the Solr Spellcheck Spellcheck Field Type definition as XML fragment.
* Gets the Solr Spellcheck Field Type definition as XML fragment.
*
* The XML format is used as part of a classic Solr schema.
*
* @param bool $add_comment
* Wether to add a comment to the XML or not to explain the purpose of this
* Solr Field Type.
* Add a comment to the XML or not to explain the purpose of this Solr Field
* Type.
*
* @return string
* The Solr Spellcheck Field Type definition as XML, might be empty if it
Expand Down
10 changes: 1 addition & 9 deletions src/SolrRequestDispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
/**
* Provides an interface defining a SolrRequestDispatcher entity.
*/
interface SolrRequestDispatcherInterface extends SolrConfigInterface {

/**
* Gets the environments targeted by this Solr RequestDispatcher.
*
* @return string[]
* Environments.
*/
public function getEnvironments();
interface SolrRequestDispatcherInterface extends EnvironmentAwareSolrConfigInterface {

/**
* Gets the Solr RequestDispatcher definition as nested associative array.
Expand Down
10 changes: 1 addition & 9 deletions src/SolrRequestHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
/**
* Provides an interface defining a SolrRequestHandler entity.
*/
interface SolrRequestHandlerInterface extends SolrConfigInterface {

/**
* Gets the environments targeted by this Solr RequestHandler.
*
* @return string[]
* Environments.
*/
public function getEnvironments();
interface SolrRequestHandlerInterface extends EnvironmentAwareSolrConfigInterface {

/**
* Gets the Solr RequestHandler definition as nested associative array.
Expand Down

0 comments on commit e4169a9

Please sign in to comment.